pytme 0.2.1__cp311-cp311-macosx_14_0_arm64.whl → 0.2.2__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.1.data → pytme-0.2.2.data}/scripts/match_template.py +147 -93
- {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/postprocess.py +67 -26
- {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/preprocessor_gui.py +175 -85
- pytme-0.2.2.dist-info/METADATA +91 -0
- pytme-0.2.2.dist-info/RECORD +74 -0
- {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/WHEEL +1 -1
- scripts/extract_candidates.py +20 -13
- scripts/match_template.py +147 -93
- scripts/match_template_filters.py +154 -95
- scripts/postprocess.py +67 -26
- scripts/preprocessor_gui.py +175 -85
- scripts/refine_matches.py +265 -61
- tme/__init__.py +0 -1
- tme/__version__.py +1 -1
- tme/analyzer.py +451 -809
- tme/backends/__init__.py +40 -11
- tme/backends/_jax_utils.py +185 -0
- tme/backends/cupy_backend.py +111 -223
- tme/backends/jax_backend.py +214 -150
- tme/backends/matching_backend.py +445 -384
- tme/backends/mlx_backend.py +32 -59
- tme/backends/npfftw_backend.py +239 -507
- tme/backends/pytorch_backend.py +21 -145
- tme/density.py +233 -363
- tme/extensions.cpython-311-darwin.so +0 -0
- tme/matching_data.py +322 -285
- tme/matching_exhaustive.py +172 -1493
- tme/matching_optimization.py +143 -106
- tme/matching_scores.py +884 -0
- tme/matching_utils.py +280 -386
- tme/memory.py +377 -0
- tme/orientations.py +52 -12
- tme/parser.py +3 -4
- tme/preprocessing/_utils.py +61 -32
- tme/preprocessing/compose.py +7 -3
- tme/preprocessing/frequency_filters.py +49 -39
- tme/preprocessing/tilt_series.py +34 -40
- tme/preprocessor.py +560 -526
- tme/structure.py +491 -188
- tme/types.py +5 -3
- pytme-0.2.1.dist-info/METADATA +0 -73
- pytme-0.2.1.dist-info/RECORD +0 -73
- tme/helpers.py +0 -881
- tme/matching_constrained.py +0 -195
- {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/estimate_ram_usage.py +0 -0
- {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/preprocess.py +0 -0
- {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/LICENSE +0 -0
- {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/entry_points.txt +0 -0
- {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/top_level.txt +0 -0
tme/matching_constrained.py
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
import numpy as np
|
2
|
-
from typing import Tuple, Dict
|
3
|
-
|
4
|
-
from scipy.ndimage import map_coordinates
|
5
|
-
|
6
|
-
from tme.types import ArrayLike
|
7
|
-
from tme.backends import backend
|
8
|
-
from tme.matching_data import MatchingData
|
9
|
-
from tme.matching_exhaustive import _normalize_under_mask
|
10
|
-
|
11
|
-
|
12
|
-
class MatchDensityToDensity:
|
13
|
-
def __init__(
|
14
|
-
self,
|
15
|
-
matching_data: "MatchingData",
|
16
|
-
pad_target_edges: bool = False,
|
17
|
-
pad_fourier: bool = False,
|
18
|
-
rotate_mask: bool = True,
|
19
|
-
interpolation_order: int = 1,
|
20
|
-
negate_score: bool = False,
|
21
|
-
):
|
22
|
-
self.rotate_mask = rotate_mask
|
23
|
-
self.interpolation_order = interpolation_order
|
24
|
-
|
25
|
-
target_pad = matching_data.target_padding(pad_target=pad_target_edges)
|
26
|
-
matching_data = matching_data.subset_by_slice(target_pad=target_pad)
|
27
|
-
|
28
|
-
fast_shape, fast_ft_shape, fourier_shift = matching_data.fourier_padding(
|
29
|
-
pad_fourier=pad_fourier
|
30
|
-
)
|
31
|
-
|
32
|
-
self.target = backend.topleft_pad(matching_data.target, fast_shape)
|
33
|
-
self.target_mask = matching_data.target_mask
|
34
|
-
|
35
|
-
self.template = matching_data.template
|
36
|
-
self.template_rot = backend.preallocate_array(
|
37
|
-
fast_shape, backend._default_dtype
|
38
|
-
)
|
39
|
-
|
40
|
-
self.template_mask, self.template_mask_rot = 1, 1
|
41
|
-
rotate_mask = False if matching_data.template_mask is None else rotate_mask
|
42
|
-
if matching_data.template_mask is not None:
|
43
|
-
self.template_mask = matching_data.template_mask
|
44
|
-
self.template_mask_rot = backend.topleft_pad(
|
45
|
-
matching_data.template_mask, fast_shape
|
46
|
-
)
|
47
|
-
|
48
|
-
self.score_sign = -1 if negate_score else 1
|
49
|
-
|
50
|
-
@staticmethod
|
51
|
-
def rigid_transform(
|
52
|
-
arr,
|
53
|
-
rotation_matrix,
|
54
|
-
translation,
|
55
|
-
arr_mask=None,
|
56
|
-
out=None,
|
57
|
-
out_mask=None,
|
58
|
-
order: int = 1,
|
59
|
-
use_geometric_center: bool = False,
|
60
|
-
):
|
61
|
-
rotate_mask = arr_mask is not None
|
62
|
-
return_type = (out is None) + 2 * rotate_mask * (out_mask is None)
|
63
|
-
translation = np.zeros(arr.ndim) if translation is None else translation
|
64
|
-
|
65
|
-
center = np.floor(np.array(arr.shape) / 2)[:, None]
|
66
|
-
grid = np.indices(arr.shape, dtype=np.float32).reshape(arr.ndim, -1)
|
67
|
-
np.subtract(grid, center, out=grid)
|
68
|
-
np.matmul(rotation_matrix.T, grid, out=grid)
|
69
|
-
np.add(grid, center, out=grid)
|
70
|
-
|
71
|
-
if out is None:
|
72
|
-
out = np.zeros_like(arr)
|
73
|
-
|
74
|
-
map_coordinates(arr, grid, order=order, output=out.ravel())
|
75
|
-
|
76
|
-
if out_mask is None and arr_mask is not None:
|
77
|
-
out_mask = np.zeros_like(arr_mask)
|
78
|
-
|
79
|
-
if arr_mask is not None:
|
80
|
-
map_coordinates(arr_mask, grid, order=order, output=out_mask.ravel())
|
81
|
-
|
82
|
-
match return_type:
|
83
|
-
case 0:
|
84
|
-
return None
|
85
|
-
case 1:
|
86
|
-
return out
|
87
|
-
case 2:
|
88
|
-
return out_mask
|
89
|
-
case 3:
|
90
|
-
return out, out_mask
|
91
|
-
|
92
|
-
@staticmethod
|
93
|
-
def angles_to_rotationmatrix(angles: Tuple[float]) -> ArrayLike:
|
94
|
-
angles = backend.to_numpy_array(angles)
|
95
|
-
rotation_matrix = euler_to_rotationmatrix(angles)
|
96
|
-
return backend.to_backend_array(rotation_matrix)
|
97
|
-
|
98
|
-
def format_translation(self, translation: Tuple[float] = None) -> ArrayLike:
|
99
|
-
if translation is None:
|
100
|
-
return backend.zeros(self.template.ndim, backend._default_dtype)
|
101
|
-
|
102
|
-
return backend.to_backend_array(translation)
|
103
|
-
|
104
|
-
def score_translation(self, x: Tuple[float]) -> float:
|
105
|
-
translation = self.format_translation(x)
|
106
|
-
rotation_matrix = self.angles_to_rotationmatrix((0, 0, 0))
|
107
|
-
|
108
|
-
return self(translation=translation, rotation_matrix=rotation_matrix)
|
109
|
-
|
110
|
-
def score_angles(self, x: Tuple[float]) -> float:
|
111
|
-
translation = self.format_translation(None)
|
112
|
-
rotation_matrix = self.angles_to_rotationmatrix(x)
|
113
|
-
|
114
|
-
return self(translation=translation, rotation_matrix=rotation_matrix)
|
115
|
-
|
116
|
-
def score(self, x: Tuple[float]) -> float:
|
117
|
-
split = len(x) // 2
|
118
|
-
translation, angles = x[:split], x[split:]
|
119
|
-
|
120
|
-
translation = self.format_translation(translation)
|
121
|
-
rotation_matrix = self.angles_to_rotationmatrix(angles)
|
122
|
-
|
123
|
-
return self(translation=translation, rotation_matrix=rotation_matrix)
|
124
|
-
|
125
|
-
|
126
|
-
class FLC(MatchDensityToDensity):
|
127
|
-
def __init__(self, **kwargs: Dict):
|
128
|
-
super().__init__(**kwargs)
|
129
|
-
|
130
|
-
if self.target_mask is not None:
|
131
|
-
backend.multiply(self.target, self.target_mask, out=self.target)
|
132
|
-
|
133
|
-
self.target_square = backend.square(self.target)
|
134
|
-
|
135
|
-
_normalize_under_mask(
|
136
|
-
template=self.template,
|
137
|
-
mask=self.template_mask,
|
138
|
-
mask_intensity=backend.sum(self.template_mask),
|
139
|
-
)
|
140
|
-
|
141
|
-
self.template = backend.reverse(self.template)
|
142
|
-
self.template_mask = backend.reverse(self.template_mask)
|
143
|
-
|
144
|
-
def __call__(self, translation: ArrayLike, rotation_matrix: ArrayLike) -> float:
|
145
|
-
if self.rotate_mask:
|
146
|
-
self.rigid_transform(
|
147
|
-
arr=self.template,
|
148
|
-
arr_mask=self.template_mask,
|
149
|
-
rotation_matrix=rotation_matrix,
|
150
|
-
translation=translation,
|
151
|
-
out=self.template_rot,
|
152
|
-
out_mask=self.template_mask_rot,
|
153
|
-
use_geometric_center=False,
|
154
|
-
order=self.interpolation_order,
|
155
|
-
)
|
156
|
-
else:
|
157
|
-
self.rigid_transform(
|
158
|
-
arr=self.template,
|
159
|
-
rotation_matrix=rotation_matrix,
|
160
|
-
translation=translation,
|
161
|
-
out=self.template_rot,
|
162
|
-
use_geometric_center=False,
|
163
|
-
order=self.interpolation_order,
|
164
|
-
)
|
165
|
-
n_observations = backend.sum(self.template_mask_rot)
|
166
|
-
|
167
|
-
_normalize_under_mask(
|
168
|
-
template=self.template_rot,
|
169
|
-
mask=self.template_mask_rot,
|
170
|
-
mask_intensity=n_observations,
|
171
|
-
)
|
172
|
-
|
173
|
-
ex2 = backend.sum(
|
174
|
-
backend.divide(
|
175
|
-
backend.sum(
|
176
|
-
backend.multiply(self.target_square, self.template_mask_rot),
|
177
|
-
),
|
178
|
-
n_observations,
|
179
|
-
)
|
180
|
-
)
|
181
|
-
e2x = backend.square(
|
182
|
-
backend.divide(
|
183
|
-
backend.sum(backend.multiply(self.target, self.template_mask_rot)),
|
184
|
-
n_observations,
|
185
|
-
)
|
186
|
-
)
|
187
|
-
|
188
|
-
denominator = backend.maximum(backend.subtract(ex2, e2x), 0.0)
|
189
|
-
denominator = backend.sqrt(denominator)
|
190
|
-
denominator = backend.multiply(denominator, n_observations)
|
191
|
-
|
192
|
-
overlap = backend.sum(backend.multiply(self.template_rot, self.target))
|
193
|
-
|
194
|
-
score = backend.divide(overlap, denominator) * self.score_sign
|
195
|
-
return score
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|