Skip to content

Commit

Permalink
comments from @alisiafadini
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Aug 22, 2024
1 parent 7dd2fb2 commit 08ef8be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion meteor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@dataclass
class MapLabels:
amplitude: str
phases: str
phase: str


def resolution_limits(dataset: rs.DataSet) -> tuple[float, float]:
Expand Down
4 changes: 2 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def diffmap_labels() -> MapLabels:
return MapLabels(
amplitude="DF",
phases="PHIC",
phase="PHIC",
)


Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions test/unit/test_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -116,7 +116,7 @@ def noisy_map() -> rs.DataSet:
[
None,
[
1.0,
0.01,
],
],
)
Expand Down Expand Up @@ -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")
21 changes: 13 additions & 8 deletions test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])),
Expand All @@ -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)
Expand All @@ -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,
)

Expand All @@ -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)

0 comments on commit 08ef8be

Please sign in to comment.