@@ -1726,22 +1726,22 @@ def get_zooms(self, units=None, raise_unknown=False):
1726
1726
raise ValueError ("`units` parameter must be 'norm' or 'raw'" )
1727
1727
1728
1728
xyz_zooms = raw_zooms [:3 ]
1729
- t_zoom = raw_zooms [3 ] if len ( raw_zooms ) > 3 else None
1729
+ t_zoom = raw_zooms [3 : 4 ] # Tuple of length 0 or 1
1730
1730
1731
1731
xyz_code , t_code = self .get_xyzt_units ()
1732
1732
xyz_msg = t_msg = ''
1733
1733
if xyz_code == 'unknown' :
1734
1734
xyz_msg = 'Unknown spatial units'
1735
1735
xyz_code = 'mm'
1736
- if t_zoom is not None :
1736
+ if t_zoom :
1737
1737
if t_code == 'unknown' :
1738
1738
t_msg = 'Unknown time units'
1739
1739
t_code = 'sec'
1740
1740
elif t_code in ('hz' , 'ppm' , 'rads' ):
1741
1741
t_msg = 'Unconvertible temporal units: {}' .format (t_code )
1742
1742
1743
- if raise_unknown and (xyz_msg , t_msg ) != ( '' , '' ):
1744
- if xyz_msg and t_msg :
1743
+ if raise_unknown and (xyz_msg or t_msg . startswith ( 'Unknown' ) ):
1744
+ if xyz_msg and t_msg . startswith ( 'Unknown' ) :
1745
1745
msg = 'Unknown spatial and time units'
1746
1746
else :
1747
1747
msg = xyz_msg or t_msg
@@ -1757,12 +1757,10 @@ def get_zooms(self, units=None, raise_unknown=False):
1757
1757
xyz_factor = {'meter' : 1000 , 'mm' : 1 , 'micron' : 0.001 }[xyz_code ]
1758
1758
xyz_zooms = tuple (np .array (xyz_zooms ) * xyz_factor )
1759
1759
1760
- if t_zoom is not None :
1760
+ if t_zoom :
1761
1761
t_factor = {'sec' : 1 , 'msec' : 0.001 , 'usec' : 0.000001 ,
1762
1762
'hz' : 1 , 'ppm' : 1 , 'rads' : 1 }[t_code ]
1763
- t_zoom = (t_zoom * t_factor ,)
1764
- else :
1765
- t_zoom = ()
1763
+ t_zoom = (t_zoom [0 ] * t_factor ,)
1766
1764
1767
1765
return xyz_zooms + t_zoom
1768
1766
@@ -1813,7 +1811,7 @@ def set_zooms(self, zooms, units=None):
1813
1811
if units not in ('norm' , 'raw' ) and not isinstance (units , tuple ):
1814
1812
raise ValueError ("`units` parameter must be 'norm', 'raw',"
1815
1813
" or a tuple of unit codes (see set_xyzt_units)" )
1816
- super (Nifti1Header , self ).set_zooms (zooms , units = units )
1814
+ super (Nifti1Header , self ).set_zooms (zooms , units = 'raw' )
1817
1815
1818
1816
if isinstance (units , tuple ):
1819
1817
self .set_xyzt_units (* units )
0 commit comments