|
1 | | -from collections import defaultdict |
2 | 1 | import pathlib |
3 | 2 | import xml.etree.ElementTree as ET |
4 | 3 | from datetime import datetime |
@@ -135,44 +134,15 @@ def get_pv_metadata(pvtiffile: str) -> dict: |
135 | 134 | > 1 |
136 | 135 | ): |
137 | 136 |
|
138 | | - z_dicts = [z_pos.attrib for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] |
139 | | - |
140 | | - z_values = list(z_dicts.values()) |
141 | | - |
142 | | - zdata_dictionary = defaultdict(list) |
143 | | - for idx, val in enumerate(z_values): |
144 | | - zdata_dictionary[val].append(idx) |
145 | | - repeating_values = {k: v for k, v in zdata_dictionary.items() if len(v) > 1} |
146 | | - if repeating_values: |
147 | | - idx_to_drop = list(repeating_values.values())[0] |
148 | | - idx_to_drop.sort(reverse=True) |
149 | | - for idx in idx_to_drop: |
150 | | - del z_values[idx] |
151 | | - z_values = [float(num) for num in z_values] |
152 | | - z_min = min(z_values) |
153 | | - z_max = max(z_values) |
154 | | - z_step = z_max / n_depths |
155 | | - z_fields = z_values |
156 | | - assert len(z_fields) == n_depths |
| 137 | + z_repeats = [z_pos.attrib.get("value") for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue")] |
| 138 | + |
| 139 | + z_coordinates = [float(z) for z in z_repeats if z_repeats.count(z) == 1] |
157 | 140 |
|
158 | 141 | else: |
159 | | - z_min = float( |
160 | | - root.findall( |
161 | | - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" |
162 | | - )[0].attrib.get("value") |
163 | | - ) |
164 | | - z_max = float( |
165 | | - root.findall( |
166 | | - ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']" |
167 | | - )[-1].attrib.get("value") |
168 | | - ) |
169 | | - z_step = float( |
170 | | - root.find( |
171 | | - ".//PVStateShard/PVStateValue/[@key='micronsPerPixel']/IndexedValue/[@index='ZAxis']" |
172 | | - ).attrib.get("value") |
173 | | - ) |
174 | | - z_fields = np.arange(z_min, z_max + 1, z_step) |
175 | | - assert z_fields.size == n_depths |
| 142 | + z_coordinates = [z_pos.attrib.get("value") for z_pos in root.findall(".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='0']")] |
| 143 | + |
| 144 | + z_fields = z_coordinates |
| 145 | + assert len(z_fields) == n_depths |
176 | 146 |
|
177 | 147 | metainfo = dict( |
178 | 148 | num_fields=n_fields, |
|
0 commit comments