Skip to content

Commit

Permalink
prep for functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Oct 25, 2024
1 parent 639e2e9 commit 66cd12d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
7 changes: 7 additions & 0 deletions meteor/testing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path

import gemmi
import numpy as np
Expand All @@ -22,6 +23,12 @@ def assert_phases_allclose(array1: np.ndarray, array2: np.ndarray, atol: float =
raise AssertionError(msg)


def check_test_file_exists(path: Path) -> None:
if not path.exists():
msg = f"cannot find {path}, use github LFS to retrieve this file from the parent repo"
raise OSError(msg)

Check warning on line 29 in meteor/testing.py

View check run for this annotation

Codecov / codecov/patch

meteor/testing.py#L28-L29

Added lines #L28 - L29 were not covered by tests


def single_carbon_structure(
carbon_position: tuple[float, float, float],
space_group: gemmi.SpaceGroup,
Expand Down
9 changes: 9 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from meteor.testing import check_test_file_exists


@pytest.fixture(scope="session")
def data_dir() -> Path:
Expand All @@ -11,3 +13,10 @@ def data_dir() -> Path:
@pytest.fixture(scope="session")
def example_pdb_file(data_dir: Path) -> Path:
return data_dir / "8a6g.pdb"


@pytest.fixture(scope="session")
def testing_mtz(data_dir: Path) -> Path:
path = data_dir / "scaled-test-data.mtz"
check_test_file_exists(path)
return path
4 changes: 2 additions & 2 deletions test/data/scaled-test-data.mtz
Git LFS file not shown
Empty file.
38 changes: 38 additions & 0 deletions test/functional/test_scale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import reciprocalspaceship as rs
from numpy import testing as npt

from meteor.rsmap import Map
from meteor.scale import scale_maps


def test_scaling_regression(testing_mtz: Path) -> None:
ds = rs.read_mtz(str(testing_mtz))

on = Map(ds, amplitude_column="F_on", phase_column="PHI_k", uncertainty_column="SIGF_on")
off = Map(ds, amplitude_column="F_off", phase_column="PHI_k", uncertainty_column="SIGF_off")
calculated = Map(ds, amplitude_column="FC_nochrom", phase_column="PHI_k")

scaled_on_truth = Map(
ds,
amplitude_column="F_on_scaled",
phase_column="PHI_k",
uncertainty_column="SIGF_on_scaled",
)
scaled_off_truth = Map(
ds,
amplitude_column="F_off_scaled",
phase_column="PHI_k",
uncertainty_column="SIGF_off_scaled",
)

scaled_on = scale_maps(
map_to_scale=on, reference_map=calculated, weight_using_uncertainties=False
)
scaled_off = scale_maps(
map_to_scale=off, reference_map=calculated, weight_using_uncertainties=False
)

npt.assert_allclose(scaled_on.amplitudes, scaled_on_truth.amplitudes, atol=1e-3)
npt.assert_allclose(scaled_off.amplitudes, scaled_off_truth.amplitudes, atol=1e-3)
46 changes: 0 additions & 46 deletions test/functional/test_scripts.py

This file was deleted.

4 changes: 2 additions & 2 deletions test/unit/scripts/test_compute_difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from meteor.tv import TvDenoiseResult

# ensure tests complete quickly by monkey-patching a limited number of weights
compute_difference_map.TV_WEIGHTS_TO_SCAN = np.linspace(0.0, 0.1, 10)
compute_difference_map.TV_WEIGHTS_TO_SCAN = np.linspace(0.0, 0.1, 6)


@pytest.fixture
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_denoise_diffmap(mode: WeightMode, random_difference_map: Map) -> None:
assert isinstance(metadata, TvDenoiseResult)

if mode == WeightMode.optimize:
assert np.isclose(metadata.optimal_weight, 0.05555555555555556)
assert np.isclose(metadata.optimal_weight, 0.06)
elif mode == WeightMode.fixed:
assert metadata.optimal_weight == 0.1
with pytest.raises(TypeError):
Expand Down

0 comments on commit 66cd12d

Please sign in to comment.