@@ -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 ,
0 commit comments