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.
Files changed (49) hide show
  1. {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/match_template.py +147 -93
  2. {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/postprocess.py +67 -26
  3. {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/preprocessor_gui.py +175 -85
  4. pytme-0.2.2.dist-info/METADATA +91 -0
  5. pytme-0.2.2.dist-info/RECORD +74 -0
  6. {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/WHEEL +1 -1
  7. scripts/extract_candidates.py +20 -13
  8. scripts/match_template.py +147 -93
  9. scripts/match_template_filters.py +154 -95
  10. scripts/postprocess.py +67 -26
  11. scripts/preprocessor_gui.py +175 -85
  12. scripts/refine_matches.py +265 -61
  13. tme/__init__.py +0 -1
  14. tme/__version__.py +1 -1
  15. tme/analyzer.py +451 -809
  16. tme/backends/__init__.py +40 -11
  17. tme/backends/_jax_utils.py +185 -0
  18. tme/backends/cupy_backend.py +111 -223
  19. tme/backends/jax_backend.py +214 -150
  20. tme/backends/matching_backend.py +445 -384
  21. tme/backends/mlx_backend.py +32 -59
  22. tme/backends/npfftw_backend.py +239 -507
  23. tme/backends/pytorch_backend.py +21 -145
  24. tme/density.py +233 -363
  25. tme/extensions.cpython-311-darwin.so +0 -0
  26. tme/matching_data.py +322 -285
  27. tme/matching_exhaustive.py +172 -1493
  28. tme/matching_optimization.py +143 -106
  29. tme/matching_scores.py +884 -0
  30. tme/matching_utils.py +280 -386
  31. tme/memory.py +377 -0
  32. tme/orientations.py +52 -12
  33. tme/parser.py +3 -4
  34. tme/preprocessing/_utils.py +61 -32
  35. tme/preprocessing/compose.py +7 -3
  36. tme/preprocessing/frequency_filters.py +49 -39
  37. tme/preprocessing/tilt_series.py +34 -40
  38. tme/preprocessor.py +560 -526
  39. tme/structure.py +491 -188
  40. tme/types.py +5 -3
  41. pytme-0.2.1.dist-info/METADATA +0 -73
  42. pytme-0.2.1.dist-info/RECORD +0 -73
  43. tme/helpers.py +0 -881
  44. tme/matching_constrained.py +0 -195
  45. {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/estimate_ram_usage.py +0 -0
  46. {pytme-0.2.1.data → pytme-0.2.2.data}/scripts/preprocess.py +0 -0
  47. {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/LICENSE +0 -0
  48. {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/entry_points.txt +0 -0
  49. {pytme-0.2.1.dist-info → pytme-0.2.2.dist-info}/top_level.txt +0 -0
@@ -9,12 +9,12 @@ from typing import Tuple, List, Callable
9
9
  import numpy as np
10
10
 
11
11
  from .npfftw_backend import NumpyFFTWBackend
12
- from ..types import NDArray, MlxArray, Scalar
12
+ from ..types import NDArray, MlxArray, Scalar, shm_type
13
13
 
14
14
 
15
15
  class MLXBackend(NumpyFFTWBackend):
16
16
  """
17
- A MLX based backend for template matching.
17
+ A mlx-based matching backend.
18
18
  """
19
19
 
20
20
  def __init__(
@@ -72,6 +72,15 @@ class MLXBackend(NumpyFFTWBackend):
72
72
  return None
73
73
  return self._array_backend.add(x1, x2, **kwargs)
74
74
 
75
+ def multiply(self, x1, x2, out: MlxArray = None, **kwargs) -> MlxArray:
76
+ x1 = self.to_backend_array(x1)
77
+ x2 = self.to_backend_array(x2)
78
+
79
+ if out is not None:
80
+ out[:] = self._array_backend.multiply(x1, x2, **kwargs)
81
+ return None
82
+ return self._array_backend.multiply(x1, x2, **kwargs)
83
+
75
84
  def std(self, arr: MlxArray, axis) -> Scalar:
76
85
  return self._array_backend.sqrt(arr.var(axis=axis))
77
86
 
@@ -84,30 +93,12 @@ class MLXBackend(NumpyFFTWBackend):
84
93
  def tobytes(self, arr):
85
94
  return self.to_numpy_array(arr).tobytes()
86
95
 
87
- def preallocate_array(self, shape: Tuple[int], dtype: type = None) -> NDArray:
88
- """
89
- Returns a byte-aligned array of zeros with specified shape and dtype.
90
-
91
- Parameters
92
- ----------
93
- shape : Tuple[int]
94
- Desired shape for the array.
95
- dtype : type, optional
96
- Desired data type for the array.
97
-
98
- Returns
99
- -------
100
- NDArray
101
- Byte-aligned array of zeros with specified shape and dtype.
102
- """
103
- arr = self._array_backend.zeros(shape, dtype=dtype)
104
- return arr
105
-
106
96
  def full(self, shape, fill_value, dtype=None):
107
97
  return self._array_backend.full(shape=shape, dtype=dtype, vals=fill_value)
108
98
 
109
- def fill(self, arr: MlxArray, value: Scalar) -> None:
99
+ def fill(self, arr: MlxArray, value: Scalar) -> MlxArray:
110
100
  arr[:] = value
101
+ return arr
111
102
 
112
103
  def zeros(self, shape: Tuple[int], dtype: type = None) -> MlxArray:
113
104
  return self._array_backend.zeros(shape=shape, dtype=dtype)
@@ -189,13 +180,11 @@ class MLXBackend(NumpyFFTWBackend):
189
180
 
190
181
  return rfftn, irfftn
191
182
 
192
- def sharedarr_to_arr(
193
- self, shape: Tuple[int], dtype: str, shm: MlxArray
194
- ) -> MlxArray:
195
- return shm
183
+ def from_sharedarr(self, arr: MlxArray) -> MlxArray:
184
+ return arr
196
185
 
197
186
  @staticmethod
198
- def arr_to_sharedarr(arr: MlxArray, shared_memory_handler: type = None) -> MlxArray:
187
+ def to_sharedarr(arr: MlxArray, shared_memory_handler: type = None) -> shm_type:
199
188
  return arr
200
189
 
201
190
  def topk_indices(self, arr: NDArray, k: int):
@@ -204,7 +193,7 @@ class MLXBackend(NumpyFFTWBackend):
204
193
  ret = [self.to_backend_array(x) for x in ret]
205
194
  return ret
206
195
 
207
- def rotate_array(
196
+ def rigid_transform(
208
197
  self,
209
198
  arr: NDArray,
210
199
  rotation_matrix: NDArray,
@@ -214,10 +203,8 @@ class MLXBackend(NumpyFFTWBackend):
214
203
  out: NDArray = None,
215
204
  out_mask: NDArray = None,
216
205
  order: int = 3,
206
+ **kwargs,
217
207
  ) -> None:
218
- rotate_mask = arr_mask is not None
219
- return_type = (out is None) + 2 * rotate_mask * (out_mask is None)
220
-
221
208
  arr = self.to_numpy_array(arr)
222
209
  rotation_matrix = self.to_numpy_array(rotation_matrix)
223
210
 
@@ -227,46 +214,32 @@ class MLXBackend(NumpyFFTWBackend):
227
214
  if translation is not None:
228
215
  translation = self.to_numpy_array(translation)
229
216
 
230
- out_pass, out_mask_pass = None, None
231
- if out is not None:
232
- out_pass = self.to_numpy_array(out)
233
- if out_mask is not None:
234
- out_mask_pass = self.to_numpy_array(out_mask)
217
+ if out is None:
218
+ out = self.zeros(arr.shape)
219
+ if out_mask is None and arr_mask is not None:
220
+ out_mask_pass = self.zeros(arr_mask.shape)
235
221
 
236
- ret = NumpyFFTWBackend().rotate_array(
222
+ ret = NumpyFFTWBackend().rigid_transform(
237
223
  arr=arr,
238
224
  rotation_matrix=rotation_matrix,
239
225
  arr_mask=arr_mask,
240
226
  translation=translation,
241
227
  use_geometric_center=use_geometric_center,
242
- out=out_pass,
243
- out_mask=out_mask_pass,
244
228
  order=order,
245
229
  )
246
230
 
247
- if ret is not None:
248
- if len(ret) == 1 and out is None:
249
- out_pass = ret
250
- elif len(ret) == 1 and out_mask is None:
251
- out_mask_pass = ret
252
- else:
253
- out_pass, out_mask_pass = ret
231
+ out_pass, out_mask_pass = ret
232
+ out[:] = self.to_backend_array(out_pass)
254
233
 
255
- if out is not None:
256
- out[:] = self.to_backend_array(out_pass)
234
+ if out_mask_pass is not None:
235
+ out_mask_pass = self.to_backend_array(out_mask_pass)
257
236
 
258
237
  if out_mask is not None:
259
- out_mask[:] = self.to_backend_array(out_mask_pass)
260
-
261
- match return_type:
262
- case 0:
263
- return None
264
- case 1:
265
- return out
266
- case 2:
267
- return out_mask
268
- case 3:
269
- return out, out_mask
238
+ out_mask[:] = out_mask_pass
239
+ else:
240
+ out_mask = out_mask_pass
241
+
242
+ return out, out_mask
270
243
 
271
244
  def indices(self, arr: List) -> MlxArray:
272
245
  ret = NumpyFFTWBackend().indices(arr)