Esempio n. 1
0
def test_plot_array_decay_plot():
    """Test plot generation for array decay correction"""
    array_dict = {
        "__id__": "array",
        "is_scaled": True,
        "decay": {
            "n_parameters": 20,
            "parameters": list(range(1, 21)),
            "est_standard_devs": [],
        },
        "configuration_parameters": {
            "corrections": ["decay"],
            "time_rot_interval": 10.0,
            "n_res_param": 5,
            "res_bin_width": 0.1,
            "n_time_param": 4,
            "resmin": 0.05,
            "valid_osc_range": [0, 100],
        },
    }

    array_model = ArrayScalingModel.from_dict(array_dict)
    plot = plot_array_decay_plot(array_model)
    assert plot["array_decay_plot"]["data"][0]["x"]
    assert plot["array_decay_plot"]["data"][0]["y"]
Esempio n. 2
0
def test_plot_array_absorption_plot():
    """Test plot generation for array absorption_correction"""
    array_dict = {
        "__id__": "array",
        "is_scaled": True,
        "absorption": {
            "n_parameters": 45,
            "parameters": list(range(1, 46)),
            "est_standard_devs": [],
        },
        "configuration_parameters": {
            "corrections": ["absorption"],
            "time_rot_interval": 10.0,
            "n_x_param": 3,
            "n_y_param": 3,
            "n_time_param": 5,
            "xmin": 0,
            "x_bin_width": 2,
            "ymin": 1,
            "y_bin_width": 2,
            "valid_osc_range": [0, 100],
        },
    }

    array_model = ArrayScalingModel.from_dict(array_dict)
    plot = plot_array_absorption_plot(array_model)
    assert plot["array_absorption_plot"]["data"][0]["x"]
    assert plot["array_absorption_plot"]["data"][0]["y"]
    assert plot["array_absorption_plot"]["data"][0]["z"]
Esempio n. 3
0
def test_model_creation_from_data(default_params, mock_exp, test_reflections):
    """Test the factory creation of the three standard scaling models with the
    default params."""

    _ = KBScalingModel.from_data(default_params, [], [])

    _ = PhysicalScalingModel.from_data(default_params, mock_exp, test_reflections)

    _ = ArrayScalingModel.from_data(default_params, mock_exp, test_reflections)
