コード例 #1
0
ファイル: model.py プロジェクト: jbeilstenedmands/dials
 def __init__(self, parameters_dict, configdict, is_scaled=False):
     """Create the phyiscal scaling model components."""
     super(PhysicalScalingModel, self).__init__(configdict, is_scaled)
     if "scale" in configdict["corrections"]:
         scale_setup = parameters_dict["scale"]
         self._components["scale"] = SmoothScaleComponent1D(
             scale_setup["parameters"], scale_setup["parameter_esds"])
     if "decay" in configdict["corrections"]:
         decay_setup = parameters_dict["decay"]
         self._components["decay"] = SmoothBScaleComponent1D(
             decay_setup["parameters"], decay_setup["parameter_esds"])
     if "absorption" in configdict["corrections"]:
         absorption_setup = parameters_dict["absorption"]
         self._components["absorption"] = SHScaleComponent(
             absorption_setup["parameters"],
             absorption_setup["parameter_esds"])
コード例 #2
0
def test_SmoothScaleFactor1D():
    """Test for the gaussian smoothed 1D scalefactor class."""
    SF = SmoothScaleComponent1D(flex.double(5, 1.1))
    assert SF.n_params == 5
    assert list(SF.parameters) == [1.1, 1.1, 1.1, 1.1, 1.1]
    norm_rot = flex.double([0.5, 1.0, 2.5, 0.0])
    SF.data = {"x": norm_rot}
    SF.update_reflection_data()
    assert list(SF.normalised_values[0]) == [0.5, 1.0, 2.5, 0.0]
    SF.smoother.set_smoothing(4, 1.0)
    assert list(SF.smoother.positions()) == [-0.5, 0.5, 1.5, 2.5, 3.5]
    s, d = SF.calculate_scales_and_derivatives()
    s2 = SF.calculate_scales()
    assert list(s) == list(s2)
    assert list(s) == pytest.approx([1.1, 1.1, 1.1, 1.1])
    assert d[0, 0] / d[0, 1] == pytest.approx(exp(-1.0) / exp(0.0))
    sumexp = exp(-1.0 / 1.0) + exp(-0.0 / 1.0) + exp(
        -1.0 / 1.0)  # only averages 3 when
    # normalised position is exactly on a smoother position.
    assert d[0, 1] == pytest.approx((exp(0.0) / sumexp))
    T = d.transpose()
    assert sum(list(T[:, 0].as_dense_vector())) == 1.0  # should always be 1.0
    assert sum(list(T[:, 1].as_dense_vector())) == 1.0
    assert sum(list(T[:, 2].as_dense_vector())) == 1.0
    assert d[1, 1] == d[1, 2]
    assert d[1, 0] == d[1, 3]
    s, d = SF.calculate_scales_and_derivatives()

    # Test that if one or none in block, then doesn't fail but returns sensible value
    SF._normalised_values = [flex.double([0.5])]
    SF._n_refl = [1]
    assert list(SF.normalised_values[0]) == [0.5]
    s, d = SF.calculate_scales_and_derivatives()
    s2 = SF.calculate_scales()
    assert list(s) == list(s2)
    SF._normalised_values = [flex.double()]
    SF._n_refl = [0]
    assert list(SF.normalised_values[0]) == []
    s, d = SF.calculate_scales_and_derivatives()
    s2 = SF.calculate_scales()
    assert list(s) == list(s2)