Skip to content

Commit

Permalink
test coverage, found and fixed small bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Oct 17, 2024
1 parent 8323f17 commit e47ba8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions meteor/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def negentropy_objective(tv_lambda: float):
high_resolution_limit=difference_map.resolution_limits[1],
)

# propogate uncertainties
if difference_map.has_uncertainties:
final_map.set_uncertainties(difference_map.uncertainties)

# sometimes `from_ccp4_map` adds reflections -- systematic absences or
# reflections just beyond the resolution limt; remove those
extra_indices = final_map.index.difference(difference_map.index)
Expand Down
22 changes: 17 additions & 5 deletions test/unit/test_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Sequence

import numpy as np
import pandas as pd
import pytest
import reciprocalspaceship as rs

from meteor import tv
from meteor.rsmap import Map
Expand All @@ -28,14 +28,14 @@ def rms_between_coefficients(map1: Map, map2: Map) -> float:
"lambda_values_to_scan",
[
None,
[0.01],
[-1.0, 0.0, 1.0],
],
)
@pytest.mark.parametrize("full_output", [False, True])
def test_tv_denoise_map_smoke(
lambda_values_to_scan: None | Sequence[float],
full_output: bool,
random_difference_map: rs.DataSet,
random_difference_map: Map,
) -> None:
output = tv.tv_denoise_difference_map(
random_difference_map,
Expand All @@ -44,10 +44,22 @@ def test_tv_denoise_map_smoke(
) # type: ignore[call-overload]
if full_output:
assert len(output) == 2
assert isinstance(output[0], rs.DataSet)
assert isinstance(output[0], Map)
assert isinstance(output[1], tv.TvDenoiseResult)
else:
assert isinstance(output, rs.DataSet)
assert isinstance(output, Map)


def test_tv_denoise_zero_weight(random_difference_map: Map) -> None:
weight = 0.0
output = tv.tv_denoise_difference_map(
random_difference_map,
lambda_values_to_scan=[weight],
full_output=False,
)
random_difference_map.canonicalize_amplitudes()
output.canonicalize_amplitudes()
pd.testing.assert_frame_equal(random_difference_map, output, rtol=1e-3)


@pytest.mark.parametrize("lambda_values_to_scan", [None, DEFAULT_LAMBDA_VALUES_TO_SCAN])
Expand Down

0 comments on commit e47ba8c

Please sign in to comment.