Esempio n. 4
0
def test_ArrayScalingModel(test_reflections, mock_exp):
    """Test the ArrayScalingModel class."""

    configdict = {
        "corrections": ["decay", "absorption", "modulation"],
        "n_res_param": 2,
        "n_time_param": 2,
        "resmin": 1.0,
        "res_bin_width": 1.0,
        "time_norm_fac": 1.0,
        "time_rot_interval": 1.0,
        "n_x_param": 2,
        "n_y_param": 2,
        "xmin": 0.0,
        "ymin": 0.0,
        "x_bin_width": 1.0,
        "y_bin_width": 2.0,
        "n_x_mod_param": 2,
        "n_y_mod_param": 2,
        "x_det_bin_width": 2.0,
        "y_det_bin_width": 2.0,
    }

    parameters_dict = {
        "decay": {
            "parameters": flex.double([1.2, 1.1, 1.0, 0.9]),
            "parameter_esds": None,
        },
        "absorption": {
            "parameters": flex.double([0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1,
                                       0.2]),
            "parameter_esds": None,
        },
        "modulation": {
            "parameters": flex.double(4, 0.9),
            "parameter_esds": None
        },
    }

    # Test standard factory initialisation
    arraymodel = ArrayScalingModel(parameters_dict, configdict)
    assert arraymodel.id_ == "array"
    assert "decay" in arraymodel.components
    assert "absorption" in arraymodel.components
    assert "modulation" in arraymodel.components
    assert list(
        arraymodel.components["decay"].parameters) == [1.2, 1.1, 1.0, 0.9]
    assert list(arraymodel.components["absorption"].parameters) == [
        0.1,
        0.2,
        0.1,
        0.2,
        0.1,
        0.2,
        0.1,
        0.2,
    ]
    assert list(arraymodel.components["modulation"].parameters) == 4 * [0.9]

    # Test configure reflection table
    _ = arraymodel.configure_components(test_reflections, mock_exp, [])

    # Test from_dict initialisation method for previous model case.
    init_dict = arraymodel.to_dict()
    new_array_model = ArrayScalingModel.from_dict(init_dict)
    assert new_array_model.id_ == "array"
    comps = new_array_model.components
    assert "modulation" in comps
    assert "absorption" in comps
    assert "decay" in comps
    assert list(comps["decay"].parameters) == [1.2, 1.1, 1.0, 0.9]
    assert list(comps["absorption"].parameters) == [
        0.1,
        0.2,
        0.1,
        0.2,
        0.1,
        0.2,
        0.1,
        0.2,
    ]
    assert list(comps["modulation"].parameters) == 4 * [0.9]

    # Test from_dict initialisation method for another case.
    array_dict = {
        "__id__": "array",
        "is_scaled": True,
        "decay": {
            "n_parameters": 4,
            "parameters": [0.5, 1.0, 0.4, 1.0],
            "null_parameter_value": 1.0,
            "est_standard_devs": [0.05, 0.1, 0.05, 0.1],
        },
        "configuration_parameters": {
            "corrections": ["decay"],
            "n_res_param": 2,
            "n_time_param": 2,
            "resmin": 1.0,
            "res_bin_width": 1.0,
            "time_norm_fac": 1.0,
            "time_rot_interval": 1.0,
        },
    }
    arraymodel = ArrayScalingModel.from_dict(array_dict)
    assert arraymodel.id_ == "array"
    comps = arraymodel.components
    assert "modulation" not in comps
    assert "absorption" not in comps
    assert "decay" in comps
    assert list(comps["decay"].parameters) == [0.5, 1.0, 0.4, 1.0]
    assert list(comps["decay"].parameter_esds) == [0.05, 0.1, 0.05, 0.1]

    new_dict = arraymodel.to_dict()
    assert new_dict == array_dict

    with pytest.raises(RuntimeError):
        array_dict["__id__"] = "physical"
        arraymodel = ArrayScalingModel.from_dict(array_dict)

    assert len(arraymodel.consecutive_refinement_order) == 3
    assert "Decay component" in str(arraymodel)

    # test limit batch range
    configdict = {
        "corrections": ["decay", "absorption"],
        "n_res_param": 2,
        "n_time_param": 3,
        "resmin": 1.0,
        "res_bin_width": 1.0,
        "time_norm_fac": 0.1,
        "time_rot_interval": 10.0,
        "n_x_param": 2,
        "n_y_param": 2,
        "xmin": 0.0,
        "ymin": 0.0,
        "x_bin_width": 1.0,
        "y_bin_width": 2.0,
        "n_x_mod_param": 2,
        "n_y_mod_param": 2,
        "x_det_bin_width": 2.0,
        "y_det_bin_width": 2.0,
        "valid_image_range": (1, 20),
        "valid_osc_range": (0, 20),
    }

    parameters_dict = {
        "decay": {
            "parameters": flex.double([1.2, 1.1, 1.0, 0.9, 0.8, 0.7]),
            "parameter_esds": None,
        },
        "absorption": {
            "parameters":
            flex.double(
                [0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.3, 0.4, 0.3, 0.4]),
            "parameter_esds":
            None,
        },
    }
    array = ArrayScalingModel(parameters_dict, configdict)
    array.limit_image_range((1, 10))
    assert list(array.components["decay"].parameters) == [1.2, 1.1, 1.0, 0.9]
    assert list(array.components["absorption"].parameters) == [
        0.1,
        0.2,
        0.1,
        0.2,
        0.1,
        0.2,
        0.1,
        0.2,
    ]
    assert array.configdict["n_time_param"] == 2
    assert array.configdict["valid_image_range"] == (1, 10)
    assert array.configdict["valid_osc_range"] == (0, 10)
Esempio n. 5
0
    def from_dict(d):
        """creates a scaling model from a dict"""
        from dials.algorithms.scaling.model.model import ArrayScalingModel

        return ArrayScalingModel.from_dict(d)