Skip to content

Commit 068b749

Browse files
authored
Merge pull request #78 from kushalbakshi/main
Fix multiple z device ingestion in `prairieviewreader.py`
2 parents f4312b3 + 215264f commit 068b749

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# User data
22
.DS_Store
33
temp*
4+
user_data/
45

56
# Byte-compiled / optimized / DLL files
67
__pycache__/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
44
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.
55

6+
## [0.5.1] - 2023-03-15
7+
8+
+ Fix - ingestion routine for multiple Z devices in `prairieviewreader.py`.
9+
610
## [0.5.0] - 2023-01-09
711

812
+ Remove - `recursive_search` function
@@ -53,6 +57,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
5357

5458
+ Add - Readers for: `ScanImage`, `Suite2p`, `CaImAn`.
5559

60+
[0.5.1]: https://github.com/datajoint/element-interface/releases/tag/0.5.1
5661
[0.5.0]: https://github.com/datajoint/element-interface/releases/tag/0.5.0
5762
[0.4.2]: https://github.com/datajoint/element-interface/releases/tag/0.4.2
5863
[0.4.1]: https://github.com/datajoint/element-interface/releases/tag/0.4.1

element_interface/prairieviewreader.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_pv_metadata(pvtiffile: str) -> dict:
4242
)
4343

4444
bidirectional_scan = False # Does not support bidirectional
45-
roi = 1
45+
roi = 0
4646
n_fields = 1 # Always contains 1 field
4747
record_start_time = root.find(".//Sequence/[@cycle='1']").attrib.get("time")
4848

@@ -115,31 +115,52 @@ def get_pv_metadata(pvtiffile: str) -> dict:
115115

116116
else:
117117

118-
bidirection_z = bool(root.find(".//Sequence").attrib.get("bidirectionalZ"))
118+
bidirection_z = root.find(".//Sequence").attrib.get("bidirectionalZ") == "True"
119119

120120
# One "Frame" per depth. Gets number of frames in first sequence
121121
planes = [
122122
int(plane.attrib.get("index"))
123123
for plane in root.findall(".//Sequence/[@cycle='1']/Frame")
124124
]
125125
n_depths = len(set(planes))
126-
z_min = float(
127-
root.findall(
128-
".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']"
129-
)[0].attrib.get("value")
130-
)
131-
z_max = float(
132-
root.findall(
133-
".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/SubindexedValue/[@subindex='0']"
134-
)[-1].attrib.get("value")
135-
)
136-
z_step = float(
137-
root.find(
138-
".//PVStateShard/PVStateValue/[@key='micronsPerPixel']/IndexedValue/[@index='ZAxis']"
139-
).attrib.get("value")
126+
127+
z_controllers = root.findall(
128+
".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue"
140129
)
141-
z_fields = np.arange(z_min, z_max + 1, z_step)
142-
assert z_fields.size == n_depths
130+
if len(z_controllers) > 1:
131+
132+
z_repeats = []
133+
for controller in root.findall(
134+
".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/"):
135+
z_repeats.append(
136+
[
137+
float(z.attrib.get("value"))
138+
for z in root.findall(
139+
".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='{0}']".format(
140+
controller.attrib.get("subindex")
141+
)
142+
)
143+
]
144+
)
145+
146+
147+
controller_assert = [not all(z == z_controller[0] for z in z_controller) for z_controller in z_repeats]
148+
149+
assert sum(controller_assert)==1, "Multiple controllers changing z depth is not supported"
150+
151+
z_fields = z_repeats[controller_assert.index(True)]
152+
153+
else:
154+
z_fields = [
155+
z.attrib.get("value")
156+
for z in root.findall(
157+
".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='0']"
158+
)
159+
]
160+
161+
assert (
162+
len(z_fields) == n_depths
163+
), "Number of z fields does not match number of depths."
143164

144165
metainfo = dict(
145166
num_fields=n_fields,

element_interface/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Package metadata"""
22

3-
__version__ = "0.5.0"
3+
__version__ = "0.5.1"

0 commit comments

Comments
 (0)