def test_centroid_outlier(dials_regression, method, colnames, expected_nout): flex.set_random_seed(42) data_dir = os.path.join(dials_regression, "refinement_test_data", "centroid_outlier") residuals = flex.reflection_table.from_file( os.path.join(data_dir, "residuals.refl")) params = phil_scope.extract() params.outlier.algorithm = method params.outlier.sauter_poon.px_sz = (0.1, 0.1) # must be set for SauterPoon outlier_detector = CentroidOutlierFactory.from_parameters_and_colnames( params, colnames) outlier_detector(residuals) outliers = residuals.get_flags(residuals.flags.centroid_outlier) assert outliers.count(True) == expected_nout
def from_parameters_reflections_experiments( params, reflections, experiments, do_stills=False ): """Given a set of parameters and models, build a reflection manager Params: params The input parameters Returns: The reflection manager instance """ # While a random subset of reflections is used, continue to # set random.seed to get consistent behaviour if params.random_seed is not None: random.seed(params.random_seed) flex.set_random_seed(params.random_seed) logger.debug("Random seed set to %d", params.random_seed) # check whether we deal with stills or scans if do_stills: refman = StillsReflectionManager # check incompatible weighting strategy if params.weighting_strategy.override == "statistical": raise DialsRefineConfigError( 'The "statistical" weighting strategy is not compatible ' "with stills refinement" ) else: refman = ReflectionManager # check incompatible weighting strategy if params.weighting_strategy.override in ["stills", "external_deltapsi"]: msg = ( 'The "{0}" weighting strategy is not compatible with ' "scan refinement" ).format(params.weighting_strategy.override) raise DialsRefineConfigError(msg) # set automatic outlier rejection options if params.outlier.algorithm in ("auto", libtbx.Auto): if do_stills: params.outlier.algorithm = "sauter_poon" else: params.outlier.algorithm = "mcd" if params.outlier.separate_panels is libtbx.Auto: if do_stills: params.outlier.separate_panels = False else: params.outlier.separate_panels = True if params.outlier.algorithm == "sauter_poon": if params.outlier.sauter_poon.px_sz is libtbx.Auto: # get this from the first panel of the first detector params.outlier.sauter_poon.px_sz = experiments.detectors()[0][ 0 ].get_pixel_size() # do outlier rejection? if params.outlier.algorithm in ("null", None): outlier_detector = None else: if do_stills: colnames = ["x_resid", "y_resid"] params.outlier.block_width = None else: colnames = ["x_resid", "y_resid", "phi_resid"] from dials.algorithms.refinement.outlier_detection import ( CentroidOutlierFactory, ) outlier_detector = CentroidOutlierFactory.from_parameters_and_colnames( params, colnames ) # override default weighting strategy? weighting_strategy = None if params.weighting_strategy.override == "statistical": from dials.algorithms.refinement.weighting_strategies import ( StatisticalWeightingStrategy, ) weighting_strategy = StatisticalWeightingStrategy() elif params.weighting_strategy.override == "stills": from dials.algorithms.refinement.weighting_strategies import ( StillsWeightingStrategy, ) weighting_strategy = StillsWeightingStrategy( params.weighting_strategy.delpsi_constant ) elif params.weighting_strategy.override == "external_deltapsi": from dials.algorithms.refinement.weighting_strategies import ( ExternalDelPsiWeightingStrategy, ) weighting_strategy = ExternalDelPsiWeightingStrategy() elif params.weighting_strategy.override == "constant": from dials.algorithms.refinement.weighting_strategies import ( ConstantWeightingStrategy, ) weighting_strategy = ConstantWeightingStrategy( *params.weighting_strategy.constants, stills=do_stills ) # Check for deprecated parameter if params.trim_scan_edges is not None: warnings.warn( "The parameter trim_scan_edges is deprecated and will be removed shortly", FutureWarning, ) params.scan_margin = params.trim_scan_edges return refman( reflections=reflections, experiments=experiments, nref_per_degree=params.reflections_per_degree, max_sample_size=params.maximum_sample_size, min_sample_size=params.minimum_sample_size, close_to_spindle_cutoff=params.close_to_spindle_cutoff, scan_margin=params.scan_margin, outlier_detector=outlier_detector, weighting_strategy_override=weighting_strategy, )