pytme 0.2.0__cp311-cp311-macosx_14_0_arm64.whl → 0.2.1__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 (40) hide show
  1. {pytme-0.2.0.data → pytme-0.2.1.data}/scripts/match_template.py +183 -69
  2. {pytme-0.2.0.data → pytme-0.2.1.data}/scripts/postprocess.py +107 -49
  3. {pytme-0.2.0.data → pytme-0.2.1.data}/scripts/preprocessor_gui.py +4 -1
  4. {pytme-0.2.0.dist-info → pytme-0.2.1.dist-info}/METADATA +1 -1
  5. pytme-0.2.1.dist-info/RECORD +73 -0
  6. scripts/extract_candidates.py +117 -85
  7. scripts/match_template.py +183 -69
  8. scripts/match_template_filters.py +193 -71
  9. scripts/postprocess.py +107 -49
  10. scripts/preprocessor_gui.py +4 -1
  11. scripts/refine_matches.py +364 -160
  12. tme/__version__.py +1 -1
  13. tme/analyzer.py +259 -117
  14. tme/backends/__init__.py +1 -0
  15. tme/backends/cupy_backend.py +20 -13
  16. tme/backends/jax_backend.py +218 -0
  17. tme/backends/matching_backend.py +25 -10
  18. tme/backends/mlx_backend.py +13 -9
  19. tme/backends/npfftw_backend.py +20 -8
  20. tme/backends/pytorch_backend.py +20 -9
  21. tme/density.py +79 -60
  22. tme/extensions.cpython-311-darwin.so +0 -0
  23. tme/matching_data.py +85 -61
  24. tme/matching_exhaustive.py +222 -129
  25. tme/matching_optimization.py +117 -76
  26. tme/orientations.py +175 -55
  27. tme/preprocessing/_utils.py +17 -5
  28. tme/preprocessing/composable_filter.py +2 -1
  29. tme/preprocessing/compose.py +1 -2
  30. tme/preprocessing/frequency_filters.py +97 -41
  31. tme/preprocessing/tilt_series.py +137 -87
  32. tme/preprocessor.py +3 -0
  33. tme/structure.py +4 -1
  34. pytme-0.2.0.dist-info/RECORD +0 -72
  35. {pytme-0.2.0.data → pytme-0.2.1.data}/scripts/estimate_ram_usage.py +0 -0
  36. {pytme-0.2.0.data → pytme-0.2.1.data}/scripts/preprocess.py +0 -0
  37. {pytme-0.2.0.dist-info → pytme-0.2.1.dist-info}/LICENSE +0 -0
  38. {pytme-0.2.0.dist-info → pytme-0.2.1.dist-info}/WHEEL +0 -0
  39. {pytme-0.2.0.dist-info → pytme-0.2.1.dist-info}/entry_points.txt +0 -0
  40. {pytme-0.2.0.dist-info → pytme-0.2.1.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytme
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Python Template Matching Engine
5
5
  Author: Valentin Maurer
6
6
  Author-email: Valentin Maurer <valentin.maurer@embl-hamburg.de>
@@ -0,0 +1,73 @@
1
+ pytme-0.2.1.data/scripts/estimate_ram_usage.py,sha256=R1NDpFajcF-MonJ4a43SfDlA-nxBYwK7D2quzCdsVFM,2767
2
+ pytme-0.2.1.data/scripts/match_template.py,sha256=d9c_014dy4X9jFtulHkypuRqcDTCJsddA5-tt2ZUw6g,39833
3
+ pytme-0.2.1.data/scripts/postprocess.py,sha256=dg2TQpoTiQFDm1Q-l-WH3g0kIqwBEvKk-hX1QhhgjoI,23132
4
+ pytme-0.2.1.data/scripts/preprocess.py,sha256=zog-l2Je-GeouJ6SnamOMuHgTn7fFPiGnO5X03y5qSY,2527
5
+ pytme-0.2.1.data/scripts/preprocessor_gui.py,sha256=-lYdd9--xvgZghhuPE43JGycventc3tPoG4JF1wkXo0,35254
6
+ scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ scripts/estimate_ram_usage.py,sha256=rN7haobnHg3YcgGJIp81FNiCzy8-saJGeEurQlmQmNQ,2768
8
+ scripts/extract_candidates.py,sha256=j8SZNw4-F73_7o0_NorioQcyH8LatrbNX4pwfe-XC9A,8139
9
+ scripts/match_template.py,sha256=yTFtX0cZqk6Q38wtlDDTzHRRJsGLNnoVTXQeXWBH8Rc,39834
10
+ scripts/match_template_filters.py,sha256=-QnSZsGgLP5k6nH5DXINO2Yd7c1zEq_qyIDwfGB0w8o,40272
11
+ scripts/postprocess.py,sha256=L67WF7A9RIWEjr04KzHjHDg4LUpbn6h19JFKh_OyonI,23133
12
+ scripts/preprocess.py,sha256=ebJVLxbRlB6TI5YHNr0VavZ4lmaRdf8QVafyiDhh_oU,2528
13
+ scripts/preprocessor_gui.py,sha256=2-IKFVwztnvOa_G6fZ4SYsk1g6rFb3_-LMDmWSHqCno,35255
14
+ scripts/refine_matches.py,sha256=BlQqZFYdatAUAPly14xobDgqJOWvwEidjTz4pW4QBlg,14628
15
+ tme/__init__.py,sha256=MGVeRX1f5k6RwExBcffZtCM7igNNtpoIr2G2yJZ4OHI,251
16
+ tme/__version__.py,sha256=HfjVOrpTnmZ-xVFCYSVmX50EXaBQeJteUHG-PD6iQs8,22
17
+ tme/analyzer.py,sha256=esp23U15jsctbtDy1QMcUwsiBCwXbapiRfH3ZEVvwOg,61500
18
+ tme/density.py,sha256=cMfHfZSY8Ff9w7HfE-Sqigo4XKT_naht3jMtdWg4sKk,88846
19
+ tme/extensions.cpython-311-darwin.so,sha256=nIqjOFVGoKxod55SSK7hNvHxk6uTnTQ-oqkYdSsmn6Y,411792
20
+ tme/helpers.py,sha256=TMtBuJoZk6q4M_rfkr8yPpGzJD74ycqyN3yXMuU9mr4,23625
21
+ tme/matching_constrained.py,sha256=NAJnZpusjQs5rKabHiNyrclXSPm27K0V8HVFjTQ2zB0,6725
22
+ tme/matching_data.py,sha256=QeAhwgqiwCpQIghlj9wN0jCbW1UpZH55DOZWFudtXSw,24869
23
+ tme/matching_exhaustive.py,sha256=YidMx0RGnV-YdAK-tEdG9aHg06sSE3QgV-D2KMTKcZE,63676
24
+ tme/matching_memory.py,sha256=bmCAUYyXWEet-1XXhldtc0irio2ytMSsAzWYyFI5LNM,11273
25
+ tme/matching_optimization.py,sha256=wil0-5DYrqLzgFMhi-uClkt5mzp15AE_--zmmhJbdkw,43530
26
+ tme/matching_utils.py,sha256=qLcRcfMCURsA5vFvJDUBa7xIAHsICWn_PB_jOYK3Pb0,42520
27
+ tme/orientations.py,sha256=3SuKZhscTGnclOfNJCz2Rq1KiePHFytPdjuHiQi7m5Q,23929
28
+ tme/parser.py,sha256=tA9ABeV95cZn8lJCukVUaocQ9RguR6ZZzQsMXf_-ud0,13887
29
+ tme/preprocessor.py,sha256=ylVO-D1o9lpvvApXEymkmtdRrvaFd2HrJSn9nsWcMTs,51225
30
+ tme/structure.py,sha256=mIhDhGksMf8cSARr0ofNhJQUpQIdpKZtJsX63Law2z0,52503
31
+ tme/types.py,sha256=2Tyh_xnMLxIWYb3aJDAUb6GWpaL6gcYMUm2YNbJlAPI,295
32
+ tme/backends/__init__.py,sha256=xNX4Vx182F57AwZjb0DwLJA-sps6DixnDRWPcMlOvWw,4397
33
+ tme/backends/cupy_backend.py,sha256=1Wsnoo0HiIELRGb8wT9VZJ5spVEU5-DVbyyY092RixI,13230
34
+ tme/backends/jax_backend.py,sha256=uq_Vk_ofb5JG9IGg3SfHn3YqcBD9c4wWypgdCu9HTno,7372
35
+ tme/backends/matching_backend.py,sha256=eFoowia-uzc1UYAq9AnDN3CMN31rWAT1ilCskH6sruw,29876
36
+ tme/backends/mlx_backend.py,sha256=pq4U3m3-dAkSC5y6P0R1CayvVKwi5rZjTVoeG4XOQ8g,8569
37
+ tme/backends/npfftw_backend.py,sha256=_PzGKO6fuo20RofChRqq7WlfqVm-6Ne6tMPEyxB3fvE,27856
38
+ tme/backends/pytorch_backend.py,sha256=cY3KSQdLy80NVvKSMy5Jj6HzD1UDsLRQTeC2WA70Abo,18694
39
+ tme/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ tme/data/c48n309.npy,sha256=NwH64mOEbm3tStq5c98o81fY1vMOoq4nvXDAh7Z7iZg,296768
41
+ tme/data/c48n527.npy,sha256=saSUMTa1R0MisPvgFL02a7IHQSwEZ-mJu0v3qJjg5AU,506048
42
+ tme/data/c48n9.npy,sha256=bDVLV6mWjZHSQfeDc-MOCKKarfc1jaNeVvpoe2xMUy4,8768
43
+ tme/data/c48u1.npy,sha256=JeXMFzFITs2ezdc3x5lp3jo1cHHHHVADSA1Tpf77kXs,1088
44
+ tme/data/c48u1153.npy,sha256=ECiEximtYDWtIux3Fwe_EJlyn08gUqP85DN9gjkT9_k,1107008
45
+ tme/data/c48u1201.npy,sha256=aceC_Jeienz_81X4520nPpZcg5tnRhbW795EqbpWkrg,1153088
46
+ tme/data/c48u1641.npy,sha256=p4LwW3LzdTjrUUpA7H53RfNWxYfPX0XjeSwZ39Ac78Q,1575488
47
+ tme/data/c48u181.npy,sha256=mLYXrv1YHLH6DsBp5MkxHkxlxgMnj1mw_KKI0udH-FY,173888
48
+ tme/data/c48u2219.npy,sha256=p8TQeX8YHu4pdxnwJjEAlQWAPa66W7kpK96iZKZr9JE,2130368
49
+ tme/data/c48u27.npy,sha256=k03ZNEsoPwBKCy8IeIa5G0WRZqjGZMtX6Ibu7EpJHvU,26048
50
+ tme/data/c48u2947.npy,sha256=icI97ED6ct66y7FIaJAugmjzrIWk7CINCxtO3wDTnrU,2829248
51
+ tme/data/c48u3733.npy,sha256=tla-__Pf-hpN6h04vtFIfkkFdCLple11VO06kr1dXkM,3583808
52
+ tme/data/c48u4749.npy,sha256=tItOA4oV7SiqCCREwz3fyEpZoxM0lCq_jfEo5_-fp2s,4559168
53
+ tme/data/c48u5879.npy,sha256=bFk89MllIFCX_sLXTYWFquSyN1NuahH4wwnEsPJLxzA,5643968
54
+ tme/data/c48u7111.npy,sha256=CMy9kI2edH-q9eTIVdgUtXurplYNI7Uqp4dXfkkVdf8,6826688
55
+ tme/data/c48u815.npy,sha256=bCuJxLtm0Sjg3GGxtyjGzRYZ1G0Gz79XHI-71GvqQnI,782528
56
+ tme/data/c48u83.npy,sha256=7ODJYnsiuDjGbgd9GFopsyIW2IjrYI0J2X2f-cK868U,79808
57
+ tme/data/c48u8649.npy,sha256=-IPlpR4zrPQZWhhSPu4zEulFdrCEVgTMFffCB5d-huE,8303168
58
+ tme/data/c600v.npy,sha256=JqSu3ALoL1A9iguehc0YGUMFPsh2fprHHp76VXeFXIw,2528
59
+ tme/data/c600vc.npy,sha256=Yht-GFXDSjjGvsjFBvyxxEZAI-ODADPd5gEgFNZQVTA,14528
60
+ tme/data/metadata.yaml,sha256=fAgX-mEzB0QMHTEtYDG4cSMbJhYxBbDJH3sdvJvL7a8,750
61
+ tme/data/quat_to_numpy.py,sha256=-gkDZb10fKBxwfYrSLCUWvMB76TzZWELCeKsYProwws,1333
62
+ tme/preprocessing/__init__.py,sha256=7O3vDzJcIfxovJkf7avWSPtzaIVlTbmsW7egQFukC_s,98
63
+ tme/preprocessing/_utils.py,sha256=jj5VSRLewO4uk0cHoEhpw2rTU9taT8iuZCijvbFcrw0,5190
64
+ tme/preprocessing/composable_filter.py,sha256=sp3bN8JeFB2r384cEIgvN6yXjC53GCoPhBmGI0S0kbI,781
65
+ tme/preprocessing/compose.py,sha256=tbQMo3LaKRBnOFKoqZ64as3i0t6U6312s76Csz0FPvk,1324
66
+ tme/preprocessing/frequency_filters.py,sha256=k3MvXTBeoETTp5WINpqxEcmhiHSFh90QyAJBXe-fGxs,12614
67
+ tme/preprocessing/tilt_series.py,sha256=OaYMuN4e0F5Z7tuNVwG_kn69E4zPAU6_xIoA5B-IQUw,34747
68
+ pytme-0.2.1.dist-info/LICENSE,sha256=K1IUNSVAz8BXbpH5EA8y5FpaHdvFXnAF2zeK95Lr2bY,18467
69
+ pytme-0.2.1.dist-info/METADATA,sha256=pTq0YVA2oWM7Zo8p-lk6ynkuZsEHAPnDDEbzcbEon_4,2165
70
+ pytme-0.2.1.dist-info/WHEEL,sha256=BDgKu9_KNfDn85ptly0T56JpX4avXH07X_ZCqAJnQwY,110
71
+ pytme-0.2.1.dist-info/entry_points.txt,sha256=ff3LQL3FCWfCYOwFiP9zatm7laUbnwCkuPELkQVyUO4,241
72
+ pytme-0.2.1.dist-info/top_level.txt,sha256=J8FUkazOb2fZ0n_KexnqCGyNOtie2bwisFSUBiM5-0w,12
73
+ pytme-0.2.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  #!python3
2
- """ CLI to simplify analysing the output of match_template.py.
2
+ """ Prepare orientations stack for refinement.
3
3
 
4
4
  Copyright (c) 2023 European Molecular Biology Laboratory
5
5
 
@@ -12,13 +12,33 @@ import numpy as np
12
12
 
13
13
  from tme import Density, Orientations
14
14
  from tme.matching_utils import (
15
- create_mask,
15
+ load_pickle,
16
16
  generate_tempfile_name,
17
17
  rotation_aligning_vectors,
18
18
  euler_from_rotationmatrix,
19
+ euler_to_rotationmatrix,
19
20
  )
20
21
 
21
22
 
23
+ class ProgressBar:
24
+ """
25
+ ASCII progress bar.
26
+ """
27
+
28
+ def __init__(self, message : str, nchars : int, total : int):
29
+ self._size = nchars - len(message)
30
+ self._message = message
31
+ self._total = total
32
+
33
+ def update(self, cur):
34
+ x = int(cur * self._size / self._total)
35
+ print(
36
+ "%s[%s%s] %i/%i\r"
37
+ % (self._message, "#" * x, "." * (self._size - x), cur, self._total),
38
+ end=''
39
+ )
40
+
41
+
22
42
  def parse_args():
23
43
  parser = argparse.ArgumentParser(
24
44
  description="Extract matching candidates for further refinement."
@@ -52,57 +72,61 @@ def parse_args():
52
72
  io_group.add_argument(
53
73
  "-o",
54
74
  "--output_file",
55
- required=False,
75
+ required=True,
56
76
  type=str,
57
77
  help="Path to output HDF5 file.",
58
78
  )
59
79
 
60
- extraction_group = parser.add_argument_group("Extraction")
61
- extraction_group.add_argument(
62
- "--box_size",
80
+ alignment_group = parser.add_argument_group("Alignment")
81
+ alignment_group.add_argument(
82
+ "--align_orientations",
83
+ action="store_true",
63
84
  required=False,
64
- type=int,
65
- help="Box size for extraction, defaults to two times the template box.",
85
+ help="Whether to align extracted orientations based on their angles. Allows "
86
+ "for efficient subsequent sampling of cone angles.",
66
87
  )
67
- extraction_group.add_argument(
68
- "--alignment_vector",
88
+ alignment_group.add_argument(
89
+ "--angles_are_vector",
90
+ action="store_true",
69
91
  required=False,
70
- type=str,
71
- help="Vector to align extracted coordinate to e.g. '1,0,0'. If provided, euler_z"
72
- "euler_y and euler_x are assumed to be a vector that will be rotated to match "
73
- "alignment_vector.",
92
+ help="Considers euler_z euler_y, euler_x as vector that will be rotated to align "
93
+ "with the z-axis (1,0,0). Only considered when --align_orientations is set."
74
94
  )
75
- extraction_group.add_argument(
95
+ alignment_group.add_argument(
76
96
  "--interpolation_order",
77
97
  dest="interpolation_order",
78
98
  required=False,
79
99
  type=int,
80
100
  default=1,
81
- help="Spline interpolation used for template rotations. If less than zero "
82
- "no interpolation is performed.",
101
+ help="Interpolation order for alignment, less than zero is no interpolation."
83
102
  )
103
+
104
+ extraction_group = parser.add_argument_group("Extraction")
84
105
  extraction_group.add_argument(
85
- "--translation_uncertainty",
86
- dest="translation_uncertainty",
106
+ "--box_size",
87
107
  required=False,
88
108
  type=int,
89
- default=None,
90
- help="Creates a cented spherical target mask with given radius in voxel.",
109
+ help="Box size for extraction, defaults to two times the template.",
91
110
  )
92
111
  extraction_group.add_argument(
93
- "--mask_path",
94
- dest="mask_path",
112
+ "--keep_out_of_box",
113
+ action="store_true",
95
114
  required=False,
96
- type=str,
97
- default="target_mask.h5",
98
- help="Path to write spherical mask to, defaults to target_mask.h5.",
115
+ help="Whether to keep orientations that fall outside the box. If the "
116
+ "orientations are sensible, it is safe to pass this flag.",
99
117
  )
118
+
100
119
  args = parser.parse_args()
101
120
 
102
- if args.alignment_vector is not None:
103
- args.alignment_vector = [float(x) for x in args.alignment_vector.split(",")]
104
- if len(args.alignment_vector) != 3:
105
- raise ValueError("Only three-dimensional vectors are supported")
121
+ data_present = args.target is not None and args.template is not None
122
+ if args.input_file is None and not data_present:
123
+ raise ValueError(
124
+ "Either --input_file or --target and --template need to be specified."
125
+ )
126
+ elif args.input_file is not None and data_present:
127
+ raise ValueError(
128
+ "Please specific either --input_file or --target and --template."
129
+ )
106
130
 
107
131
  return args
108
132
 
@@ -111,57 +135,59 @@ def main():
111
135
  args = parse_args()
112
136
  orientations = Orientations.from_file(args.orientations)
113
137
 
138
+ if args.input_file is not None:
139
+ data = load_pickle(args.input_file)
140
+ target_origin, _, sampling_rate, cli_args = data[-1]
141
+ args.target, args.template = cli_args.target, cli_args.template
142
+
114
143
  target = Density.from_file(args.target, use_memmap=True)
115
- template = Density.from_file(args.template)
116
144
 
117
- box_size = template.shape
118
- if args.box_size is not None:
119
- args.box_size = args.box_size // 2
120
- box_size = np.full(template.data.ndim, fill_value=args.box_size, dtype=int)
145
+ try:
146
+ template = Density.from_file(args.template)
147
+ except Exception:
148
+ template = Density.from_structure(args.template, sampling_rate = target.sampling_rate)
149
+
150
+ box_size = args.box_size
151
+ if box_size is None:
152
+ box_size = np.multiply(template.shape, 2)
153
+ box_size = np.array(box_size)
154
+ box_size = np.repeat(box_size, template.data.ndim // box_size.size).astype(int)
155
+
156
+ extraction_shape = np.copy(box_size)
157
+ if args.align_orientations:
158
+ extraction_shape[:] = int(np.linalg.norm(box_size) + 1)
121
159
 
122
- subtomo_shape = np.multiply(box_size, 2).astype(int)
123
- extraction_scaling = 3 if args.alignment_vector is not None else 2
124
- extraction_shape = np.multiply(box_size, extraction_scaling).astype(int)
125
160
  orientations, cand_slices, obs_slices = orientations.get_extraction_slices(
126
161
  target_shape=target.shape,
127
162
  extraction_shape=extraction_shape,
128
- drop_out_of_box=True,
163
+ drop_out_of_box=not args.keep_out_of_box,
129
164
  return_orientations=True,
130
165
  )
131
166
 
167
+ if args.align_orientations:
168
+ orientations.rotations = orientations.rotations.astype(np.float32)
169
+ for index in range(orientations.rotations.shape[0]):
170
+ rotation_matrix = euler_to_rotationmatrix(orientations.rotations[index])
171
+ rotation_matrix = np.linalg.inv(rotation_matrix)
172
+ if args.angles_are_vector:
173
+ rotation_matrix = rotation_aligning_vectors(
174
+ orientations.rotations[index], target_vector=(1,0,0)
175
+ )
176
+ orientations.rotations[index] = euler_from_rotationmatrix(rotation_matrix)
177
+
178
+
132
179
  filename = generate_tempfile_name()
133
180
  output_dtype = target.data.dtype
134
- if args.alignment_vector is not None:
181
+ if args.align_orientations is not None:
135
182
  output_dtype = np.float32
136
183
 
137
- if args.translation_uncertainty is not None:
138
- dens = Density(
139
- np.memmap(
140
- args.mask_path,
141
- mode="w+",
142
- shape=(len(obs_slices), *subtomo_shape),
143
- dtype=output_dtype,
144
- ),
145
- sampling_rate=(1, *target.sampling_rate),
146
- origin=(0, *target.origin),
147
- )
148
- dens.data[:] = 0
149
- mask = create_mask(
150
- mask_type="ellipse",
151
- center=template.shape,
152
- radius=args.translation_uncertainty,
153
- shape=subtomo_shape,
154
- )
155
- dens.data[:] = mask
156
- dens.to_file(args.mask_path)
157
-
158
184
  target.data = target.data.astype(output_dtype)
159
185
 
160
186
  dens = Density(
161
187
  np.memmap(
162
188
  filename,
163
189
  mode="w+",
164
- shape=(len(obs_slices), *subtomo_shape),
190
+ shape=(len(obs_slices), *box_size),
165
191
  dtype=output_dtype,
166
192
  ),
167
193
  sampling_rate=(1, *target.sampling_rate),
@@ -169,50 +195,56 @@ def main():
169
195
  )
170
196
  dens.data[:] = target.metadata["mean"]
171
197
 
172
- target_meta = {
173
- k: v for k, v in target.metadata.items() if k in ("mean", "max", "min", "std")
174
- }
175
-
176
- total_slices = len(obs_slices)
177
- magnitude = len(str(total_slices))
178
- for index, obs_slice in enumerate(obs_slices):
179
- print(f"Processing {index:{magnitude}} / {total_slices:{magnitude}}", end="\r")
198
+ print(target.data.shape)
199
+ # There appears to be an isseu with the stack creation. Trace this further
200
+ data_subset = np.zeros(extraction_shape, dtype = target.data.dtype)
201
+ pbar = ProgressBar(message = "Orientation ", nchars = 80, total = len(obs_slices))
202
+ for index, (obs_slice, cand_slice) in enumerate(zip(obs_slices, cand_slices)):
203
+ pbar.update(index + 1)
180
204
 
205
+ data_subset.fill(0)
206
+ data_subset[cand_slice] = target.data[obs_slice]
181
207
  target_subset = Density(
182
- target.data[obs_slice],
208
+ data_subset,
183
209
  sampling_rate=target.sampling_rate,
184
210
  origin=target.origin,
185
211
  )
186
212
 
187
- rotation_matrix = np.eye(target_subset.data.ndim)
188
- if args.alignment_vector is not None:
189
- normal = orientations.rotations[index]
190
- # To visualize only normals were picked we would need to do the opposite
191
- # However, this allows us to align everything to the template axis
192
- rotation_matrix = rotation_aligning_vectors(
193
- normal, target_vector=args.alignment_vector
194
- )
195
-
213
+ if args.align_orientations:
214
+ rotation_matrix = euler_to_rotationmatrix(orientations.rotations[index])
196
215
  target_subset = target_subset.rigid_transform(
197
216
  rotation_matrix=rotation_matrix,
198
217
  use_geometric_center=True,
199
218
  order=args.interpolation_order,
200
219
  )
201
- target_subset.pad(subtomo_shape, center=True)
220
+ target_subset.pad(box_size, center=True)
221
+
222
+ target_value = target.data[tuple(orientations.translations[index].astype(int))]
223
+ center = np.divide(target_subset.data.shape, 2).astype(int ) + np.mod(target_subset.shape, 2)
224
+ print(np.where(target_subset.data == target_value), center)
225
+ print(target_subset.data[tuple(center.astype(int))],
226
+ target_value,
227
+ target_subset.data[tuple(center.astype(int))] == target_value
228
+ )
229
+
202
230
  dens.data[index] = target_subset.data
203
- orientations.rotations[index] = euler_from_rotationmatrix(rotation_matrix)
231
+ print("")
204
232
 
233
+ target_meta = {
234
+ k: v for k, v in target.metadata.items() if k in ("mean", "max", "min", "std")
235
+ }
205
236
  dens.metadata.update(target_meta)
237
+ dens.metadata["batch_dimension"] = (0, )
238
+
206
239
  dens.to_file(args.output_file)
207
240
  orientations.to_file(
208
- f"{splitext(args.output_file)}_aligned.tsv",
241
+ f"{splitext(args.output_file)[0]}_aligned.tsv",
209
242
  file_format="text"
210
243
  )
211
244
  orientations.to_file(
212
- f"{splitext(args.output_file)}_aligned.star",
245
+ f"{splitext(args.output_file)[0]}_aligned.star",
213
246
  file_format="relion"
214
247
  )
215
248
 
216
-
217
249
  if __name__ == "__main__":
218
250
  main()