From 7555b5ec1aaab974fa6ff08072a6aa33abb584df Mon Sep 17 00:00:00 2001 From: tjlane Date: Sun, 3 Nov 2024 18:20:18 +0000 Subject: [PATCH] remove index matching code --- meteor/diffmaps.py | 2 +- meteor/scripts/compute_difference_map.py | 1 - meteor/tv.py | 9 --------- meteor/validate.py | 11 ++++++----- test/unit/test_tv.py | 6 +++--- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/meteor/diffmaps.py b/meteor/diffmaps.py index b555f88..37d8143 100644 --- a/meteor/diffmaps.py +++ b/meteor/diffmaps.py @@ -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 diff --git a/meteor/scripts/compute_difference_map.py b/meteor/scripts/compute_difference_map.py index de554b6..d631289 100644 --- a/meteor/scripts/compute_difference_map.py +++ b/meteor/scripts/compute_difference_map.py @@ -4,7 +4,6 @@ from typing import Any -import numpy as np import structlog from meteor.rsmap import Map diff --git a/meteor/tv.py b/meteor/tv.py index 0cec605..364bf96 100644 --- a/meteor/tv.py +++ b/meteor/tv.py @@ -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( diff --git a/meteor/validate.py b/meteor/validate.py index 93a2cc1..eaa247f 100644 --- a/meteor/validate.py +++ b/meteor/validate.py @@ -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: @@ -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. @@ -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. @@ -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) diff --git a/test/unit/test_tv.py b/test/unit/test_tv.py index f8a945f..baf597c 100644 --- a/test/unit/test_tv.py +++ b/test/unit/test_tv.py @@ -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" \ No newline at end of file + assert np.isclose(actual_negentropy, metadata.negentropy_at_weights[-1]), "final/optimizer"