pytme 0.3.1__tar.gz → 0.3.1.post1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytme-0.3.1 → pytme-0.3.1.post1}/PKG-INFO +2 -4
- {pytme-0.3.1 → pytme-0.3.1.post1}/pyproject.toml +2 -3
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/postprocess.py +15 -14
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_analyzer.py +2 -3
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_extensions.py +0 -1
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/analyzer/aggregation.py +22 -12
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/_jax_utils.py +13 -2
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/cupy_backend.py +11 -11
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/jax_backend.py +19 -1
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/matching_backend.py +11 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/npfftw_backend.py +3 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/matching_data.py +24 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/matching_exhaustive.py +5 -2
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/matching_scores.py +23 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/orientations.py +9 -2
- {pytme-0.3.1 → pytme-0.3.1.post1}/LICENSE +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/MANIFEST.in +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/README.md +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/pytme.egg-info/SOURCES.txt +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/estimate_memory_usage.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/eval.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/extract_candidates.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/match_template.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/match_template_filters.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/preprocess.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/preprocessor_gui.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/pytme_runner.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/scripts/refine_matches.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/setup.cfg +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/setup.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/.DS_Store +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/.DS_Store +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/blob_width18.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/edgegaussian_sigma3.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/gaussian_sigma2.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/hamming_width6.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/kaiserb_width18.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/localgaussian_sigma0510.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/mean_size5.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/ntree_sigma0510.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Blurring/rank_rank3.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Maps/.DS_Store +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Maps/emd_8621.mrc.gz +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/README.md +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Raw/.DS_Store +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Raw/em_map.map +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/.DS_Store +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/1pdj.cif +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/1pdj.pdb +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/5khe.cif +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/5khe.ent +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/5khe.pdb +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/data/Structures/5uz4.cif +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/preprocessing/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/preprocessing/test_compose.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/preprocessing/test_frequency_filters.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/preprocessing/test_preprocessor.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/preprocessing/test_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_backends.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_density.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_matching_cli.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_matching_data.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_matching_exhaustive.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_matching_memory.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_matching_optimization.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_matching_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_orientations.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_parser.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_rotations.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tests/test_structure.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/__version__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/analyzer/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/analyzer/_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/analyzer/base.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/analyzer/peaks.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/analyzer/proxy.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/_cupy_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/_numpyfftw_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/mlx_backend.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/backends/pytorch_backend.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/cli.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48n309.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48n527.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48n9.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u1.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u1153.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u1201.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u1641.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u181.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u2219.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u27.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u2947.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u3733.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u4749.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u5879.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u7111.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u815.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u83.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c48u8649.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c600v.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/c600vc.npy +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/metadata.yaml +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/quat_to_numpy.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/data/scattering_factors.pickle +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/density.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/external/bindings.cpp +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/__init__.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/bandpass.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/compose.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/ctf.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/reconstruction.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/wedge.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/filters/whitening.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/mask.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/matching_optimization.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/matching_utils.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/memory.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/parser.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/preprocessor.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/rotations.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/structure.py +0 -0
- {pytme-0.3.1 → pytme-0.3.1.post1}/tme/types.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pytme
|
3
|
-
Version: 0.3.1
|
3
|
+
Version: 0.3.1.post1
|
4
4
|
Summary: Python Template Matching Engine
|
5
5
|
Author: Valentin Maurer
|
6
6
|
Author-email: Valentin Maurer <valentin.maurer@embl-hamburg.de>
|
@@ -26,9 +26,7 @@ Requires-Dist: importlib_resources
|
|
26
26
|
Requires-Dist: joblib
|
27
27
|
Provides-Extra: cupy
|
28
28
|
Requires-Dist: cupy-cuda12x>13.0.0; extra == "cupy"
|
29
|
-
|
30
|
-
Requires-Dist: cupy-cuda12x>13.0.0; extra == "cupy-voltools"
|
31
|
-
Requires-Dist: voltools; extra == "cupy-voltools"
|
29
|
+
Requires-Dist: voltools; extra == "cupy"
|
32
30
|
Provides-Extra: pytorch
|
33
31
|
Requires-Dist: torch; extra == "pytorch"
|
34
32
|
Requires-Dist: torchvision; extra == "pytorch"
|
@@ -7,7 +7,7 @@ name="pytme"
|
|
7
7
|
authors = [
|
8
8
|
{ name = "Valentin Maurer", email = "valentin.maurer@embl-hamburg.de" },
|
9
9
|
]
|
10
|
-
version="0.3.1"
|
10
|
+
version="0.3.1.post1"
|
11
11
|
description="Python Template Matching Engine"
|
12
12
|
readme="README.md"
|
13
13
|
requires-python = ">=3.11"
|
@@ -33,8 +33,7 @@ classifiers = [
|
|
33
33
|
]
|
34
34
|
|
35
35
|
[project.optional-dependencies]
|
36
|
-
cupy = ["cupy-cuda12x>13.0.0"]
|
37
|
-
cupy_voltools = ["cupy-cuda12x>13.0.0", "voltools"]
|
36
|
+
cupy = ["cupy-cuda12x>13.0.0", "voltools"]
|
38
37
|
pytorch = ["torch", "torchvision"]
|
39
38
|
jax = ["jax[cuda12]", "jaxlib"]
|
40
39
|
jax_cpu = ["jax", "jaxlib"]
|
@@ -188,7 +188,7 @@ def parse_args():
|
|
188
188
|
)
|
189
189
|
additional_group.add_argument(
|
190
190
|
"--n-false-positives",
|
191
|
-
type=
|
191
|
+
type=float,
|
192
192
|
default=None,
|
193
193
|
required=False,
|
194
194
|
help="Number of accepted false-positives picks to determine minimum score.",
|
@@ -318,11 +318,7 @@ def normalize_input(foregrounds: Tuple[str], backgrounds: Tuple[str]) -> Tuple:
|
|
318
318
|
data = load_matching_output(foreground)
|
319
319
|
scores, _, rotations, rotation_mapping, *_ = data
|
320
320
|
|
321
|
-
# We could normalize to unit sdev, but that might lead to unexpected
|
322
|
-
# results for flat background distributions
|
323
|
-
# scores -= scores.mean()
|
324
321
|
indices = tuple(slice(0, x) for x in scores.shape)
|
325
|
-
|
326
322
|
indices_update = scores > scores_out[indices]
|
327
323
|
scores_out[indices][indices_update] = scores[indices_update]
|
328
324
|
|
@@ -369,9 +365,7 @@ def normalize_input(foregrounds: Tuple[str], backgrounds: Tuple[str]) -> Tuple:
|
|
369
365
|
scores_norm = np.full(out_shape_norm, fill_value=0, dtype=np.float32)
|
370
366
|
for background in backgrounds:
|
371
367
|
data_norm = load_matching_output(background)
|
372
|
-
|
373
|
-
scores = data_norm[0]
|
374
|
-
# scores -= scores.mean()
|
368
|
+
scores, _, rotations, rotation_mapping, *_ = data_norm
|
375
369
|
|
376
370
|
indices = tuple(slice(0, x) for x in scores.shape)
|
377
371
|
indices_update = scores > scores_norm[indices]
|
@@ -381,6 +375,7 @@ def normalize_input(foregrounds: Tuple[str], backgrounds: Tuple[str]) -> Tuple:
|
|
381
375
|
update = tuple(slice(0, int(x)) for x in np.minimum(out_shape, scores.shape))
|
382
376
|
scores_out = np.full(out_shape, fill_value=0, dtype=np.float32)
|
383
377
|
scores_out[update] = data[0][update] - scores_norm[update]
|
378
|
+
scores_out[update] += scores_norm[update].mean()
|
384
379
|
|
385
380
|
# scores_out[update] = np.divide(scores_out[update], 1 - scores_norm[update])
|
386
381
|
scores_out = np.fmax(scores_out, 0, out=scores_out)
|
@@ -485,8 +480,11 @@ def main():
|
|
485
480
|
if orientations is None:
|
486
481
|
translations, rotations, scores, details = [], [], [], []
|
487
482
|
|
488
|
-
|
489
|
-
|
483
|
+
var = None
|
484
|
+
# Data processed by normalize_input is guaranteed to have this shape)
|
485
|
+
scores, _, rotation_array, rotation_mapping, *_ = data
|
486
|
+
if len(data) == 6:
|
487
|
+
scores, _, rotation_array, rotation_mapping, var, *_ = data
|
490
488
|
|
491
489
|
cropped_shape = np.subtract(
|
492
490
|
scores.shape, np.multiply(args.min_boundary_distance, 2)
|
@@ -509,13 +507,16 @@ def main():
|
|
509
507
|
)
|
510
508
|
args.n_false_positives = max(args.n_false_positives, 1)
|
511
509
|
n_correlations = np.size(scores[cropped_slice]) * len(rotation_mapping)
|
510
|
+
std = np.std(scores[cropped_slice])
|
511
|
+
if var is not None:
|
512
|
+
std = np.asarray(np.sqrt(var)).reshape(())
|
513
|
+
|
512
514
|
minimum_score = np.multiply(
|
513
515
|
erfcinv(2 * args.n_false_positives / n_correlations),
|
514
|
-
np.sqrt(2) *
|
516
|
+
np.sqrt(2) * std,
|
515
517
|
)
|
516
|
-
print(f"Determined
|
517
|
-
|
518
|
-
args.min_score = minimum_score
|
518
|
+
print(f"Determined cutoff --min-score {minimum_score}.")
|
519
|
+
args.min_score = max(minimum_score, 0)
|
519
520
|
|
520
521
|
args.batch_dims = None
|
521
522
|
if hasattr(cli_args, "batch_dims"):
|
@@ -165,7 +165,6 @@ class TestMaxScoreOverRotations:
|
|
165
165
|
assert res[0].dtype == be._float_dtype
|
166
166
|
assert res[1].size == self.data.ndim
|
167
167
|
assert np.allclose(res[2].shape, self.data.shape)
|
168
|
-
assert len(res) == 4
|
169
168
|
|
170
169
|
@pytest.mark.parametrize("use_memmap", [False, True])
|
171
170
|
@pytest.mark.parametrize("score_threshold", [0, 1e10, -1e10])
|
@@ -181,7 +180,7 @@ class TestMaxScoreOverRotations:
|
|
181
180
|
|
182
181
|
data2 = self.data * 2
|
183
182
|
score_analyzer(state, data2, rotation_matrix=self.rotation_matrix)
|
184
|
-
scores,
|
183
|
+
scores, offset, rotations, mapping, *_ = score_analyzer.result(state)
|
185
184
|
|
186
185
|
assert np.all(scores >= score_threshold)
|
187
186
|
max_scores = np.maximum(self.data, data2)
|
@@ -214,7 +213,7 @@ class TestMaxScoreOverRotations:
|
|
214
213
|
ret = MaxScoreOverRotations.merge(
|
215
214
|
results=states, use_memmap=use_memmap, score_threshold=score_threshold
|
216
215
|
)
|
217
|
-
scores, translation, rotations, mapping = ret
|
216
|
+
scores, translation, rotations, mapping, *_ = ret
|
218
217
|
assert np.all(scores >= score_threshold)
|
219
218
|
max_scores = np.maximum(self.data, data2)
|
220
219
|
max_scores = np.maximum(max_scores, score_threshold)
|
@@ -53,7 +53,6 @@ class TestExtensions:
|
|
53
53
|
@pytest.mark.parametrize("min_distance", [0, 5, 10])
|
54
54
|
def test_find_candidate_indices(self, dimension, dtype, min_distance):
|
55
55
|
coordinates = COORDINATES[dimension].astype(dtype)
|
56
|
-
print(coordinates.shape)
|
57
56
|
|
58
57
|
min_distance = np.array([min_distance]).astype(dtype)[0]
|
59
58
|
|
@@ -132,12 +132,14 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
132
132
|
- scores : BackendArray of shape `self._shape` filled with `score_threshold`.
|
133
133
|
- rotations : BackendArray of shape `self._shape` filled with -1.
|
134
134
|
- rotation_mapping : dict, empty mapping from rotation bytes to indices.
|
135
|
+
- ssum : BackendArray, accumulator for sum of squared scores.
|
135
136
|
"""
|
136
137
|
scores = be.full(
|
137
138
|
shape=self._shape, dtype=be._float_dtype, fill_value=self._score_threshold
|
138
139
|
)
|
139
140
|
rotations = be.full(self._shape, dtype=be._int_dtype, fill_value=-1)
|
140
|
-
|
141
|
+
ssum = be.full((1), dtype=be._float_dtype, fill_value=0)
|
142
|
+
return scores, rotations, {}, ssum
|
141
143
|
|
142
144
|
def __call__(
|
143
145
|
self,
|
@@ -156,6 +158,7 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
156
158
|
- scores : BackendArray, current maximum scores.
|
157
159
|
- rotations : BackendArray, current rotation indices.
|
158
160
|
- rotation_mapping : dict, mapping from rotation bytes to indices.
|
161
|
+
- ssum : BackendArray, accumulator for sum of squared scores.
|
159
162
|
scores : BackendArray
|
160
163
|
Array of new scores to update analyzer with.
|
161
164
|
rotation_matrix : BackendArray
|
@@ -168,7 +171,7 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
168
171
|
# be.tobytes behaviour caused overhead for certain GPU/CUDA combinations
|
169
172
|
# If the analyzer is not shared and each rotation is unique, we can
|
170
173
|
# use index to rotation mapping and invert prior to merging.
|
171
|
-
prev_scores, rotations, rotation_mapping = state
|
174
|
+
prev_scores, rotations, rotation_mapping, ssum = state
|
172
175
|
|
173
176
|
rotation_index = len(rotation_mapping)
|
174
177
|
rotation_matrix = be.astype(rotation_matrix, be._float_dtype)
|
@@ -180,13 +183,14 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
180
183
|
rotation = be.tobytes(rotation_matrix)
|
181
184
|
rotation_index = rotation_mapping.setdefault(rotation, rotation_index)
|
182
185
|
|
186
|
+
ssum = be.add(ssum, be.ssum(scores), out=ssum)
|
183
187
|
scores, rotations = be.max_score_over_rotations(
|
184
188
|
scores=scores,
|
185
189
|
max_scores=prev_scores,
|
186
190
|
rotations=rotations,
|
187
191
|
rotation_index=rotation_index,
|
188
192
|
)
|
189
|
-
return scores, rotations, rotation_mapping
|
193
|
+
return scores, rotations, rotation_mapping, ssum
|
190
194
|
|
191
195
|
@staticmethod
|
192
196
|
def _invert_rmap(rotation_mapping: dict) -> dict:
|
@@ -224,6 +228,7 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
224
228
|
- scores : BackendArray, current maximum scores.
|
225
229
|
- rotations : BackendArray, current rotation indices.
|
226
230
|
- rotation_mapping : dict, mapping from rotation indices to matrices.
|
231
|
+
- ssum : BackendArray, accumulator for sum of squared scores.
|
227
232
|
targetshape : Tuple[int], optional
|
228
233
|
Shape of the target for convolution mode correction.
|
229
234
|
templateshape : Tuple[int], optional
|
@@ -240,9 +245,9 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
240
245
|
Returns
|
241
246
|
-------
|
242
247
|
tuple
|
243
|
-
Final result tuple (scores, offset, rotations, rotation_mapping).
|
248
|
+
Final result tuple (scores, offset, rotations, rotation_mapping, ssum).
|
244
249
|
"""
|
245
|
-
scores, rotations, rotation_mapping = state
|
250
|
+
scores, rotations, rotation_mapping, ssum = state
|
246
251
|
|
247
252
|
# Apply postprocessing if parameters are provided
|
248
253
|
if fourier_shift is not None:
|
@@ -269,11 +274,13 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
269
274
|
if self._inversion_mapping:
|
270
275
|
rotation_mapping = {be.tobytes(v): k for k, v in rotation_mapping.items()}
|
271
276
|
|
277
|
+
n_rotations = max(len(rotation_mapping), 1)
|
272
278
|
return (
|
273
279
|
scores,
|
274
280
|
be.to_numpy_array(self._offset),
|
275
281
|
rotations,
|
276
282
|
self._invert_rmap(rotation_mapping),
|
283
|
+
be.to_numpy_array(ssum) / (scores.size * n_rotations),
|
277
284
|
)
|
278
285
|
|
279
286
|
def _harmonize_states(states: List[Tuple]):
|
@@ -287,18 +294,18 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
287
294
|
if states[i] is None:
|
288
295
|
continue
|
289
296
|
|
290
|
-
scores, offset, rotations, rotation_mapping = states[i]
|
297
|
+
scores, offset, rotations, rotation_mapping, ssum = states[i]
|
291
298
|
if out_shape is None:
|
292
299
|
out_shape = np.zeros(scores.ndim, int)
|
293
300
|
out_shape = np.maximum(out_shape, np.add(offset, scores.shape))
|
294
301
|
|
295
302
|
new_param = {}
|
296
303
|
for key, value in rotation_mapping.items():
|
297
|
-
rotation_bytes =
|
304
|
+
rotation_bytes = np.asarray(value).tobytes()
|
298
305
|
new_param[rotation_bytes] = key
|
299
306
|
if rotation_bytes not in new_rotation_mapping:
|
300
307
|
new_rotation_mapping[rotation_bytes] = len(new_rotation_mapping)
|
301
|
-
states[i] = (scores, offset, rotations, new_param)
|
308
|
+
states[i] = (scores, offset, rotations, new_param, ssum)
|
302
309
|
out_shape = tuple(int(x) for x in out_shape)
|
303
310
|
return new_rotation_mapping, out_shape, states
|
304
311
|
|
@@ -329,11 +336,10 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
329
336
|
if len(results) == 1:
|
330
337
|
ret = results[0]
|
331
338
|
if use_memmap:
|
332
|
-
scores, offset, rotations, rotation_mapping = ret
|
339
|
+
scores, offset, rotations, rotation_mapping, ssum = ret
|
333
340
|
scores = array_to_memmap(scores)
|
334
341
|
rotations = array_to_memmap(rotations)
|
335
|
-
ret = (scores, offset, rotations, rotation_mapping)
|
336
|
-
|
342
|
+
ret = (scores, offset, rotations, rotation_mapping, ssum)
|
337
343
|
return ret
|
338
344
|
|
339
345
|
# Determine output array shape and create consistent rotation map
|
@@ -368,6 +374,7 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
368
374
|
)
|
369
375
|
rotations_out = np.full(out_shape, fill_value=-1, dtype=rotations_dtype)
|
370
376
|
|
377
|
+
total_ssum = 0
|
371
378
|
for i in range(len(results)):
|
372
379
|
if results[i] is None:
|
373
380
|
continue
|
@@ -385,7 +392,9 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
385
392
|
shape=out_shape,
|
386
393
|
dtype=rotations_dtype,
|
387
394
|
)
|
388
|
-
scores, offset, rotations, rotation_mapping = results[i]
|
395
|
+
scores, offset, rotations, rotation_mapping, ssum = results[i]
|
396
|
+
|
397
|
+
total_ssum = np.add(total_ssum, ssum)
|
389
398
|
stops = np.add(offset, scores.shape).astype(int)
|
390
399
|
indices = tuple(slice(*pos) for pos in zip(offset, stops))
|
391
400
|
|
@@ -428,6 +437,7 @@ class MaxScoreOverRotations(AbstractAnalyzer):
|
|
428
437
|
np.zeros(scores_out.ndim, dtype=int),
|
429
438
|
rotations_out,
|
430
439
|
cls._invert_rmap(master_rotation_mapping),
|
440
|
+
total_ssum / len(results),
|
431
441
|
)
|
432
442
|
|
433
443
|
|
@@ -112,10 +112,14 @@ def _identity(arr: BackendArray, arr_filter: BackendArray) -> BackendArray:
|
|
112
112
|
return arr
|
113
113
|
|
114
114
|
|
115
|
+
def _mask_scores(arr, mask):
|
116
|
+
return arr.at[:].multiply(mask)
|
117
|
+
|
118
|
+
|
115
119
|
@partial(
|
116
120
|
pmap,
|
117
|
-
in_axes=(0,) + (None,) *
|
118
|
-
static_broadcasted_argnums=[
|
121
|
+
in_axes=(0,) + (None,) * 7,
|
122
|
+
static_broadcasted_argnums=[7, 8, 9, 10],
|
119
123
|
axis_name="batch",
|
120
124
|
)
|
121
125
|
def scan(
|
@@ -125,6 +129,7 @@ def scan(
|
|
125
129
|
rotations: BackendArray,
|
126
130
|
template_filter: BackendArray,
|
127
131
|
target_filter: BackendArray,
|
132
|
+
score_mask: BackendArray,
|
128
133
|
fast_shape: Tuple[int],
|
129
134
|
rotate_mask: bool,
|
130
135
|
analyzer_class: object,
|
@@ -159,6 +164,10 @@ def scan(
|
|
159
164
|
if template_filter.shape != ():
|
160
165
|
_template_filter_func = _apply_fourier_filter
|
161
166
|
|
167
|
+
_score_mask_func = _identity
|
168
|
+
if score_mask.shape != ():
|
169
|
+
_score_mask_func = _mask_scores
|
170
|
+
|
162
171
|
def _sample_transform(ret, rotation_matrix):
|
163
172
|
state, index = ret
|
164
173
|
template_rot, template_mask_rot = be.rigid_transform(
|
@@ -185,6 +194,8 @@ def scan(
|
|
185
194
|
n_observations=n_observations,
|
186
195
|
eps=eps,
|
187
196
|
)
|
197
|
+
scores = _score_mask_func(scores, score_mask)
|
198
|
+
|
188
199
|
state = analyzer(state, scores, rotation_matrix, rotation_index=index)
|
189
200
|
return (state, index + 1), None
|
190
201
|
|
@@ -81,6 +81,17 @@ class CupyBackend(NumpyFFTWBackend):
|
|
81
81
|
""",
|
82
82
|
"norm_scores",
|
83
83
|
)
|
84
|
+
|
85
|
+
# Sum of square computation similar to the demeaned variance in pytom
|
86
|
+
self.ssum = cp.ReductionKernel(
|
87
|
+
f"{ftype} arr",
|
88
|
+
f"{ftype} ret",
|
89
|
+
"arr * arr",
|
90
|
+
"a + b",
|
91
|
+
"ret = a",
|
92
|
+
"0",
|
93
|
+
f"ssum_{ftype}",
|
94
|
+
)
|
84
95
|
self.texture_available = find_spec("voltools") is not None
|
85
96
|
|
86
97
|
def to_backend_array(self, arr: NDArray) -> CupyArray:
|
@@ -139,17 +150,6 @@ class CupyBackend(NumpyFFTWBackend):
|
|
139
150
|
peaks = self._array_backend.array(self._array_backend.nonzero(max_filter)).T
|
140
151
|
return peaks
|
141
152
|
|
142
|
-
# The default methods in Cupy were oddly slow
|
143
|
-
def var(self, a, *args, **kwargs):
|
144
|
-
out = a - self._array_backend.mean(a, *args, **kwargs)
|
145
|
-
self._array_backend.square(out, out)
|
146
|
-
out = self._array_backend.mean(out, *args, **kwargs)
|
147
|
-
return out
|
148
|
-
|
149
|
-
def std(self, a, *args, **kwargs):
|
150
|
-
out = self.var(a, *args, **kwargs)
|
151
|
-
return self._array_backend.sqrt(out)
|
152
|
-
|
153
153
|
def _get_texture(self, arr: CupyArray, order: int = 3, prefilter: bool = False):
|
154
154
|
key = id(arr)
|
155
155
|
if key in TEXTURE_CACHE:
|
@@ -197,6 +197,13 @@ class JaxBackend(NumpyFFTWBackend):
|
|
197
197
|
def _tuple_to_dict(self, data: Tuple) -> Dict:
|
198
198
|
return {x[0]: self._from_hashable(*x[1]) for x in data}
|
199
199
|
|
200
|
+
def _unbatch(self, data, target_ndim, index):
|
201
|
+
if not isinstance(data, type(self.zeros(1))):
|
202
|
+
return data
|
203
|
+
elif data.ndim <= target_ndim:
|
204
|
+
return data
|
205
|
+
return data[index]
|
206
|
+
|
200
207
|
def scan(
|
201
208
|
self,
|
202
209
|
matching_data: type,
|
@@ -212,11 +219,13 @@ class JaxBackend(NumpyFFTWBackend):
|
|
212
219
|
:py:class:`tme.analyzer.MaxScoreOverRotations`.
|
213
220
|
"""
|
214
221
|
from ._jax_utils import scan as scan_inner
|
222
|
+
from ..analyzer import MaxScoreOverRotations
|
215
223
|
|
216
224
|
pad_target = True if len(splits) > 1 else False
|
217
225
|
convolution_mode = "valid" if pad_target else "same"
|
218
226
|
target_pad = matching_data.target_padding(pad_target=pad_target)
|
219
227
|
|
228
|
+
score_mask = self.full((1,), fill_value=1, dtype=bool)
|
220
229
|
target_shape = tuple(
|
221
230
|
(x.stop - x.start + p) for x, p in zip(splits[0][0], target_pad)
|
222
231
|
)
|
@@ -273,6 +282,9 @@ class JaxBackend(NumpyFFTWBackend):
|
|
273
282
|
|
274
283
|
analyzer_kwargs.append(self._dict_to_tuple(cur_args))
|
275
284
|
|
285
|
+
if pad_target:
|
286
|
+
score_mask = base._score_mask(fast_shape, shift)
|
287
|
+
|
276
288
|
_target = self.astype(base._target, self._float_dtype)
|
277
289
|
translation_offsets.append(translation_offset)
|
278
290
|
targets.append(self.topleft_pad(_target, fast_shape))
|
@@ -306,17 +318,23 @@ class JaxBackend(NumpyFFTWBackend):
|
|
306
318
|
matching_data.rotations,
|
307
319
|
template_filter,
|
308
320
|
target_filter,
|
321
|
+
score_mask,
|
309
322
|
fast_shape,
|
310
323
|
rotate_mask,
|
311
324
|
callback_class,
|
312
325
|
analyzer_kwargs,
|
313
326
|
)
|
314
327
|
|
328
|
+
ndim = targets.ndim - 1
|
315
329
|
for index in range(targets.shape[0]):
|
316
330
|
kwargs = self._tuple_to_dict(analyzer_kwargs[index])
|
317
331
|
analyzer = callback_class(**kwargs)
|
318
332
|
|
319
|
-
state = (
|
333
|
+
state = [self._unbatch(x, ndim, index) for x in states]
|
334
|
+
|
335
|
+
if isinstance(analyzer, MaxScoreOverRotations):
|
336
|
+
state[2] = rotation_mapping
|
337
|
+
|
320
338
|
ret.append(analyzer.result(state, **kwargs))
|
321
339
|
return ret
|
322
340
|
|
@@ -863,6 +863,17 @@ class MatchingBackend(ABC):
|
|
863
863
|
Indices of ``k`` largest elements in ``arr``.
|
864
864
|
"""
|
865
865
|
|
866
|
+
@abstractmethod
|
867
|
+
def ssum(self, arr, *args, **kwargs) -> BackendArray:
|
868
|
+
"""
|
869
|
+
Compute the sum of squares of ``arr``.
|
870
|
+
|
871
|
+
Returns
|
872
|
+
-------
|
873
|
+
BackendArray
|
874
|
+
Sum of squares with shape ().
|
875
|
+
"""
|
876
|
+
|
866
877
|
def indices(self, *args, **kwargs) -> BackendArray:
|
867
878
|
"""
|
868
879
|
Creates an array representing the index grid of an input.
|
@@ -201,6 +201,9 @@ class NumpyFFTWBackend(_NumpyWrapper, MatchingBackend):
|
|
201
201
|
sorted_indices = self.unravel_index(indices=sorted_indices, shape=arr.shape)
|
202
202
|
return sorted_indices
|
203
203
|
|
204
|
+
def ssum(self, arr, *args, **kwargs):
|
205
|
+
return self.sum(self.square(arr), *args, **kwargs)
|
206
|
+
|
204
207
|
def indices(self, *args, **kwargs) -> NDArray:
|
205
208
|
return self._array_backend.indices(*args, **kwargs)
|
206
209
|
|
@@ -544,6 +544,30 @@ class MatchingData:
|
|
544
544
|
batch_mask=be.to_numpy_array(self._batch_mask),
|
545
545
|
)
|
546
546
|
|
547
|
+
def _score_mask(self, fast_shape: Tuple[int], shift: Tuple[int]) -> BackendArray:
|
548
|
+
"""
|
549
|
+
Create a boolean mask to exclude scores derived from padding in template matching.
|
550
|
+
"""
|
551
|
+
padding = self.target_padding(True)
|
552
|
+
offset = tuple(x // 2 for x in padding)
|
553
|
+
shape = tuple(y - x for x, y in zip(padding, self.target.shape))
|
554
|
+
|
555
|
+
subset = []
|
556
|
+
for i in range(len(offset)):
|
557
|
+
if self._batch_mask[i]:
|
558
|
+
subset.append(slice(None))
|
559
|
+
else:
|
560
|
+
subset.append(slice(offset[i], offset[i] + shape[i]))
|
561
|
+
|
562
|
+
score_mask = np.zeros(fast_shape, dtype=bool)
|
563
|
+
score_mask[tuple(subset)] = 1
|
564
|
+
score_mask = np.roll(
|
565
|
+
score_mask,
|
566
|
+
shift=tuple(-x for x in shift),
|
567
|
+
axis=tuple(i for i in range(len(shift))),
|
568
|
+
)
|
569
|
+
return be.to_backend_array(score_mask)
|
570
|
+
|
547
571
|
def computation_schedule(
|
548
572
|
self,
|
549
573
|
matching_method: str = "FLCSphericalMask",
|
@@ -223,6 +223,10 @@ def scan(
|
|
223
223
|
)
|
224
224
|
conv, fwd, inv, shift = matching_data.fourier_padding()
|
225
225
|
|
226
|
+
score_mask = be.full(shape=(1,), fill_value=1, dtype=bool)
|
227
|
+
if pad_target:
|
228
|
+
score_mask = matching_data._score_mask(fwd, shift)
|
229
|
+
|
226
230
|
template_filter = _setup_template_filter_apply_target_filter(
|
227
231
|
matching_data=matching_data,
|
228
232
|
fast_shape=fwd,
|
@@ -275,6 +279,7 @@ def scan(
|
|
275
279
|
callback=callback_classes[index % n_callback_classes],
|
276
280
|
interpolation_order=interpolation_order,
|
277
281
|
template_filter=be.to_sharedarr(template_filter, shm_handler),
|
282
|
+
score_mask=be.to_sharedarr(score_mask, shm_handler),
|
278
283
|
**setup,
|
279
284
|
)
|
280
285
|
for index, rotation in enumerate(matching_data._split_rotations_on_jobs(n_jobs))
|
@@ -420,8 +425,6 @@ def scan_subsets(
|
|
420
425
|
outer_jobs, inner_jobs = job_schedule
|
421
426
|
if be._backend_name == "jax":
|
422
427
|
func = be.scan
|
423
|
-
if kwargs.get("projection_matching", False):
|
424
|
-
func = be.scan_projections
|
425
428
|
|
426
429
|
corr_scoring = MATCHING_EXHAUSTIVE_REGISTER.get("CORR", (None, None))[1]
|
427
430
|
results = func(
|
@@ -356,6 +356,7 @@ def corr_scoring(
|
|
356
356
|
callback: CallbackClass,
|
357
357
|
interpolation_order: int,
|
358
358
|
template_mask: shm_type = None,
|
359
|
+
score_mask: shm_type = None,
|
359
360
|
) -> CallbackClass:
|
360
361
|
"""
|
361
362
|
Calculates a normalized cross-correlation between a target f and a template g.
|
@@ -394,6 +395,8 @@ def corr_scoring(
|
|
394
395
|
Spline order for template rotations.
|
395
396
|
template_mask : Union[Tuple[type, tuple of ints, type], BackendArray], optional
|
396
397
|
Template mask data buffer, its shape and datatype, None by default.
|
398
|
+
score_mask : Union[Tuple[type, tuple of ints, type], BackendArray], optional
|
399
|
+
Score mask data buffer, its shape and datatype, None by default.
|
397
400
|
|
398
401
|
Returns
|
399
402
|
-------
|
@@ -404,6 +407,7 @@ def corr_scoring(
|
|
404
407
|
inv_denominator = be.from_sharedarr(inv_denominator)
|
405
408
|
numerator = be.from_sharedarr(numerator)
|
406
409
|
template_filter = be.from_sharedarr(template_filter)
|
410
|
+
score_mask = be.from_sharedarr(score_mask)
|
407
411
|
|
408
412
|
n_obs = None
|
409
413
|
if template_mask is not None:
|
@@ -413,6 +417,7 @@ def corr_scoring(
|
|
413
417
|
norm_template = conditional_execute(normalize_template, n_obs is not None)
|
414
418
|
norm_sub = conditional_execute(be.subtract, numerator.shape != (1,))
|
415
419
|
norm_mul = conditional_execute(be.multiply, inv_denominator.shape != (1))
|
420
|
+
norm_mask = conditional_execute(be.multiply, score_mask.shape != (1,))
|
416
421
|
|
417
422
|
arr = be.zeros(fast_shape, be._float_dtype)
|
418
423
|
ft_temp = be.zeros(fast_ft_shape, be._complex_dtype)
|
@@ -447,6 +452,8 @@ def corr_scoring(
|
|
447
452
|
|
448
453
|
arr = norm_sub(arr, numerator, out=arr)
|
449
454
|
arr = norm_mul(arr, inv_denominator, out=arr)
|
455
|
+
arr = norm_mask(arr, score_mask, out=arr)
|
456
|
+
|
450
457
|
callback(arr, rotation_matrix=rotation)
|
451
458
|
|
452
459
|
return callback
|
@@ -463,6 +470,7 @@ def flc_scoring(
|
|
463
470
|
rotations: BackendArray,
|
464
471
|
callback: CallbackClass,
|
465
472
|
interpolation_order: int,
|
473
|
+
score_mask: shm_type = None,
|
466
474
|
) -> CallbackClass:
|
467
475
|
"""
|
468
476
|
Computes a normalized cross-correlation between ``target`` (f),
|
@@ -522,6 +530,7 @@ def flc_scoring(
|
|
522
530
|
ft_target = be.from_sharedarr(ft_target)
|
523
531
|
ft_target2 = be.from_sharedarr(ft_target2)
|
524
532
|
template_filter = be.from_sharedarr(template_filter)
|
533
|
+
score_mask = be.from_sharedarr(score_mask)
|
525
534
|
|
526
535
|
arr = be.zeros(fast_shape, float_dtype)
|
527
536
|
temp = be.zeros(fast_shape, float_dtype)
|
@@ -532,6 +541,7 @@ def flc_scoring(
|
|
532
541
|
template_mask_rot = be.zeros(template.shape, be._float_dtype)
|
533
542
|
|
534
543
|
tmpl_filter_func = _create_filter_func(template.shape, template_filter.shape)
|
544
|
+
norm_mask = conditional_execute(be.multiply, score_mask.shape != (1,))
|
535
545
|
|
536
546
|
eps = be.eps(float_dtype)
|
537
547
|
center = be.divide(be.to_backend_array(template.shape) - 1, 2)
|
@@ -567,6 +577,8 @@ def flc_scoring(
|
|
567
577
|
arr = _correlate_fts(ft_target, ft_temp, ft_temp, arr, fast_shape)
|
568
578
|
|
569
579
|
arr = be.norm_scores(arr, temp2, temp, n_obs, eps, arr)
|
580
|
+
arr = norm_mask(arr, score_mask, out=arr)
|
581
|
+
|
570
582
|
callback(arr, rotation_matrix=rotation)
|
571
583
|
|
572
584
|
return callback
|
@@ -585,6 +597,7 @@ def mcc_scoring(
|
|
585
597
|
callback: CallbackClass,
|
586
598
|
interpolation_order: int,
|
587
599
|
overlap_ratio: float = 0.3,
|
600
|
+
score_mask: shm_type = None,
|
588
601
|
) -> CallbackClass:
|
589
602
|
"""
|
590
603
|
Computes a normalized cross-correlation score between ``target`` (f),
|
@@ -755,12 +768,14 @@ def flc_scoring2(
|
|
755
768
|
rotations: BackendArray,
|
756
769
|
callback: CallbackClass,
|
757
770
|
interpolation_order: int,
|
771
|
+
score_mask: shm_type = None,
|
758
772
|
) -> CallbackClass:
|
759
773
|
template = be.from_sharedarr(template)
|
760
774
|
template_mask = be.from_sharedarr(template_mask)
|
761
775
|
ft_target = be.from_sharedarr(ft_target)
|
762
776
|
ft_target2 = be.from_sharedarr(ft_target2)
|
763
777
|
template_filter = be.from_sharedarr(template_filter)
|
778
|
+
score_mask = be.from_sharedarr(score_mask)
|
764
779
|
|
765
780
|
tar_batch, tmpl_batch = _get_batch_dim(ft_target, template)
|
766
781
|
|
@@ -785,6 +800,7 @@ def flc_scoring2(
|
|
785
800
|
filter_shape=template_filter.shape,
|
786
801
|
arr_padded=True,
|
787
802
|
)
|
803
|
+
norm_mask = conditional_execute(be.multiply, score_mask.shape != (1,))
|
788
804
|
|
789
805
|
eps = be.eps(be._float_dtype)
|
790
806
|
for index in range(rotations.shape[0]):
|
@@ -816,6 +832,8 @@ def flc_scoring2(
|
|
816
832
|
arr = _correlate_fts(ft_target, ft_temp, ft_denom, arr, shape, axes)
|
817
833
|
|
818
834
|
arr = be.norm_scores(arr, temp2, temp, n_obs, eps, arr)
|
835
|
+
arr = norm_mask(arr, score_mask, out=arr)
|
836
|
+
|
819
837
|
callback(arr, rotation_matrix=rotation)
|
820
838
|
|
821
839
|
return callback
|
@@ -834,12 +852,14 @@ def corr_scoring2(
|
|
834
852
|
interpolation_order: int,
|
835
853
|
target_filter: shm_type = None,
|
836
854
|
template_mask: shm_type = None,
|
855
|
+
score_mask: shm_type = None,
|
837
856
|
) -> CallbackClass:
|
838
857
|
template = be.from_sharedarr(template)
|
839
858
|
ft_target = be.from_sharedarr(ft_target)
|
840
859
|
inv_denominator = be.from_sharedarr(inv_denominator)
|
841
860
|
numerator = be.from_sharedarr(numerator)
|
842
861
|
template_filter = be.from_sharedarr(template_filter)
|
862
|
+
score_mask = be.from_sharedarr(score_mask)
|
843
863
|
|
844
864
|
tar_batch, tmpl_batch = _get_batch_dim(ft_target, template)
|
845
865
|
|
@@ -869,6 +889,7 @@ def corr_scoring2(
|
|
869
889
|
norm_template = conditional_execute(normalize_template, n_obs is not None)
|
870
890
|
norm_sub = conditional_execute(be.subtract, numerator.shape != (1,))
|
871
891
|
norm_mul = conditional_execute(be.multiply, inv_denominator.shape != (1,))
|
892
|
+
norm_mask = conditional_execute(be.multiply, score_mask.shape != (1,))
|
872
893
|
|
873
894
|
template_filter_func = _create_filter_func(
|
874
895
|
arr_shape=template.shape,
|
@@ -896,6 +917,8 @@ def corr_scoring2(
|
|
896
917
|
|
897
918
|
arr = norm_sub(arr, numerator, out=arr)
|
898
919
|
arr = norm_mul(arr, inv_denominator, out=arr)
|
920
|
+
arr = norm_mask(arr, score_mask, out=arr)
|
921
|
+
|
899
922
|
callback(arr, rotation_matrix=rotation)
|
900
923
|
|
901
924
|
return callback
|
@@ -327,11 +327,18 @@ class Orientations:
|
|
327
327
|
"_rlnAnglePsi",
|
328
328
|
"_rlnClassNumber",
|
329
329
|
]
|
330
|
+
|
331
|
+
target_identifer = "_rlnMicrographName"
|
332
|
+
if version == "# version 50001":
|
333
|
+
header[3] = "_rlnCenteredCoordinateXAngst"
|
334
|
+
header[4] = "_rlnCenteredCoordinateYAngst"
|
335
|
+
header[5] = "_rlnCenteredCoordinateZAngst"
|
336
|
+
target_identifer = "_rlnTomoName"
|
337
|
+
|
330
338
|
if source_path is not None:
|
331
|
-
header.append(
|
339
|
+
header.append(target_identifer)
|
332
340
|
|
333
341
|
header.append("_pytmeScore")
|
334
|
-
|
335
342
|
header = "\n".join(header)
|
336
343
|
with open(filename, mode="w", encoding="utf-8") as ofile:
|
337
344
|
if version is not None:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|