def test_PrfIntensityReducer(): """Test the methods of the PrfIntensityReducer class""" reflections = generate_integrated_test_reflections() reflections = PrfIntensityReducer.reduce_on_intensities(reflections) assert list(reflections["intensity.prf.value"]) == [1.0, 2.0, 3.0, 6.0] assert list(reflections["intensity.prf.variance"]) == [0.1, 0.2, 0.3, 0.6] reflections = generate_test_reflections_for_scaling() reflections = PrfIntensityReducer.apply_scaling_factors(reflections) assert list(reflections["intensity.prf.value"]) == [1.0, 3.0, 4.0, 20.0, 3.0] assert list(reflections["intensity.prf.variance"]) == pytest.approx( [0.1, 0.3, 0.4, 0.5 * 16.0, 0.6 * 0.25] ) # check it still passes with no partiality correction reflections = generate_test_reflections_for_scaling() del reflections["partiality"] reflections = PrfIntensityReducer.apply_scaling_factors(reflections) assert list(reflections["intensity.prf.value"]) == [1.0, 2.0, 3.0, 4.0, 20.0, 3.0] # test IsgiI selecting r = flex.reflection_table() r["intensity.prf.value"] = flex.double([1.0, 2.0]) r["intensity.prf.variance"] = flex.double([1.0, 1.0]) r = PrfIntensityReducer.filter_on_min_isigi(r, 1.5) assert list(r["intensity.prf.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["qe"] = flex.double(6, 2) reflections = PrfIntensityReducer.filter_for_export(reflections) assert list(reflections["intensity.prf.value"]) == pytest.approx( [1.0 / 2.0, 2.0 / 2.0, 3.0 / 2.0, 6.0 / 2.0] ) assert list(reflections["intensity.prf.variance"]) == pytest.approx( [0.1 / 4.0, 0.2 / 4.0, 0.3 / 4.0, 0.6 / 4.0] ) assert list(reflections["fractioncalc"]) == [1.0] * 4 assert "intensity.sum.value" not in reflections assert "intensity.scale.value" not in reflections assert "intensity.sum.variance" not in reflections assert "intensity.scale.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 test_checks_in_reduce_data_for_export(): """Test for graceful failures if serious problems with the data are found.""" # If no valid ids, should raise sorry r = flex.reflection_table() r["id"] = flex.int([-1, -1, -1]) r["intensity.prf.value"] = flex.double(3, 1.0) r["intensity.prf.variance"] = flex.double(3, 1.0) with pytest.raises(ValueError): r = PrfIntensityReducer.filter_for_export(r) # If no valid prf, should raise NoProfilesException r = flex.reflection_table() r["id"] = flex.int([0, 0]) r["intensity.prf.value"] = flex.double([1.0, 2.0]) r["intensity.prf.variance"] = flex.double([0.0, 1.0]) r.set_flags(flex.bool([False, False]), r.flags.integrated_prf) with pytest.raises(NoProfilesException): r = PrfIntensityReducer.filter_for_export(r) r.set_flags(flex.bool([True, True]), r.flags.integrated_prf) # Should filter bad variances r = PrfIntensityReducer.filter_bad_variances(r) assert r.size() == 1 # If reflection table is empty r = flex.reflection_table() with pytest.raises(AssertionError): r = PrfIntensityReducer.filter_for_export(r) # What if all ice ring r = generate_simple_table() r.set_flags(flex.bool([True, True, True]), r.flags.in_powder_ring) with pytest.raises(ValueError): _ = PrfIntensityReducer.filter_for_export(r, filter_ice_rings=True, min_isigi=1.0, partiality_threshold=0.99) # What if none left on SigI r = generate_simple_table() with pytest.raises(ValueError): _ = PrfIntensityReducer.filter_for_export(r, filter_ice_rings=False, min_isigi=4.0, partiality_threshold=0.99)