def test_ScaleIntensityReducer(): """Test that the reflection table is reduced on scaling intensities""" reflections = generate_integrated_test_reflections() reflections = ScaleIntensityReducer.reduce_on_intensities(reflections) assert list(reflections["intensity.scale.value"]) == pytest.approx( [23.0, 24.0, 25.0]) assert list(reflections["intensity.scale.variance"]) == pytest.approx( [2.3, 2.4, 2.5]) del reflections["inverse_scale_factor"] with pytest.raises(AssertionError): reflections = ScaleIntensityReducer.reduce_on_intensities(reflections) reflections = generate_test_reflections_for_scaling() reflections = ScaleIntensityReducer.apply_scaling_factors(reflections) assert list(reflections["intensity.scale.value"]) == pytest.approx([ 21.0 / 5.0, 23.0 / 5.0, 24.0 / 10.0, 25.0 / 10.0, 26.0 / 10.0, 27.0 / 10.0 ]) assert list(reflections["intensity.scale.variance"]) == pytest.approx( [2.1 / 25.0, 2.3 / 25.0, 2.4 / 100, 2.5 / 100, 2.6 / 100, 2.7 / 100]) del reflections["inverse_scale_factor"] with pytest.raises(AssertionError): reflections = ScaleIntensityReducer.apply_scaling_factors(reflections) reflections = generate_test_reflections_for_scaling() del reflections["partiality"] reflections = ScaleIntensityReducer.apply_scaling_factors(reflections) assert list(reflections["intensity.scale.value"]) == [ 21.0 / 5.0, 22.0 / 5.0, 23.0 / 5.0, 24.0 / 10.0, 25.0 / 10.0, 26.0 / 10.0, 27.0 / 10.0, ] # test IsgiI selecting r = flex.reflection_table() r["intensity.scale.value"] = flex.double([1.0, 2.0]) r["intensity.scale.variance"] = flex.double([1.0, 1.0]) r = ScaleIntensityReducer.filter_on_min_isigi(r, 1.5) assert list(r["intensity.scale.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, 0.6) reflections = ScaleIntensityReducer.filter_for_export(reflections) assert list(reflections["intensity.scale.value"]) == pytest.approx( [23.0 / 5.0, 24.0 / 10.0, 25.0 / 10.0]) assert list(reflections["intensity.scale.variance"]) == pytest.approx( [2.3 / 25.0, 0.024, 0.025]) assert "intensity.prf.value" not in reflections assert "intensity.sum.value" not in reflections assert "intensity.prf.variance" not in reflections assert "intensity.sum.variance" not in reflections
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)
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