Skip to content

Commit

Permalink
remove index matching code
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Nov 3, 2024
1 parent 498d591 commit 7555b5e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion meteor/diffmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import reciprocalspaceship as rs

from .rsmap import Map, _assert_is_map
from .settings import DEFAULT_KPARAMS_TO_SCAN, MAP_SAMPLING
from .settings import DEFAULT_KPARAMS_TO_SCAN
from .utils import filter_common_indices
from .validate import ScalarMaximizer, map_negentropy

Expand Down
1 change: 0 additions & 1 deletion meteor/scripts/compute_difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from typing import Any

import numpy as np
import structlog

from meteor.rsmap import Map
Expand Down
9 changes: 0 additions & 9 deletions meteor/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ def negentropy_objective(tv_weight: float) -> float:
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)
final_map.drop(extra_indices, inplace=True)
sym_diff = difference_map.index.symmetric_difference(final_map.index)
if len(sym_diff) > 0:
msg = "something went wrong, input and output coefficients do not have identical indices"
raise IndexError(msg)

if full_output:
initial_negentropy = negentropy(realspace_map_array)
tv_result = TvDenoiseResult(
Expand Down
11 changes: 6 additions & 5 deletions meteor/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import numpy as np
from scipy.optimize import minimize_scalar
from scipy.stats import differential_entropy
from .settings import MAP_SAMPLING

from .rsmap import Map
from .settings import MAP_SAMPLING


def negentropy(samples: np.ndarray, *, tolerance: float = 0.1) -> float:
Expand Down Expand Up @@ -63,7 +64,7 @@ def negentropy(samples: np.ndarray, *, tolerance: float = 0.1) -> float:
return float(neg_e)


def map_negentropy(map: Map, *, tolerance: float = 0.1) -> float:
def map_negentropy(map_to_assess: Map, *, tolerance: float = 0.1) -> float:
"""
Computes the negentropy of a crystallographic map.
Expand All @@ -74,8 +75,8 @@ def map_negentropy(map: Map, *, tolerance: float = 0.1) -> float:
Parameters
----------
samples: np.ndarray
A numpy array of sample data for which to calculate the negentropy.
map_to_assess: Map
The map (coefficients) we will compute the negentropy for.
tolerance: float
Tolerance level determining if the negentropy is suspiciously negative. Defaults to 0.1.
Expand All @@ -90,7 +91,7 @@ def map_negentropy(map: Map, *, tolerance: float = 0.1) -> float:
ValueError: If the computed negentropy is less than the negative tolerance,
indicating potential issues with the computation.
"""
realspace_map = map.to_ccp4_map(map_sampling=MAP_SAMPLING)
realspace_map = map_to_assess.to_ccp4_map(map_sampling=MAP_SAMPLING)
realspace_map_array = np.array(realspace_map.grid)
return negentropy(realspace_map_array, tolerance=tolerance)

Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ def rms_to_noise_free(test_map: Map) -> float:
)


def test_final_map_has_reported_negentropy(random_difference_map: Map) -> None:
def test_final_map_has_reported_negentropy(noisy_map: Map) -> None:
# regression test -- previously the written map had different indices --> discrepency
weight = 0.01
output_map, metadata = tv.tv_denoise_difference_map(
random_difference_map,
noisy_map,
weights_to_scan=[weight],
full_output=True,
)
actual_negentropy = map_negentropy(output_map)
assert np.isclose(actual_negentropy, metadata.optimal_negentropy), "final/metadata mismatch"
assert np.isclose(actual_negentropy, metadata.negentropy_at_weights[-1]), "final/optimizer"
assert np.isclose(actual_negentropy, metadata.negentropy_at_weights[-1]), "final/optimizer"

0 comments on commit 7555b5e

Please sign in to comment.