From e30f9af09ef9bf9da88be191f9be771296e6ed3c Mon Sep 17 00:00:00 2001 From: davidmcdonagh Date: Tue, 10 Sep 2024 23:59:52 +0100 Subject: [PATCH] Changed predicted reflections calculation during tof_integrate. --- .../algorithms/spot_prediction/__init__.py | 34 +++++++++++++++++++ src/dials/command_line/tof_integrate.py | 17 +++++----- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/dials/algorithms/spot_prediction/__init__.py b/src/dials/algorithms/spot_prediction/__init__.py index 0d46fccfac..2d615e38ec 100644 --- a/src/dials/algorithms/spot_prediction/__init__.py +++ b/src/dials/algorithms/spot_prediction/__init__.py @@ -234,6 +234,40 @@ def post_prediction(self, reflections): return reflections + def indices_for_ub(self, indices): + reflection_table = self.predictor(indices) + reflection_table = self.post_prediction(reflection_table) + + interpolation_tof = self.experiment.scan.get_property("time_of_flight") + interpolation_frames = list(range(len(interpolation_tof))) + tof_to_frame = tof_helpers.tof_to_frame_interpolator( + interpolation_tof, interpolation_frames + ) + L0 = self.experiment.beam.get_sample_to_source_distance() * 10**-3 # (m) + + reflection_tof = ( + tof_helpers.tof_from_wavelength( + reflection_table["wavelength_cal"], + L0 + reflection_table["L1"] * 10**-3, + ) + * 10**6 + ) + + reflection_table = reflection_table.select( + (reflection_tof > min(interpolation_tof)) + & (reflection_tof < max(interpolation_tof)) + ) + + reflection_tof = reflection_tof.select( + (reflection_tof > min(interpolation_tof)) + & (reflection_tof < max(interpolation_tof)) + ) + reflection_frames = flumpy.from_numpy(tof_to_frame(reflection_tof)) + x, y, _ = reflection_table["xyzcal.px"].parts() + reflection_table["xyzcal.px"] = flex.vec3_double(x, y, reflection_frames) + + return reflection_table + def for_ub(self, ub): reflection_table = self.predictor.for_ub(ub) diff --git a/src/dials/command_line/tof_integrate.py b/src/dials/command_line/tof_integrate.py index 021c1cafcc..1ed8bb53b7 100644 --- a/src/dials/command_line/tof_integrate.py +++ b/src/dials/command_line/tof_integrate.py @@ -19,6 +19,7 @@ ComputeEsdBeamDivergence, ) from dials.algorithms.shoebox import MaskCode +from dials.algorithms.spot_prediction import TOFReflectionPredictor from dials.array_family import flex from dials.command_line.integrate import process_reference from dials.extensions.simple_background_ext import SimpleBackgroundExt @@ -330,12 +331,12 @@ def run_integrate(params, experiments, reflections): dmin = expt_dmin predicted_reflections = None + miller_indices = reflections["miller_index"] for idx, experiment in enumerate(experiments): + predictor = TOFReflectionPredictor(experiment, dmin) if predicted_reflections is None: - predicted_reflections = flex.reflection_table.from_predictions( - experiment, padding=1.0, dmin=dmin - ) + predicted_reflections = predictor.indices_for_ub(miller_indices) predicted_reflections["id"] = cctbx.array_family.flex.int( len(predicted_reflections), idx ) @@ -343,9 +344,7 @@ def run_integrate(params, experiments, reflections): len(predicted_reflections), idx ) else: - r = flex.reflection_table.from_predictions( - experiment, padding=1.0, dmin=dmin - ) + r = predictor.indices_for_ub(miller_indices) r["id"] = cctbx.array_family.flex.int(len(r), idx) r["imageset_id"] = cctbx.array_family.flex.int(len(r), idx) predicted_reflections.extend(r) @@ -497,7 +496,7 @@ def run_integrate(params, experiments, reflections): expt_reflections.compute_summed_intensity() if params.method.line_profile_fitting: - print("Calculating line profile fitted intensities") + print(f"Calculating line profile fitted intensities for expt {idx}") expt_reflections = compute_line_profile_intensity(expt_reflections) predicted_reflections.set_selected(sel, expt_reflections) else: @@ -539,7 +538,7 @@ def run_integrate(params, experiments, reflections): expt_reflections.compute_summed_intensity() if params.method.line_profile_fitting: - print("Calculating line profile fitted intensities") + print(f"Calculating line profile fitted intensities for expt {idx}") expt_reflections = compute_line_profile_intensity(expt_reflections) predicted_reflections.set_selected(sel, expt_reflections) else: @@ -581,7 +580,7 @@ def run_integrate(params, experiments, reflections): expt_reflections.compute_summed_intensity() if params.method.line_profile_fitting: - print("Calculating line profile fitted intensities") + print(f"Calculating line profile fitted intensities for expt {idx}") expt_reflections = compute_line_profile_intensity(expt_reflections) predicted_reflections.set_selected(sel, expt_reflections)