Repository : ssh://g18-sc-serv-04.diamond.ac.uk/dials On branch : master >--------------------------------------------------------------- commit 821cc450e40f4518e728537e643e957e2d0e2cd6 Author: dgwaterman <[log in to unmask]> Date: Wed Jul 25 15:30:35 2018 +0100 Merge relevant squashed commits from trim-scan-edge-centroids branch. This adds a new option to refinement, default trim_scan_edges=0.0, which removes centroids within this angular width in degrees from the edges of the scan before refinement. Tests in #457 show that this might not improve results for processing small wedge datasets, so the default behaviour is left unchanged. >--------------------------------------------------------------- 821cc450e40f4518e728537e643e957e2d0e2cd6 algorithms/refinement/refiner.py | 11 +++++++++ algorithms/refinement/reflection_manager.py | 35 ++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/algorithms/refinement/refiner.py b/algorithms/refinement/refiner.py index 06819de2..5449786a 100644 --- a/algorithms/refinement/refiner.py +++ b/algorithms/refinement/refiner.py @@ -390,6 +390,16 @@ .type = float(value_min = 0) .expert_level = 1 + trim_scan_edges = 0.0 + .help = "Reflections within this value in degrees from the centre of the" + "first or last image of the scan will be removed before" + "refinement, unless doing so would result in too few remaining" + "reflections. Reflections that are truncated at the scan edges" + "have poorly-determined centroids and can bias the refined model" + "if they are included." + .type = float(value_min=0,value_max=1) + .expert_level = 1 + block_width = 1.0 .help = "Width of a reflection 'block' (in degrees) determining how fine-" "grained the model used for scan-varying prediction during" @@ -1735,6 +1745,7 @@ def config_refman(params, reflections, experiments, do_stills, verbosity): max_sample_size = options.maximum_sample_size, min_sample_size = options.minimum_sample_size, close_to_spindle_cutoff=options.close_to_spindle_cutoff, + trim_scan_edges=options.trim_scan_edges, outlier_detector=outlier_detector, weighting_strategy_override=weighting_strategy, verbosity=verbosity) diff --git a/algorithms/refinement/reflection_manager.py b/algorithms/refinement/reflection_manager.py index e7675258..1a928979 100644 --- a/algorithms/refinement/reflection_manager.py +++ b/algorithms/refinement/reflection_manager.py @@ -159,6 +159,7 @@ def __init__(self, reflections, max_sample_size=None, min_sample_size=0, close_to_spindle_cutoff=0.02, + trim_scan_edges=0.0, outlier_detector=None, weighting_strategy_override=None, verbosity=0): @@ -200,11 +201,12 @@ def __init__(self, reflections, break # set up the reflection inclusion criteria - self._close_to_spindle_cutoff = close_to_spindle_cutoff #too close to spindle - self._outlier_detector = outlier_detector #for outlier rejection - self._nref_per_degree = nref_per_degree #random subsets - self._max_sample_size = max_sample_size #sample size ceiling - self._min_sample_size = min_sample_size #sample size floor + self._close_to_spindle_cutoff = close_to_spindle_cutoff # close to spindle + self._trim_scan_edges = DEG2RAD * trim_scan_edges # close to the scan edge + self._outlier_detector = outlier_detector # for outlier rejection + self._nref_per_degree = nref_per_degree # random subsets + self._max_sample_size = max_sample_size # sample size ceiling + self._min_sample_size = min_sample_size # sample size floor # exclude reflections that fail some inclusion criteria refs_to_keep = self._id_refs_to_keep(reflections) @@ -350,8 +352,29 @@ def _id_refs_to_keep(self, obs_data): raise Sorry("Experiment id {0} contains no reflections with valid " "scan angles".format(iexp)) - # combine tests + # combine tests so far to_update = passed1 & passed2 + + # third test: reject reflections close to the centres of the first and + # last images in the scan + if self._trim_scan_edges > 0.0: + edge1, edge2 = [e + 0.5 for e in exp.scan.get_image_range()] + edge1 = exp.scan.get_angle_from_image_index(edge1, deg=False) + edge1 += (self._trim_scan_edges) + edge2 = exp.scan.get_angle_from_image_index(edge2, deg=False) + edge2 -= (self._trim_scan_edges) + passed3 = ((edge1 <= phi) & (phi <= edge2)) + + # combine the last test only if there would be a reasonable number of + # reflections left for refinement + tmp = to_update + to_update = to_update & passed3 + if to_update.count(True) < 40: + logger.warning("Too few reflections to trim centroids from the scan " + "edges. Resetting trim_scan_edges=0.0") + to_update = tmp + + # make selection to_keep.set_selected(sel, to_update) inc = inc.select(to_keep) ######################################################################## To unsubscribe from the DIALS-COMMIT list, click the following link: https://www.jiscmail.ac.uk/cgi-bin/webadmin?SUBED1=DIALS-COMMIT&A=1