@@ -115,7 +115,7 @@ def get_pv_metadata(pvtiffile: str) -> dict:
115115
116116 else :
117117
118- bidirection_z = root .find (".//Sequence" ).attrib .get ("bidirectionalZ" ) == ' True'
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 = [
@@ -124,25 +124,31 @@ def get_pv_metadata(pvtiffile: str) -> dict:
124124 ]
125125 n_depths = len (set (planes ))
126126
127- # find z_depths controller if there is more than 1.
128- if (
129- len (
130- root .findall (
131- ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue"
127+ # find z-axis controller if there is more than 1.
128+ z_controllers = root .findall (
129+ ".//Sequence/[@cycle='1']/Frame/[@index='1']/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue"
130+ )
131+ if len (z_controllers ) > 1 :
132+ z_repeats = [
133+ z .attrib .get ("value" )
134+ for z in root .findall (
135+ ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue"
132136 )
133- )
134- > 1
135- ):
137+ ]
136138
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 ]
139+ z_fields = [float (z ) for z in z_repeats if z_repeats .count (z ) == 1 ]
140140
141141 else :
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']" )]
142+ z_fields = [
143+ z .attrib .get ("value" )
144+ for z in root .findall (
145+ ".//Sequence/[@cycle='1']/Frame/PVStateShard/PVStateValue/[@key='positionCurrent']/SubindexedValues/[@index='ZAxis']/SubindexedValue/[@subindex='0']"
146+ )
147+ ]
143148
144- z_fields = z_coordinates
145- assert len (z_fields ) == n_depths
149+ assert (
150+ len (z_fields ) == n_depths
151+ ), "Number of z fields does not match number of depths."
146152
147153 metainfo = dict (
148154 num_fields = n_fields ,
0 commit comments