Skip to content

Commit 9543139

Browse files
committed
Update code from code review
1 parent 32861b7 commit 9543139

File tree

1 file changed

+7
-37
lines changed

1 file changed

+7
-37
lines changed

element_interface/prairieviewreader.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import defaultdict
21
import pathlib
32
import xml.etree.ElementTree as ET
43
from datetime import datetime
@@ -135,44 +134,15 @@ def get_pv_metadata(pvtiffile: str) -> dict:
135134
> 1
136135
):
137136

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]
157140

158141
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
176146

177147
metainfo = dict(
178148
num_fields=n_fields,

0 commit comments

Comments
 (0)