From f3f717693989e2afc5293bab237476da242080f8 Mon Sep 17 00:00:00 2001 From: davidmcdonagh Date: Thu, 1 Aug 2024 14:26:21 +0100 Subject: [PATCH] Fixed tof integrate error when using multiple orientations. --- .../integration/fit/tof_line_profile.py | 6 +- src/dials/command_line/tof_integrate.py | 114 ++++++++++++++---- 2 files changed, 91 insertions(+), 29 deletions(-) diff --git a/src/dials/algorithms/integration/fit/tof_line_profile.py b/src/dials/algorithms/integration/fit/tof_line_profile.py index 949aaaf58e..b2613e5fb9 100644 --- a/src/dials/algorithms/integration/fit/tof_line_profile.py +++ b/src/dials/algorithms/integration/fit/tof_line_profile.py @@ -113,7 +113,7 @@ def compute_line_profile_data_for_reflection( l = BackToBackExponential( tof=tof, intensities=projected_intensity, - A=A, + A=max(projected_intensity), alpha=alpha, beta=beta, sigma=sigma, @@ -148,7 +148,7 @@ def compute_line_profile_data_for_reflection( def compute_line_profile_intensity(reflections): - A = 200.0 + # A = 200.0 alpha = 0.4 beta = 0.4 sigma = 8.0 @@ -195,7 +195,7 @@ def compute_line_profile_intensity(reflections): l = BackToBackExponential( tof=tof, intensities=projected_intensity, - A=A, + A=max(projected_intensity), alpha=alpha, beta=beta, sigma=sigma, diff --git a/src/dials/command_line/tof_integrate.py b/src/dials/command_line/tof_integrate.py index c75c997ce2..021c1cafcc 100644 --- a/src/dials/command_line/tof_integrate.py +++ b/src/dials/command_line/tof_integrate.py @@ -434,12 +434,15 @@ def run_integrate(params, experiments, reflections): incident_proton_charge = incident_fmt_class.get_proton_charge() empty_proton_charge = empty_fmt_class.get_proton_charge() - for expt in experiments: + for idx, expt in enumerate(experiments): expt_data = expt.imageset expt_proton_charge = experiment_cls.get_instance( expt.imageset.paths()[0], **expt.imageset.data().get_params() ).get_proton_charge() + sel = predicted_reflections["id"] == idx + expt_reflections = predicted_reflections.select(sel) + if applying_spherical_absorption_correction(params): logger.info( "Applying spherical absorption correction to target and Vanadium runs" @@ -462,7 +465,7 @@ def run_integrate(params, experiments, reflections): ) tof_extract_shoeboxes_to_reflection_table( - predicted_reflections, + expt_reflections, expt, expt_data, incident_data, @@ -470,12 +473,39 @@ def run_integrate(params, experiments, reflections): corrections_data, params.corrections.lorentz, ) + # tof_calculate_shoebox_mask(predicted_reflections, expt) + tof_calculate_shoebox_foreground( + expt_reflections, expt, params.foreground_radius + ) + expt_reflections.is_overloaded(experiments) + expt_reflections.contains_invalid_pixels() + expt_reflections["partiality"] = flex.double(len(expt_reflections), 1.0) + + # Background calculated explicitly to expose underlying algorithm + background_algorithm = SimpleBackgroundExt( + params=None, experiments=experiments + ) + success = background_algorithm.compute_background(expt_reflections) + expt_reflections.set_flags( + ~success, expt_reflections.flags.failed_during_background_modelling + ) + + # Centroids calculated explicitly to expose underlying algorithm + # centroid_algorithm = SimpleCentroidExt(params=None, experiments=experiments) + # centroid_algorithm.compute_centroid(expt_reflections) + + expt_reflections.compute_summed_intensity() + + if params.method.line_profile_fitting: + print("Calculating line profile fitted intensities") + expt_reflections = compute_line_profile_intensity(expt_reflections) + predicted_reflections.set_selected(sel, expt_reflections) else: logger.info("Normalising target run with Vanadium run") if params.corrections.lorentz: logger.info("Applying Lorentz correction to target run") tof_extract_shoeboxes_to_reflection_table( - predicted_reflections, + expt_reflections, expt, expt_data, incident_data, @@ -485,43 +515,75 @@ def run_integrate(params, experiments, reflections): empty_proton_charge, params.corrections.lorentz, ) + # tof_calculate_shoebox_mask(predicted_reflections, expt) + tof_calculate_shoebox_foreground( + expt_reflections, expt, params.foreground_radius + ) + expt_reflections.is_overloaded(experiments) + expt_reflections.contains_invalid_pixels() + expt_reflections["partiality"] = flex.double(len(expt_reflections), 1.0) + + # Background calculated explicitly to expose underlying algorithm + background_algorithm = SimpleBackgroundExt( + params=None, experiments=experiments + ) + success = background_algorithm.compute_background(expt_reflections) + expt_reflections.set_flags( + ~success, expt_reflections.flags.failed_during_background_modelling + ) + + # Centroids calculated explicitly to expose underlying algorithm + # centroid_algorithm = SimpleCentroidExt(params=None, experiments=experiments) + # centroid_algorithm.compute_centroid(expt_reflections) + + expt_reflections.compute_summed_intensity() + + if params.method.line_profile_fitting: + print("Calculating line profile fitted intensities") + expt_reflections = compute_line_profile_intensity(expt_reflections) + predicted_reflections.set_selected(sel, expt_reflections) else: if params.corrections.lorentz: logger.info("Applying Lorentz correction to target run") - for expt in experiments: + print("Calculating summed intensities") + for idx, expt in enumerate(experiments): + sel = predicted_reflections["id"] == idx + expt_reflections = predicted_reflections.select(sel) expt_data = expt.imageset tof_extract_shoeboxes_to_reflection_table( - predicted_reflections, + expt_reflections, expt, expt_data, params.corrections.lorentz, ) - # tof_calculate_shoebox_mask(predicted_reflections, expt) - tof_calculate_shoebox_foreground( - predicted_reflections, expt, params.foreground_radius - ) - predicted_reflections.is_overloaded(experiments) - predicted_reflections.contains_invalid_pixels() - predicted_reflections["partiality"] = flex.double(len(predicted_reflections), 1.0) + # tof_calculate_shoebox_mask(predicted_reflections, expt) + tof_calculate_shoebox_foreground( + expt_reflections, expt, params.foreground_radius + ) + expt_reflections.is_overloaded(experiments) + expt_reflections.contains_invalid_pixels() + expt_reflections["partiality"] = flex.double(len(expt_reflections), 1.0) - # Background calculated explicitly to expose underlying algorithm - background_algorithm = SimpleBackgroundExt(params=None, experiments=experiments) - success = background_algorithm.compute_background(predicted_reflections) - predicted_reflections.set_flags( - ~success, predicted_reflections.flags.failed_during_background_modelling - ) + # Background calculated explicitly to expose underlying algorithm + background_algorithm = SimpleBackgroundExt( + params=None, experiments=experiments + ) + success = background_algorithm.compute_background(expt_reflections) + expt_reflections.set_flags( + ~success, expt_reflections.flags.failed_during_background_modelling + ) - # Centroids calculated explicitly to expose underlying algorithm - # centroid_algorithm = SimpleCentroidExt(params=None, experiments=experiments) - # centroid_algorithm.compute_centroid(predicted_reflections) + # Centroids calculated explicitly to expose underlying algorithm + # centroid_algorithm = SimpleCentroidExt(params=None, experiments=experiments) + # centroid_algorithm.compute_centroid(expt_reflections) - print("Calculating summed intensities") - predicted_reflections.compute_summed_intensity() + expt_reflections.compute_summed_intensity() - if params.method.line_profile_fitting: - print("Calculating line profile fitted intensities") - predicted_reflections = compute_line_profile_intensity(predicted_reflections) + if params.method.line_profile_fitting: + print("Calculating line profile fitted intensities") + expt_reflections = compute_line_profile_intensity(expt_reflections) + predicted_reflections.set_selected(sel, expt_reflections) # Filter reflections with a high fraction of masked foreground valid_foreground_threshold = 1.0 # DIALS default