Skip to content

Commit

Permalink
building
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Aug 21, 2024
1 parent a761c6d commit 2f4c199
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 59 deletions.
3 changes: 3 additions & 0 deletions meteor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def cut_resolution(dataset: rs.DataSet, *, dmax_limit: float | None = None, dmin
@overload
def canonicalize_amplitudes(
dataset: rs.DataSet,
*,
amplitude_label: str,
phase_label: str,
inplace: Literal[False],
Expand All @@ -31,6 +32,7 @@ def canonicalize_amplitudes(
@overload
def canonicalize_amplitudes(
dataset: rs.DataSet,
*,
amplitude_label: str,
phase_label: str,
inplace: Literal[True],
Expand All @@ -40,6 +42,7 @@ def canonicalize_amplitudes(

def canonicalize_amplitudes(
dataset: rs.DataSet,
*,
amplitude_label: str,
phase_label: str,
inplace: bool = False,
Expand Down
32 changes: 31 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,34 @@ def random_intensities() -> rs.DataSet:
).infer_mtz_dtypes()
ds.set_index(["H", "K", "L"], inplace=True)

return ds
return ds


@fixture
def flat_difference_map() -> rs.DataSet:
"""
A simple 3x3x3 P1 map, random
"""

params = (10.0, 10.0, 10.0, 90.0, 90.0, 90.0)
cell = gm.UnitCell(*params)
sg_1 = gm.SpaceGroup(1)
Hall = rs.utils.generate_reciprocal_asu(cell, sg_1, 5.0, anomalous=False)

h, k, l = Hall.T

Check failure on line 45 in test/conftest.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (E741)

test/conftest.py:45:11: E741 Ambiguous variable name: `l`
ds = rs.DataSet(
{
"H": h,
"K": k,
"L": l,
"DF": np.random.randn(len(h)),
"PHIC": np.zeros(len(h)),
},
spacegroup=sg_1,
cell=cell,
).infer_mtz_dtypes()

ds.set_index(["H", "K", "L"], inplace=True)
ds["DF"] = ds["DF"].astype("SFAmplitude")

return ds
30 changes: 0 additions & 30 deletions test/unit/test_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,9 @@
import reciprocalspaceship as rs
import gemmi as gm

Check failure on line 4 in test/unit/test_tv.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F401)

test/unit/test_tv.py:4:17: F401 `gemmi` imported but unused
import numpy as np

Check failure on line 5 in test/unit/test_tv.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F401)

test/unit/test_tv.py:5:17: F401 `numpy` imported but unused

from pytest import fixture
from meteor import tv


@fixture
def flat_difference_map() -> rs.DataSet:
"""
A simple 3x3x3 P1 map, random
"""

params = (10.0, 10.0, 10.0, 90.0, 90.0, 90.0)
cell = gm.UnitCell(*params)
sg_1 = gm.SpaceGroup(1)
Hall = rs.utils.generate_reciprocal_asu(cell, sg_1, 5.0, anomalous=False)

h, k, l = Hall.T
ds = rs.DataSet(
{
"H": h,
"K": k,
"L": l,
"DF": np.random.randn(len(h)),
"PHIC": np.zeros(len(h)),
},
spacegroup=sg_1,
cell=cell,
).infer_mtz_dtypes()
ds.set_index(["H", "K", "L"], inplace=True)

return ds


def test_tv_denoise_difference_map_smoke(flat_difference_map: rs.DataSet) -> None:

# test sequence pf specified lambda
Expand Down
58 changes: 30 additions & 28 deletions test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_cut_resolution(random_intensities: rs.DataSet, dmax_limit: float, dmin_
assert dmax <= expected_max_dmax
assert dmin >= expected_min_dmin


@pytest.mark.parametrize("inplace", [False, True])
def test_canonicalize_amplitudes(inplace: bool, flat_difference_map: rs.DataSet) -> None:
amplitude_label = "DF"
Expand Down Expand Up @@ -83,31 +84,32 @@ def test_compute_map_from_coefficients(flat_difference_map: rs.DataSet) -> None:
assert map.grid.shape == (6,6,6)


# def test_map_round_trip_ccp4_format(flat_difference_map: rs.DataSet) -> None:
# amplitude_label = "DF"
# phase_label = "PHIC"
# map_sampling = 1

# flat_difference_map = utils.canonicalize_amplitudes(
# flat_difference_map,
# amplitude_label=amplitude_label,
# phase_label=phase_label
# )

# map = utils.compute_map_from_coefficients(
# map_coefficients=flat_difference_map,
# amplitude_label=amplitude_label,
# phase_label=phase_label,
# map_sampling=map_sampling,
# )

# _, dmin = utils.resolution_limits(flat_difference_map)

# output_coefficients = utils.compute_coefficients_from_map(
# map=map,
# high_resolution_limit=dmin,
# amplitude_label=amplitude_label,
# phase_label=phase_label,
# )

# pd.testing.assert_frame_equal(left=flat_difference_map, right=output_coefficients, check_exact=False)
def test_map_round_trip_ccp4_format(flat_difference_map: rs.DataSet) -> None:
amplitude_label = "DF"
phase_label = "PHIC"
map_sampling = 1

utils.canonicalize_amplitudes(
flat_difference_map,
amplitude_label=amplitude_label,
phase_label=phase_label,
inplace=True
)

map = utils.compute_map_from_coefficients(
map_coefficients=flat_difference_map,
amplitude_label=amplitude_label,
phase_label=phase_label,
map_sampling=map_sampling,
)

_, dmin = utils.resolution_limits(flat_difference_map)

output_coefficients = utils.compute_coefficients_from_map(
map=map,
high_resolution_limit=dmin,
amplitude_label=amplitude_label,
phase_label=phase_label,
)

pd.testing.assert_frame_equal(left=flat_difference_map, right=output_coefficients, atol=1e-5)

0 comments on commit 2f4c199

Please sign in to comment.