pytme 0.2.9__cp311-cp311-macosx_15_0_arm64.whl
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.2.9.data/scripts/estimate_ram_usage.py +97 -0
- pytme-0.2.9.data/scripts/match_template.py +1135 -0
- pytme-0.2.9.data/scripts/postprocess.py +622 -0
- pytme-0.2.9.data/scripts/preprocess.py +209 -0
- pytme-0.2.9.data/scripts/preprocessor_gui.py +1227 -0
- pytme-0.2.9.dist-info/METADATA +95 -0
- pytme-0.2.9.dist-info/RECORD +119 -0
- pytme-0.2.9.dist-info/WHEEL +5 -0
- pytme-0.2.9.dist-info/entry_points.txt +6 -0
- pytme-0.2.9.dist-info/licenses/LICENSE +153 -0
- pytme-0.2.9.dist-info/top_level.txt +3 -0
- scripts/__init__.py +0 -0
- scripts/estimate_ram_usage.py +97 -0
- scripts/match_template.py +1135 -0
- scripts/postprocess.py +622 -0
- scripts/preprocess.py +209 -0
- scripts/preprocessor_gui.py +1227 -0
- tests/__init__.py +0 -0
- tests/data/Blurring/blob_width18.npy +0 -0
- tests/data/Blurring/edgegaussian_sigma3.npy +0 -0
- tests/data/Blurring/gaussian_sigma2.npy +0 -0
- tests/data/Blurring/hamming_width6.npy +0 -0
- tests/data/Blurring/kaiserb_width18.npy +0 -0
- tests/data/Blurring/localgaussian_sigma0510.npy +0 -0
- tests/data/Blurring/mean_size5.npy +0 -0
- tests/data/Blurring/ntree_sigma0510.npy +0 -0
- tests/data/Blurring/rank_rank3.npy +0 -0
- tests/data/Maps/.DS_Store +0 -0
- tests/data/Maps/emd_8621.mrc.gz +0 -0
- tests/data/README.md +2 -0
- tests/data/Raw/em_map.map +0 -0
- tests/data/Structures/.DS_Store +0 -0
- tests/data/Structures/1pdj.cif +3339 -0
- tests/data/Structures/1pdj.pdb +1429 -0
- tests/data/Structures/5khe.cif +3685 -0
- tests/data/Structures/5khe.ent +2210 -0
- tests/data/Structures/5khe.pdb +2210 -0
- tests/data/Structures/5uz4.cif +70548 -0
- tests/preprocessing/__init__.py +0 -0
- tests/preprocessing/test_compose.py +76 -0
- tests/preprocessing/test_frequency_filters.py +178 -0
- tests/preprocessing/test_preprocessor.py +136 -0
- tests/preprocessing/test_utils.py +79 -0
- tests/test_analyzer.py +216 -0
- tests/test_backends.py +446 -0
- tests/test_density.py +503 -0
- tests/test_extensions.py +130 -0
- tests/test_matching_cli.py +283 -0
- tests/test_matching_data.py +162 -0
- tests/test_matching_exhaustive.py +124 -0
- tests/test_matching_memory.py +30 -0
- tests/test_matching_optimization.py +226 -0
- tests/test_matching_utils.py +189 -0
- tests/test_orientations.py +175 -0
- tests/test_parser.py +33 -0
- tests/test_rotations.py +153 -0
- tests/test_structure.py +247 -0
- tme/__init__.py +6 -0
- tme/__version__.py +1 -0
- tme/analyzer/__init__.py +2 -0
- tme/analyzer/_utils.py +186 -0
- tme/analyzer/aggregation.py +577 -0
- tme/analyzer/peaks.py +953 -0
- tme/backends/__init__.py +171 -0
- tme/backends/_cupy_utils.py +734 -0
- tme/backends/_jax_utils.py +188 -0
- tme/backends/cupy_backend.py +294 -0
- tme/backends/jax_backend.py +314 -0
- tme/backends/matching_backend.py +1270 -0
- tme/backends/mlx_backend.py +241 -0
- tme/backends/npfftw_backend.py +583 -0
- tme/backends/pytorch_backend.py +430 -0
- tme/data/__init__.py +0 -0
- tme/data/c48n309.npy +0 -0
- tme/data/c48n527.npy +0 -0
- tme/data/c48n9.npy +0 -0
- tme/data/c48u1.npy +0 -0
- tme/data/c48u1153.npy +0 -0
- tme/data/c48u1201.npy +0 -0
- tme/data/c48u1641.npy +0 -0
- tme/data/c48u181.npy +0 -0
- tme/data/c48u2219.npy +0 -0
- tme/data/c48u27.npy +0 -0
- tme/data/c48u2947.npy +0 -0
- tme/data/c48u3733.npy +0 -0
- tme/data/c48u4749.npy +0 -0
- tme/data/c48u5879.npy +0 -0
- tme/data/c48u7111.npy +0 -0
- tme/data/c48u815.npy +0 -0
- tme/data/c48u83.npy +0 -0
- tme/data/c48u8649.npy +0 -0
- tme/data/c600v.npy +0 -0
- tme/data/c600vc.npy +0 -0
- tme/data/metadata.yaml +80 -0
- tme/data/quat_to_numpy.py +42 -0
- tme/data/scattering_factors.pickle +0 -0
- tme/density.py +2263 -0
- tme/extensions.cpython-311-darwin.so +0 -0
- tme/external/bindings.cpp +332 -0
- tme/filters/__init__.py +6 -0
- tme/filters/_utils.py +311 -0
- tme/filters/bandpass.py +230 -0
- tme/filters/compose.py +81 -0
- tme/filters/ctf.py +393 -0
- tme/filters/reconstruction.py +160 -0
- tme/filters/wedge.py +542 -0
- tme/filters/whitening.py +191 -0
- tme/matching_data.py +863 -0
- tme/matching_exhaustive.py +497 -0
- tme/matching_optimization.py +1311 -0
- tme/matching_scores.py +1183 -0
- tme/matching_utils.py +1188 -0
- tme/memory.py +337 -0
- tme/orientations.py +598 -0
- tme/parser.py +685 -0
- tme/preprocessor.py +1329 -0
- tme/rotations.py +350 -0
- tme/structure.py +1864 -0
- tme/types.py +13 -0
tme/filters/whitening.py
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
""" Implements class BandPassFilter to create Fourier filter representations.
|
2
|
+
|
3
|
+
Copyright (c) 2024 European Molecular Biology Laboratory
|
4
|
+
|
5
|
+
Author: Valentin Maurer <valentin.maurer@embl-hamburg.de>
|
6
|
+
"""
|
7
|
+
|
8
|
+
from typing import Tuple, Dict
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
from scipy.ndimage import mean as ndimean
|
12
|
+
from scipy.ndimage import map_coordinates
|
13
|
+
|
14
|
+
from ..types import BackendArray
|
15
|
+
from ..backends import backend as be
|
16
|
+
from .compose import ComposableFilter
|
17
|
+
from ._utils import fftfreqn, compute_fourier_shape
|
18
|
+
|
19
|
+
__all__ = ["LinearWhiteningFilter"]
|
20
|
+
|
21
|
+
|
22
|
+
class LinearWhiteningFilter(ComposableFilter):
|
23
|
+
"""
|
24
|
+
Compute Fourier power spectrums and perform whitening.
|
25
|
+
|
26
|
+
Parameters
|
27
|
+
----------
|
28
|
+
**kwargs : Dict, optional
|
29
|
+
Additional keyword arguments.
|
30
|
+
|
31
|
+
References
|
32
|
+
----------
|
33
|
+
.. [1] de Teresa-Trueba, I.; Goetz, S. K.; Mattausch, A.; Stojanovska, F.; Zimmerli, C. E.;
|
34
|
+
Toro-Nahuelpan, M.; Cheng, D. W. C.; Tollervey, F.; Pape, C.; Beck, M.; Diz-Munoz,
|
35
|
+
A.; Kreshuk, A.; Mahamid, J.; Zaugg, J. B. Nat. Methods 2023, 20, 284–294.
|
36
|
+
.. [2] M. L. Chaillet, G. van der Schot, I. Gubins, S. Roet,
|
37
|
+
R. C. Veltkamp, and F. Förster, Int. J. Mol. Sci. 24,
|
38
|
+
13375 (2023)
|
39
|
+
"""
|
40
|
+
|
41
|
+
def __init__(self, **kwargs):
|
42
|
+
pass
|
43
|
+
|
44
|
+
@staticmethod
|
45
|
+
def _compute_spectrum(
|
46
|
+
data_rfft: BackendArray, n_bins: int = None, batch_dimension: int = None
|
47
|
+
) -> Tuple[BackendArray, BackendArray]:
|
48
|
+
"""
|
49
|
+
Compute the power spectrum of the input data.
|
50
|
+
|
51
|
+
Parameters
|
52
|
+
----------
|
53
|
+
data_rfft : BackendArray
|
54
|
+
The Fourier transform of the input data.
|
55
|
+
n_bins : int, optional
|
56
|
+
The number of bins for computing the spectrum, defaults to None.
|
57
|
+
batch_dimension : int, optional
|
58
|
+
Batch dimension to average over.
|
59
|
+
|
60
|
+
Returns
|
61
|
+
-------
|
62
|
+
bins : BackendArray
|
63
|
+
Array containing the bin indices for the spectrum.
|
64
|
+
radial_averages : BackendArray
|
65
|
+
Array containing the radial averages of the spectrum.
|
66
|
+
"""
|
67
|
+
shape = tuple(x for i, x in enumerate(data_rfft.shape) if i != batch_dimension)
|
68
|
+
|
69
|
+
max_bins = max(max(shape[:-1]) // 2 + 1, shape[-1])
|
70
|
+
n_bins = max_bins if n_bins is None else n_bins
|
71
|
+
n_bins = int(min(n_bins, max_bins))
|
72
|
+
|
73
|
+
bins = fftfreqn(
|
74
|
+
shape=shape,
|
75
|
+
sampling_rate=0.5,
|
76
|
+
shape_is_real_fourier=True,
|
77
|
+
compute_euclidean_norm=True,
|
78
|
+
)
|
79
|
+
bins = be.to_numpy_array(bins)
|
80
|
+
|
81
|
+
# Implicit lowpass to nyquist
|
82
|
+
bins = np.floor(bins * (n_bins - 1) + 0.5).astype(int)
|
83
|
+
fft_shift_axes = tuple(
|
84
|
+
i for i in range(data_rfft.ndim - 1) if i != batch_dimension
|
85
|
+
)
|
86
|
+
fourier_spectrum = np.fft.fftshift(data_rfft, axes=fft_shift_axes)
|
87
|
+
fourier_spectrum = np.abs(fourier_spectrum)
|
88
|
+
np.square(fourier_spectrum, out=fourier_spectrum)
|
89
|
+
|
90
|
+
radial_averages = ndimean(
|
91
|
+
fourier_spectrum, labels=bins, index=np.arange(n_bins)
|
92
|
+
)
|
93
|
+
np.sqrt(radial_averages, out=radial_averages)
|
94
|
+
np.reciprocal(radial_averages, out=radial_averages)
|
95
|
+
np.divide(radial_averages, radial_averages.max(), out=radial_averages)
|
96
|
+
|
97
|
+
return bins, radial_averages
|
98
|
+
|
99
|
+
@staticmethod
|
100
|
+
def _interpolate_spectrum(
|
101
|
+
spectrum: BackendArray,
|
102
|
+
shape: Tuple[int],
|
103
|
+
shape_is_real_fourier: bool = True,
|
104
|
+
order: int = 1,
|
105
|
+
) -> BackendArray:
|
106
|
+
"""
|
107
|
+
References
|
108
|
+
----------
|
109
|
+
.. [1] M. L. Chaillet, G. van der Schot, I. Gubins, S. Roet,
|
110
|
+
R. C. Veltkamp, and F. Förster, Int. J. Mol. Sci. 24,
|
111
|
+
13375 (2023)
|
112
|
+
"""
|
113
|
+
grid = fftfreqn(
|
114
|
+
shape=shape,
|
115
|
+
sampling_rate=0.5,
|
116
|
+
shape_is_real_fourier=shape_is_real_fourier,
|
117
|
+
compute_euclidean_norm=True,
|
118
|
+
)
|
119
|
+
grid = be.to_numpy_array(grid)
|
120
|
+
np.multiply(grid, (spectrum.shape[0] - 1), out=grid) + 0.5
|
121
|
+
spectrum = map_coordinates(spectrum, grid.reshape(1, -1), order=order)
|
122
|
+
return spectrum.reshape(grid.shape)
|
123
|
+
|
124
|
+
def __call__(
|
125
|
+
self,
|
126
|
+
data: BackendArray = None,
|
127
|
+
data_rfft: BackendArray = None,
|
128
|
+
n_bins: int = None,
|
129
|
+
batch_dimension: int = None,
|
130
|
+
order: int = 1,
|
131
|
+
**kwargs: Dict,
|
132
|
+
) -> Dict:
|
133
|
+
"""
|
134
|
+
Apply linear whitening to the data and return the result.
|
135
|
+
|
136
|
+
Parameters
|
137
|
+
----------
|
138
|
+
data : BackendArray, optional
|
139
|
+
The input data, defaults to None.
|
140
|
+
data_rfft : BackendArray, optional
|
141
|
+
The Fourier transform of the input data, defaults to None.
|
142
|
+
n_bins : int, optional
|
143
|
+
The number of bins for computing the spectrum, defaults to None.
|
144
|
+
batch_dimension : int, optional
|
145
|
+
Batch dimension to average over.
|
146
|
+
order : int, optional
|
147
|
+
Interpolation order to use.
|
148
|
+
**kwargs : Dict
|
149
|
+
Additional keyword arguments.
|
150
|
+
|
151
|
+
Returns
|
152
|
+
-------
|
153
|
+
Dict
|
154
|
+
Filter data and associated parameters.
|
155
|
+
"""
|
156
|
+
if data_rfft is None:
|
157
|
+
data_rfft = np.fft.rfftn(be.to_numpy_array(data))
|
158
|
+
|
159
|
+
data_rfft = be.to_numpy_array(data_rfft)
|
160
|
+
|
161
|
+
bins, radial_averages = self._compute_spectrum(
|
162
|
+
data_rfft, n_bins, batch_dimension
|
163
|
+
)
|
164
|
+
|
165
|
+
if order is None:
|
166
|
+
cutoff = bins < radial_averages.size
|
167
|
+
filter_mask = np.zeros(bins.shape, radial_averages.dtype)
|
168
|
+
filter_mask[cutoff] = radial_averages[bins[cutoff]]
|
169
|
+
else:
|
170
|
+
shape = bins.shape
|
171
|
+
if kwargs.get("shape", False):
|
172
|
+
shape = compute_fourier_shape(
|
173
|
+
shape=kwargs.get("shape"),
|
174
|
+
shape_is_real_fourier=kwargs.get("shape_is_real_fourier", False),
|
175
|
+
)
|
176
|
+
|
177
|
+
filter_mask = self._interpolate_spectrum(
|
178
|
+
spectrum=radial_averages,
|
179
|
+
shape=shape,
|
180
|
+
shape_is_real_fourier=True,
|
181
|
+
)
|
182
|
+
|
183
|
+
filter_mask = np.fft.ifftshift(
|
184
|
+
filter_mask,
|
185
|
+
axes=tuple(i for i in range(data_rfft.ndim - 1) if i != batch_dimension),
|
186
|
+
)
|
187
|
+
|
188
|
+
return {
|
189
|
+
"data": be.to_backend_array(filter_mask),
|
190
|
+
"is_multiplicative_filter": True,
|
191
|
+
}
|