def test_SumAndPrfIntensityReducer():
    """Test that the reflection table is reduced on prf and sum intensities"""
    reflections = generate_integrated_test_reflections()
    reflections = SumAndPrfIntensityReducer.reduce_on_intensities(reflections)
    assert list(reflections["intensity.prf.value"]) == [1.0, 2.0, 3.0]
    assert list(reflections["intensity.prf.variance"]) == [0.1, 0.2, 0.3]
    assert list(reflections["intensity.sum.value"]) == [11.0, 12.0, 13.0]
    assert list(reflections["intensity.sum.variance"]) == [1.1, 1.2, 1.3]

    reflections["lp"] = flex.double([0.5, 0.5, 1.0])
    reflections["partiality"] = flex.double([0.0, 1.0, 1.0])
    reflections = SumAndPrfIntensityReducer.apply_scaling_factors(reflections)
    assert list(reflections["intensity.prf.value"]) == [1.0, 3.0]
    assert list(reflections["intensity.prf.variance"]) == [0.2 * 0.25, 0.3]
    assert list(reflections["intensity.sum.value"]) == [6.0, 13.0]
    assert list(reflections["intensity.sum.variance"]) == [0.3, 1.3]

    # test IsgiI selecting
    r = flex.reflection_table()
    r["intensity.prf.value"] = flex.double([1.0, 2.0, 3.0])
    r["intensity.prf.variance"] = flex.double([1.0, 1.0, 1.0])
    r["intensity.sum.value"] = flex.double([1.0, 2.0, 3.0])
    r["intensity.sum.variance"] = flex.double([1.0, 1.1, 1.0])
    r = SumAndPrfIntensityReducer.filter_on_min_isigi(r, 1.999)
    assert list(r["intensity.prf.value"]) == [3.0]

    # test bad variance filtering
    r = flex.reflection_table()
    r["intensity.prf.value"] = flex.double([1.0, 2.0, 3.0])
    r["intensity.prf.variance"] = flex.double([0.0, 1.0, 1.0])
    r["intensity.sum.value"] = flex.double([1.0, 2.0, 3.0])
    r["intensity.sum.variance"] = flex.double([1.0, 0.0, 1.0])
    r.set_flags(flex.bool([True, True, True]), r.flags.integrated_prf)
    r.set_flags(flex.bool([True, True, True]), r.flags.integrated_sum)
    r = SumAndPrfIntensityReducer.filter_bad_variances(r)
    assert list(r["intensity.prf.value"]) == [3.0]

    # test filtering for export
    reflections = generate_integrated_test_reflections()
    reflections = SumAndPrfIntensityReducer.filter_for_export(reflections)
    assert "intensity.scale.value" not in reflections
    assert "intensity.scale.variance" not in reflections
Esempio n. 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)
Esempio n. 3
0
def setup_dials_models(refls, expts):

    ### Initial setting up of data
    dose = flex.ceil(refls["xyzobs.px.value"].parts()[2])
    refls["dose"] = dose.iround()

    # want to get scaled data with outliers still present
    excluded = refls.get_flags(
        refls.flags.excluded_for_scaling) | refls.get_flags(
            refls.flags.user_excluded_in_scaling)
    good = ~excluded
    refls = refls.select(good)  # still has outliers
    refls = ScaleIntensityReducer.apply_scaling_factors(refls)
    scaled_refls = SumAndPrfIntensityReducer.apply_scaling_factors(refls)

    sg = expts[0].crystal.get_space_group()
    uc = expts[0].crystal.get_unit_cell()

    asu_index_s, d_s = map_indices_to_asu(scaled_refls["miller_index"], sg, uc)
    anom_index_s, _ = map_indices_to_asu(scaled_refls["miller_index"],
                                         sg,
                                         uc,
                                         anom=True)
    ### finished initial setting up, now know indices

    ### Get relevant data and sort by asu index
    intensity_s = scaled_refls["intensity.scale.value"]
    sigma_s = scaled_refls["intensity.scale.variance"]**0.5
    dose_s = scaled_refls["dose"]

    integrated_refls = scaled_refls
    intensity_u = integrated_refls["intensity.prf.value"]
    sigma_u = flex.sqrt(integrated_refls["intensity.prf.variance"])

    isel_s = flex.sort_permutation(d_s, reverse=True)
    sorted_asu_s = asu_index_s.select(isel_s)
    sorted_anom_s = anom_index_s.select(isel_s)
    scaled_groups = list(OrderedSet(sorted_asu_s))
    outliers = scaled_refls.get_flags(scaled_refls.flags.outlier_in_scaling)

    Data = collections.namedtuple(
        "Data",
        ["intensity", "sigma", "dose", "asu_index", "anom_index", "outliers"])

    data = Data(
        intensity=intensity_s.select(isel_s),
        sigma=sigma_s.select(isel_s),
        dose=dose_s.select(isel_s),
        asu_index=sorted_asu_s,
        anom_index=sorted_anom_s,
        outliers=outliers.select(isel_s),
    )
    dials_scaled = DialsScaledModel(data)

    unscaled_data = Data(
        intensity=intensity_u.select(isel_s),
        sigma=sigma_u.select(isel_s),
        dose=dose_s.select(isel_s),
        asu_index=sorted_asu_s,
        anom_index=sorted_anom_s,
        outliers=None,
    )
    dials_unscaled = DialsUnScaledModel(unscaled_data)
    return [dials_scaled, dials_unscaled], scaled_groups, uc, sg