From 08ef8be4944f0024392d66965006817ab68e8e83 Mon Sep 17 00:00:00 2001 From: tjlane Date: Thu, 22 Aug 2024 19:00:27 +0100 Subject: [PATCH] comments from @alisiafadini --- meteor/utils.py | 2 +- test/conftest.py | 4 ++-- test/unit/test_tv.py | 12 ++++++------ test/unit/test_utils.py | 21 +++++++++++++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/meteor/utils.py b/meteor/utils.py index a581e83..e6142de 100644 --- a/meteor/utils.py +++ b/meteor/utils.py @@ -11,7 +11,7 @@ @dataclass class MapLabels: amplitude: str - phases: str + phase: str def resolution_limits(dataset: rs.DataSet) -> tuple[float, float]: diff --git a/test/conftest.py b/test/conftest.py index 2994b85..b0bd51a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -10,7 +10,7 @@ def diffmap_labels() -> MapLabels: return MapLabels( amplitude="DF", - phases="PHIC", + phase="PHIC", ) @@ -30,7 +30,7 @@ def random_difference_map(diffmap_labels: MapLabels) -> rs.DataSet: "K": k, "L": l, diffmap_labels.amplitude: np.random.randn(number_of_reflections), - diffmap_labels.phases: np.random.uniform(-180, 180, size=number_of_reflections), + diffmap_labels.phase: np.random.uniform(-180, 180, size=number_of_reflections), }, spacegroup=space_group, cell=cell, diff --git a/test/unit/test_tv.py b/test/unit/test_tv.py index 2a672bb..51b2679 100644 --- a/test/unit/test_tv.py +++ b/test/unit/test_tv.py @@ -80,13 +80,13 @@ def rms_between_coefficients(ds1: rs.DataSet, ds2: rs.DataSet, diffmap_labels: M map1 = compute_map_from_coefficients( map_coefficients=ds1, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, map_sampling=3, ) map2 = compute_map_from_coefficients( map_coefficients=ds2, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, map_sampling=3, ) @@ -116,7 +116,7 @@ def noisy_map() -> rs.DataSet: [ None, [ - 1.0, + 0.01, ], ], ) @@ -160,21 +160,21 @@ def test_tv_denoise_difference_map( # testmap = compute_map_from_coefficients( # map_coefficients=noise_free_map, # amplitude_label=diffmap_labels.amplitude, - # phase_label=diffmap_labels.phases, + # phase_label=diffmap_labels.phase, # map_sampling=1, # ) # testmap.write_ccp4_map("original.ccp4") # testmap = compute_map_from_coefficients( # map_coefficients=noisy_map, # amplitude_label=diffmap_labels.amplitude, - # phase_label=diffmap_labels.phases, + # phase_label=diffmap_labels.phase, # map_sampling=1, # ) # testmap.write_ccp4_map("noisy.ccp4") # testmap = compute_map_from_coefficients( # map_coefficients=denoised_map, # amplitude_label=diffmap_labels.amplitude, - # phase_label=diffmap_labels.phases, + # phase_label=diffmap_labels.phase, # map_sampling=1, # ) # testmap.write_ccp4_map("denoised.ccp4") diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index 36ea611..dcdb2fb 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -50,25 +50,30 @@ def test_cut_resolution( def test_canonicalize_amplitudes( inplace: bool, random_difference_map: rs.DataSet, diffmap_labels: utils.MapLabels ) -> None: + # ensure at least one amplitude is negative, one phase is outside [-180,180) + index_single_hkl = 0 + random_difference_map.loc[index_single_hkl, diffmap_labels.amplitude] = -1.0 + random_difference_map.loc[index_single_hkl, diffmap_labels.phase] = -470.0 + if inplace: canonicalized = random_difference_map utils.canonicalize_amplitudes( canonicalized, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, inplace=inplace, ) else: canonicalized = utils.canonicalize_amplitudes( random_difference_map, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, inplace=inplace, ) assert (canonicalized[diffmap_labels.amplitude] >= 0.0).all(), "not all amplitudes positive" - assert (canonicalized[diffmap_labels.phases] >= -180.0).all(), "not all phases > -180" - assert (canonicalized[diffmap_labels.phases] <= 180.0).all(), "not all phases < +180" + assert (canonicalized[diffmap_labels.phase] >= -180.0).all(), "not all phases > -180" + assert (canonicalized[diffmap_labels.phase] <= 180.0).all(), "not all phases < +180" np.testing.assert_almost_equal( np.array(np.abs(random_difference_map[diffmap_labels.amplitude])), @@ -82,7 +87,7 @@ def test_compute_map_from_coefficients( map = utils.compute_map_from_coefficients( map_coefficients=random_difference_map, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, map_sampling=1, ) assert isinstance(map, gemmi.Ccp4Map) @@ -95,7 +100,7 @@ def test_map_to_coefficients_round_trip( map = utils.compute_map_from_coefficients( map_coefficients=random_difference_map, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, map_sampling=map_sampling, ) @@ -105,13 +110,13 @@ def test_map_to_coefficients_round_trip( ccp4_map=map, high_resolution_limit=dmin, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, ) utils.canonicalize_amplitudes( output_coefficients, amplitude_label=diffmap_labels.amplitude, - phase_label=diffmap_labels.phases, + phase_label=diffmap_labels.phase, inplace=True, ) pd.testing.assert_frame_equal(left=random_difference_map, right=output_coefficients, atol=0.5)