pytme 0.2.2__cp311-cp311-macosx_14_0_arm64.whl → 0.2.4__cp311-cp311-macosx_14_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.2.data → pytme-0.2.4.data}/scripts/match_template.py +97 -148
- {pytme-0.2.2.data → pytme-0.2.4.data}/scripts/postprocess.py +20 -29
- pytme-0.2.4.data/scripts/preprocess.py +148 -0
- {pytme-0.2.2.data → pytme-0.2.4.data}/scripts/preprocessor_gui.py +15 -23
- {pytme-0.2.2.dist-info → pytme-0.2.4.dist-info}/METADATA +11 -10
- pytme-0.2.4.dist-info/RECORD +119 -0
- {pytme-0.2.2.dist-info → pytme-0.2.4.dist-info}/WHEEL +1 -1
- {pytme-0.2.2.dist-info → pytme-0.2.4.dist-info}/top_level.txt +1 -0
- pytme-0.2.2.data/scripts/preprocess.py → scripts/eval.py +1 -1
- scripts/match_template.py +97 -148
- scripts/postprocess.py +20 -29
- scripts/preprocess.py +116 -61
- scripts/preprocessor_gui.py +15 -23
- tests/__init__.py +0 -0
- tests/data/.DS_Store +0 -0
- tests/data/Blurring/.DS_Store +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/.DS_Store +0 -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 +310 -0
- tests/test_backends.py +375 -0
- tests/test_density.py +508 -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 +162 -0
- tests/test_matching_memory.py +30 -0
- tests/test_matching_optimization.py +276 -0
- tests/test_matching_utils.py +326 -0
- tests/test_orientations.py +173 -0
- tests/test_packaging.py +95 -0
- tests/test_parser.py +33 -0
- tests/test_structure.py +243 -0
- tme/__init__.py +0 -1
- tme/__version__.py +1 -1
- tme/analyzer.py +9 -6
- tme/backends/__init__.py +1 -1
- tme/backends/_jax_utils.py +10 -8
- tme/backends/cupy_backend.py +2 -7
- tme/backends/jax_backend.py +35 -20
- tme/backends/npfftw_backend.py +3 -2
- tme/backends/pytorch_backend.py +10 -7
- tme/data/scattering_factors.pickle +0 -0
- tme/density.py +26 -12
- tme/extensions.cpython-311-darwin.so +0 -0
- tme/external/bindings.cpp +332 -0
- tme/matching_data.py +33 -24
- tme/matching_exhaustive.py +39 -20
- tme/matching_scores.py +5 -2
- tme/matching_utils.py +8 -2
- tme/orientations.py +26 -9
- tme/preprocessing/_utils.py +14 -14
- tme/preprocessing/composable_filter.py +5 -4
- tme/preprocessing/compose.py +4 -4
- tme/preprocessing/frequency_filters.py +32 -35
- tme/preprocessing/tilt_series.py +210 -148
- tme/preprocessor.py +24 -246
- tme/structure.py +14 -14
- pytme-0.2.2.dist-info/RECORD +0 -74
- tme/matching_memory.py +0 -383
- {pytme-0.2.2.data → pytme-0.2.4.data}/scripts/estimate_ram_usage.py +0 -0
- {pytme-0.2.2.dist-info → pytme-0.2.4.dist-info}/LICENSE +0 -0
- {pytme-0.2.2.dist-info → pytme-0.2.4.dist-info}/entry_points.txt +0 -0
tme/matching_memory.py
DELETED
@@ -1,383 +0,0 @@
|
|
1
|
-
""" Compute memory consumption of template matching components.
|
2
|
-
|
3
|
-
Copyright (c) 2023 European Molecular Biology Laboratory
|
4
|
-
|
5
|
-
Author: Valentin Maurer <valentin.maurer@embl-hamburg.de>
|
6
|
-
"""
|
7
|
-
|
8
|
-
from abc import ABC, abstractmethod
|
9
|
-
from typing import Tuple
|
10
|
-
|
11
|
-
import numpy as np
|
12
|
-
from pyfftw import next_fast_len
|
13
|
-
|
14
|
-
|
15
|
-
class MatchingMemoryUsage(ABC):
|
16
|
-
"""
|
17
|
-
Base class for estimating the memory usage of template matching.
|
18
|
-
|
19
|
-
This class provides a template for estimating memory usage for
|
20
|
-
different matching methods. Users should subclass it and implement the
|
21
|
-
`base_usage` and `per_fork` methods to specify custom memory usage
|
22
|
-
estimates.
|
23
|
-
|
24
|
-
Parameters
|
25
|
-
----------
|
26
|
-
fast_shape : tuple of int
|
27
|
-
Shape of the real array.
|
28
|
-
ft_shape : tuple of int
|
29
|
-
Shape of the complex array.
|
30
|
-
float_nbytes : int
|
31
|
-
Number of bytes of the used float, e.g. 4 for float32.
|
32
|
-
complex_nbytes : int
|
33
|
-
Number of bytes of the used complex, e.g. 8 for complex64.
|
34
|
-
integer_nbytes : int
|
35
|
-
Number of bytes of the used integer, e.g. 4 for int32.
|
36
|
-
|
37
|
-
Attributes
|
38
|
-
----------
|
39
|
-
real_array_size : int
|
40
|
-
Number of elements in real array.
|
41
|
-
complex_array_size : int
|
42
|
-
Number of elements in complex array.
|
43
|
-
float_nbytes : int
|
44
|
-
Number of bytes of the used float, e.g. 4 for float32.
|
45
|
-
complex_nbytes : int
|
46
|
-
Number of bytes of the used complex, e.g. 8 for complex64.
|
47
|
-
integer_nbytes : int
|
48
|
-
Number of bytes of the used integer, e.g. 4 for int32.
|
49
|
-
|
50
|
-
Methods
|
51
|
-
-------
|
52
|
-
base_usage():
|
53
|
-
Returns the base memory usage in bytes.
|
54
|
-
per_fork():
|
55
|
-
Returns the memory usage in bytes per fork.
|
56
|
-
"""
|
57
|
-
|
58
|
-
def __init__(
|
59
|
-
self,
|
60
|
-
fast_shape: Tuple[int],
|
61
|
-
ft_shape: Tuple[int],
|
62
|
-
float_nbytes: int,
|
63
|
-
complex_nbytes: int,
|
64
|
-
integer_nbytes: int,
|
65
|
-
):
|
66
|
-
self.real_array_size = np.prod(fast_shape)
|
67
|
-
self.complex_array_size = np.prod(ft_shape)
|
68
|
-
self.float_nbytes = float_nbytes
|
69
|
-
self.complex_nbytes = complex_nbytes
|
70
|
-
self.integer_nbytes = integer_nbytes
|
71
|
-
|
72
|
-
@abstractmethod
|
73
|
-
def base_usage(self) -> int:
|
74
|
-
"""Return the base memory usage in bytes."""
|
75
|
-
|
76
|
-
@abstractmethod
|
77
|
-
def per_fork(self) -> int:
|
78
|
-
"""Return the memory usage per fork in bytes."""
|
79
|
-
|
80
|
-
|
81
|
-
class CCMemoryUsage(MatchingMemoryUsage):
|
82
|
-
"""
|
83
|
-
Memory usage estimation for the CC fitter.
|
84
|
-
|
85
|
-
See Also
|
86
|
-
--------
|
87
|
-
:py:meth:`tme.matching_exhaustive.cc_setup`.
|
88
|
-
"""
|
89
|
-
|
90
|
-
def base_usage(self) -> int:
|
91
|
-
float_arrays = self.real_array_size * self.float_nbytes
|
92
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes
|
93
|
-
return float_arrays + complex_arrays
|
94
|
-
|
95
|
-
def per_fork(self) -> int:
|
96
|
-
float_arrays = self.real_array_size * self.float_nbytes
|
97
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes
|
98
|
-
return float_arrays + complex_arrays
|
99
|
-
|
100
|
-
|
101
|
-
class LCCMemoryUsage(CCMemoryUsage):
|
102
|
-
"""
|
103
|
-
Memory usage estimation for LCC scoring.
|
104
|
-
See Also
|
105
|
-
--------
|
106
|
-
:py:meth:`tme.matching_exhaustive.lcc_setup`.
|
107
|
-
"""
|
108
|
-
|
109
|
-
|
110
|
-
class CORRMemoryUsage(MatchingMemoryUsage):
|
111
|
-
"""
|
112
|
-
Memory usage estimation for CORR scoring.
|
113
|
-
|
114
|
-
See Also
|
115
|
-
--------
|
116
|
-
:py:meth:`tme.matching_exhaustive.corr_setup`.
|
117
|
-
"""
|
118
|
-
|
119
|
-
def base_usage(self) -> int:
|
120
|
-
float_arrays = self.real_array_size * self.float_nbytes * 4
|
121
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes
|
122
|
-
return float_arrays + complex_arrays
|
123
|
-
|
124
|
-
def per_fork(self) -> int:
|
125
|
-
float_arrays = self.real_array_size * self.float_nbytes
|
126
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes
|
127
|
-
return float_arrays + complex_arrays
|
128
|
-
|
129
|
-
|
130
|
-
class CAMMemoryUsage(CORRMemoryUsage):
|
131
|
-
"""
|
132
|
-
Memory usage estimation for CAM scoring.
|
133
|
-
|
134
|
-
See Also
|
135
|
-
--------
|
136
|
-
:py:meth:`tme.matching_exhaustive.cam_setup`.
|
137
|
-
"""
|
138
|
-
|
139
|
-
|
140
|
-
class FLCSphericalMaskMemoryUsage(CORRMemoryUsage):
|
141
|
-
"""
|
142
|
-
Memory usage estimation for FLCMSphericalMask scoring.
|
143
|
-
|
144
|
-
See Also
|
145
|
-
--------
|
146
|
-
:py:meth:`tme.matching_exhaustive.flcSphericalMask_setup`.
|
147
|
-
"""
|
148
|
-
|
149
|
-
|
150
|
-
class FLCMemoryUsage(MatchingMemoryUsage):
|
151
|
-
"""
|
152
|
-
Memory usage estimation for FLC scoring.
|
153
|
-
|
154
|
-
See Also
|
155
|
-
--------
|
156
|
-
:py:meth:`tme.matching_exhaustive.flc_setup`.
|
157
|
-
"""
|
158
|
-
|
159
|
-
def base_usage(self) -> int:
|
160
|
-
float_arrays = self.real_array_size * self.float_nbytes * 2
|
161
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes * 2
|
162
|
-
return float_arrays + complex_arrays
|
163
|
-
|
164
|
-
def per_fork(self) -> int:
|
165
|
-
float_arrays = self.real_array_size * self.float_nbytes * 3
|
166
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes * 2
|
167
|
-
return float_arrays + complex_arrays
|
168
|
-
|
169
|
-
|
170
|
-
class MCCMemoryUsage(MatchingMemoryUsage):
|
171
|
-
"""
|
172
|
-
Memory usage estimation for MCC scoring.
|
173
|
-
|
174
|
-
See Also
|
175
|
-
--------
|
176
|
-
:py:meth:`tme.matching_exhaustive.mcc_setup`.
|
177
|
-
"""
|
178
|
-
|
179
|
-
def base_usage(self) -> int:
|
180
|
-
float_arrays = self.real_array_size * self.float_nbytes * 2
|
181
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes * 3
|
182
|
-
return float_arrays + complex_arrays
|
183
|
-
|
184
|
-
def per_fork(self) -> int:
|
185
|
-
float_arrays = self.real_array_size * self.float_nbytes * 6
|
186
|
-
complex_arrays = self.complex_array_size * self.complex_nbytes
|
187
|
-
return float_arrays + complex_arrays
|
188
|
-
|
189
|
-
|
190
|
-
class MaxScoreOverRotationsMemoryUsage(MatchingMemoryUsage):
|
191
|
-
"""
|
192
|
-
Memory usage estimation MaxScoreOverRotations Analyzer.
|
193
|
-
|
194
|
-
See Also
|
195
|
-
--------
|
196
|
-
:py:class:`tme.analyzer.MaxScoreOverRotations`.
|
197
|
-
"""
|
198
|
-
|
199
|
-
def base_usage(self) -> int:
|
200
|
-
float_arrays = self.real_array_size * self.float_nbytes * 2
|
201
|
-
return float_arrays
|
202
|
-
|
203
|
-
def per_fork(self) -> int:
|
204
|
-
return 0
|
205
|
-
|
206
|
-
|
207
|
-
class PeakCallerMaximumFilterMemoryUsage(MatchingMemoryUsage):
|
208
|
-
"""
|
209
|
-
Memory usage estimation MaxScoreOverRotations Analyzer.
|
210
|
-
|
211
|
-
See Also
|
212
|
-
--------
|
213
|
-
:py:class:`tme.analyzer.PeakCallerMaximumFilter`.
|
214
|
-
"""
|
215
|
-
|
216
|
-
def base_usage(self) -> int:
|
217
|
-
float_arrays = self.real_array_size * self.float_nbytes
|
218
|
-
return float_arrays
|
219
|
-
|
220
|
-
def per_fork(self) -> int:
|
221
|
-
float_arrays = self.real_array_size * self.float_nbytes
|
222
|
-
return float_arrays
|
223
|
-
|
224
|
-
|
225
|
-
class CupyBackendMemoryUsage(MatchingMemoryUsage):
|
226
|
-
"""
|
227
|
-
Memory usage estimation for CupyBackend.
|
228
|
-
|
229
|
-
See Also
|
230
|
-
--------
|
231
|
-
:py:class:`tme.backends.CupyBackend`.
|
232
|
-
"""
|
233
|
-
|
234
|
-
def base_usage(self) -> int:
|
235
|
-
# FFT plans, overhead from assigning FFT result, rotation interpolation
|
236
|
-
complex_arrays = self.real_array_size * self.complex_nbytes * 3
|
237
|
-
float_arrays = self.complex_array_size * self.float_nbytes * 2
|
238
|
-
return float_arrays + complex_arrays
|
239
|
-
|
240
|
-
def per_fork(self) -> int:
|
241
|
-
return 0
|
242
|
-
|
243
|
-
|
244
|
-
def _compute_convolution_shapes(
|
245
|
-
arr1_shape: Tuple[int], arr2_shape: Tuple[int]
|
246
|
-
) -> Tuple[Tuple[int], Tuple[int], Tuple[int]]:
|
247
|
-
"""
|
248
|
-
Computes regular, optimized and fourier convolution shape.
|
249
|
-
|
250
|
-
Parameters
|
251
|
-
----------
|
252
|
-
arr1_shape : tuple
|
253
|
-
Tuple of integers corresponding to array1 shape.
|
254
|
-
arr2_shape : tuple
|
255
|
-
Tuple of integers corresponding to array2 shape.
|
256
|
-
|
257
|
-
Returns
|
258
|
-
-------
|
259
|
-
tuple
|
260
|
-
Tuple with regular convolution shape, convolution shape optimized for faster
|
261
|
-
fourier transform, shape of the forward fourier transform
|
262
|
-
(see :py:meth:`build_fft`).
|
263
|
-
"""
|
264
|
-
convolution_shape = np.add(arr1_shape, arr2_shape) - 1
|
265
|
-
fast_shape = [next_fast_len(x) for x in convolution_shape]
|
266
|
-
fast_ft_shape = list(fast_shape[:-1]) + [fast_shape[-1] // 2 + 1]
|
267
|
-
|
268
|
-
return convolution_shape, fast_shape, fast_ft_shape
|
269
|
-
|
270
|
-
|
271
|
-
MATCHING_MEMORY_REGISTRY = {
|
272
|
-
"CC": CCMemoryUsage,
|
273
|
-
"LCC": LCCMemoryUsage,
|
274
|
-
"CORR": CORRMemoryUsage,
|
275
|
-
"CAM": CAMMemoryUsage,
|
276
|
-
"MCC": MCCMemoryUsage,
|
277
|
-
"FLCSphericalMask": FLCSphericalMaskMemoryUsage,
|
278
|
-
"FLC": FLCMemoryUsage,
|
279
|
-
"FLC2": FLCMemoryUsage,
|
280
|
-
"MaxScoreOverRotations": MaxScoreOverRotationsMemoryUsage,
|
281
|
-
"PeakCallerMaximumFilter": PeakCallerMaximumFilterMemoryUsage,
|
282
|
-
"cupy": CupyBackendMemoryUsage,
|
283
|
-
"pytorch": CupyBackendMemoryUsage,
|
284
|
-
}
|
285
|
-
|
286
|
-
|
287
|
-
def estimate_ram_usage(
|
288
|
-
shape1: Tuple[int],
|
289
|
-
shape2: Tuple[int],
|
290
|
-
matching_method: str,
|
291
|
-
ncores: int,
|
292
|
-
analyzer_method: str = None,
|
293
|
-
backend: str = None,
|
294
|
-
float_nbytes: int = 4,
|
295
|
-
complex_nbytes: int = 8,
|
296
|
-
integer_nbytes: int = 4,
|
297
|
-
) -> int:
|
298
|
-
"""
|
299
|
-
Estimate the RAM usage for a given convolution operation based on input shapes,
|
300
|
-
matching_method, and number of cores.
|
301
|
-
|
302
|
-
Parameters
|
303
|
-
----------
|
304
|
-
shape1 : tuple
|
305
|
-
The shape of the input target.
|
306
|
-
shape2 : tuple
|
307
|
-
The shape of the input template.
|
308
|
-
matching_method : str
|
309
|
-
The method used for the operation.
|
310
|
-
is_gpu : bool, optional
|
311
|
-
Whether the computation is performed on GPU. This factors in FFT
|
312
|
-
plan caching.
|
313
|
-
analyzer_method : str, optional
|
314
|
-
The method used for score analysis.
|
315
|
-
backend : str, optional
|
316
|
-
Backend used for computation.
|
317
|
-
ncores : int
|
318
|
-
The number of CPU cores used for the operation.
|
319
|
-
float_nbytes : int
|
320
|
-
Number of bytes of the used float, e.g. 4 for float32.
|
321
|
-
complex_nbytes : int
|
322
|
-
Number of bytes of the used complex, e.g. 8 for complex64.
|
323
|
-
integer_nbytes : int
|
324
|
-
Number of bytes of the used integer, e.g. 4 for int32.
|
325
|
-
|
326
|
-
Returns
|
327
|
-
-------
|
328
|
-
int
|
329
|
-
The estimated RAM usage for the operation in bytes.
|
330
|
-
|
331
|
-
Notes
|
332
|
-
-----
|
333
|
-
Residual memory from other objects that may remain allocated during
|
334
|
-
template matching, e.g. the full sized target when using splitting,
|
335
|
-
are not considered by this function.
|
336
|
-
|
337
|
-
Raises
|
338
|
-
------
|
339
|
-
ValueError
|
340
|
-
If an unsupported matching_methode is provided.
|
341
|
-
"""
|
342
|
-
if matching_method not in MATCHING_MEMORY_REGISTRY:
|
343
|
-
raise ValueError(
|
344
|
-
f"Supported options are {','.join(MATCHING_MEMORY_REGISTRY.keys())}"
|
345
|
-
)
|
346
|
-
|
347
|
-
convolution_shape, fast_shape, ft_shape = _compute_convolution_shapes(
|
348
|
-
shape1, shape2
|
349
|
-
)
|
350
|
-
|
351
|
-
memory_instance = MATCHING_MEMORY_REGISTRY[matching_method](
|
352
|
-
fast_shape=fast_shape,
|
353
|
-
ft_shape=ft_shape,
|
354
|
-
float_nbytes=float_nbytes,
|
355
|
-
complex_nbytes=complex_nbytes,
|
356
|
-
integer_nbytes=integer_nbytes,
|
357
|
-
)
|
358
|
-
|
359
|
-
nbytes = memory_instance.base_usage() + memory_instance.per_fork() * ncores
|
360
|
-
|
361
|
-
analyzer_instance = MATCHING_MEMORY_REGISTRY.get(analyzer_method, None)
|
362
|
-
if analyzer_instance is not None:
|
363
|
-
analyzer_instance = analyzer_instance(
|
364
|
-
fast_shape=fast_shape,
|
365
|
-
ft_shape=ft_shape,
|
366
|
-
float_nbytes=float_nbytes,
|
367
|
-
complex_nbytes=complex_nbytes,
|
368
|
-
integer_nbytes=integer_nbytes,
|
369
|
-
)
|
370
|
-
nbytes += analyzer_instance.base_usage() + analyzer_instance.per_fork() * ncores
|
371
|
-
|
372
|
-
backend_instance = MATCHING_MEMORY_REGISTRY.get(backend, None)
|
373
|
-
if backend_instance is not None:
|
374
|
-
backend_instance = backend_instance(
|
375
|
-
fast_shape=fast_shape,
|
376
|
-
ft_shape=ft_shape,
|
377
|
-
float_nbytes=float_nbytes,
|
378
|
-
complex_nbytes=complex_nbytes,
|
379
|
-
integer_nbytes=integer_nbytes,
|
380
|
-
)
|
381
|
-
nbytes += backend_instance.base_usage() + backend_instance.per_fork() * ncores
|
382
|
-
|
383
|
-
return nbytes
|
File without changes
|
File without changes
|
File without changes
|