コード例 #1
0
ファイル: test_observers.py プロジェクト: jasonroyprice/dials
def test_register_scaling_observers():
    """Test the registering of the standard scaling observers."""
    class Scaler(Subject):
        """Test scaler class"""
        def __init__(self):
            super(Scaler, self).__init__(events=[
                "performed_scaling",
                "performed_outlier_rejection",
                "performed_error_analysis",
            ])

    class TestScript(Subject):
        """Test script class"""
        def __init__(self):
            super(TestScript, self).__init__(
                events=["merging_statistics", "run_script", "run_filtering"])
            self.scaler = Scaler()

    script = TestScript()
    register_default_scaling_observers(script)
    assert script.get_observers("merging_statistics") == {
        MergingStatisticsObserver(): MergingStatisticsObserver().update
    }
    assert script.get_observers("run_script") == {
        ScalingHTMLGenerator(): ScalingHTMLGenerator().make_scaling_html,
        ScalingSummaryGenerator():
        ScalingSummaryGenerator().print_scaling_summary,
    }
    assert script.scaler.get_observers("performed_scaling") == {
        ScalingModelObserver(): ScalingModelObserver().update
    }
    assert script.scaler.get_observers("performed_outlier_rejection") == {
        ScalingOutlierObserver(): ScalingOutlierObserver().update
    }
コード例 #2
0
ファイル: scale.py プロジェクト: hattne/dials
def run_scaling(params, experiments, reflections):
    """Run scaling algorithms; stats only, cross validation or standard."""
    if params.stats_only:
        Script.stats_only(reflections, experiments, params)
        sys.exit()

    if params.export_mtz_only:
        Script.export_mtz_only(reflections, experiments, params)
        sys.exit()

    if params.output.delete_integration_shoeboxes:
        for r in reflections:
            del r["shoebox"]

    if params.cross_validation.cross_validation_mode:
        from dials.algorithms.scaling.cross_validation.cross_validate import (
            cross_validate,
        )
        from dials.algorithms.scaling.cross_validation.crossvalidator import (
            DialsScaleCrossValidator,
        )

        cross_validator = DialsScaleCrossValidator(experiments, reflections)
        try:
            cross_validate(params, cross_validator)
        except ValueError as e:
            raise Sorry(e)

        logger.info(
            "Cross validation analysis does not produce scaling output files, rather\n"
            "it gives insight into the dataset. Choose an appropriate parameterisation\n"
            "and rerun scaling without cross_validation_mode.\n"
        )

    else:
        script = Script(params, experiments, reflections)
        # Register the observers at the highest level
        if params.output.html:
            register_default_scaling_observers(script)
        else:
            register_merging_stats_observers(script)
        if params.filtering.method:
            if script.scaler.id_ != "multi":
                raise Sorry(
                    """
Scaling and filtering can only be performed in multi-dataset scaling mode
(not single dataset or scaling against a reference)"""
                )
            register_scale_and_filter_observers(script)
            script.run_scale_and_filter()
            with open(params.filtering.output.scale_and_filter_results, "w") as f:
                json.dump(script.filtering_results.to_dict(), f, indent=2)
        else:
            script.run()
        script.export()
コード例 #3
0
def run_scaling(params, experiments, reflections):
    """Run scaling algorithms; cross validation, scaling + filtering or standard.

    Returns:
        experiments: an experiment list with scaled data (if created)
        joint_table: a single reflection table containing scaled data (if created).
    """

    if params.output.delete_integration_shoeboxes:
        for r in reflections:
            del r["shoebox"]

    if params.cross_validation.cross_validation_mode:
        from dials.algorithms.scaling.cross_validation.cross_validate import (
            cross_validate, )
        from dials.algorithms.scaling.cross_validation.crossvalidator import (
            DialsScaleCrossValidator, )

        cross_validator = DialsScaleCrossValidator(experiments, reflections)
        cross_validate(params, cross_validator)

        logger.info(
            "Cross validation analysis does not produce scaling output files, rather\n"
            "it gives insight into the dataset. Choose an appropriate parameterisation\n"
            "and rerun scaling without cross_validation_mode.\n")
        return (None, None)

    else:
        # Register the observers at the highest level
        if params.filtering.method:
            algorithm = ScaleAndFilterAlgorithm(params, experiments,
                                                reflections)
            register_scale_and_filter_observers(algorithm)
        else:
            algorithm = ScalingAlgorithm(params, experiments, reflections)

        if params.output.html:
            register_default_scaling_observers(algorithm)
        else:
            register_merging_stats_observers(algorithm)

        algorithm.run()

        experiments, joint_table = algorithm.finish()

        return experiments, joint_table