Example #1
0
def test_SumIntensityReducer():
    """Test the methods of the SumIntensityReducer class"""
    reflections = generate_integrated_test_reflections()
    reflections = SumIntensityReducer.reduce_on_intensities(reflections)
    # reflections = reduce_on_summation_intensities(reflections)
    assert list(reflections["intensity.sum.value"]) == [11.0, 12.0, 13.0, 14.0]
    assert list(reflections["intensity.sum.variance"]) == [1.1, 1.2, 1.3, 1.4]

    reflections = generate_test_reflections_for_scaling()
    reflections = SumIntensityReducer.apply_scaling_factors(reflections)
    assert list(
        reflections["intensity.sum.value"]) == [110.0, 13.0, 14.0, 60.0, 8.0]
    assert list(reflections["intensity.sum.variance"]) == pytest.approx(
        [110.0, 1.3, 1.4, 24.0, 0.4])

    # check it still passes with no partiality correction
    reflections = generate_test_reflections_for_scaling()
    del reflections["partiality"]
    reflections = SumIntensityReducer.apply_scaling_factors(reflections)
    assert list(reflections["intensity.sum.value"]) == [
        11.0,
        12.0,
        13.0,
        14.0,
        60.0,
        8.0,
    ]

    # test IsgiI selecting
    r = flex.reflection_table()
    r["intensity.sum.value"] = flex.double([1.0, 2.0])
    r["intensity.sum.variance"] = flex.double([1.0, 1.0])
    r = SumIntensityReducer.filter_on_min_isigi(r, 1.5)
    assert list(r["intensity.sum.value"]) == [2.0]

    # now test a typical case - reflection table with inv scale factor,
    # check that we only apply that correction and do any relevant filtering
    reflections = generate_integrated_test_reflections()
    reflections["lp"] = flex.double(6, 2)
    reflections["partiality"] = flex.double([1.0, 1.0, 0.5, 0.1, 1.0, 1.0])
    reflections["d"] = flex.double([5.0, 5.0, 0.1, 5.0, 5.0, 5.0])
    reflections = SumIntensityReducer.filter_for_export(
        reflections, partiality_threshold=0.25, d_min=1.0)

    assert list(reflections["intensity.sum.value"]) == pytest.approx(
        [22.0, 24.0])
    assert list(reflections["intensity.sum.variance"]) == pytest.approx(
        [4.4, 4.8])

    assert "intensity.prf.value" not in reflections
    assert "intensity.scale.value" not in reflections
    assert "intensity.prf.variance" not in reflections
    assert "intensity.scale.variance" not in reflections
Example #2
0
def test_IntensityReducer_instantiations():
    """Test that all classes can be instantiated (have the required implemented
    methods) and have an intensities list with at least one str values"""
    allowed_intensities = FilterForExportAlgorithm.allowed_intensities
    SumIntensityReducer()
    assert all(i in allowed_intensities for i in SumIntensityReducer.intensities)
    PrfIntensityReducer()
    assert all(i in allowed_intensities for i in PrfIntensityReducer.intensities)
    SumAndPrfIntensityReducer()
    assert all(i in allowed_intensities for i in SumAndPrfIntensityReducer.intensities)
    ScaleIntensityReducer()
    assert all(i in allowed_intensities for i in ScaleIntensityReducer.intensities)