@@ -1685,22 +1685,22 @@ def get_zooms(self, units=None, raise_unknown=False):
1685
1685
raise ValueError ("`units` parameter must be 'norm' or 'raw'" )
1686
1686
1687
1687
xyz_zooms = raw_zooms [:3 ]
1688
- t_zoom = raw_zooms [3 ] if len ( raw_zooms ) > 3 else None
1688
+ t_zoom = raw_zooms [3 : 4 ] # Tuple of length 0 or 1
1689
1689
1690
1690
xyz_code , t_code = self .get_xyzt_units ()
1691
1691
xyz_msg = t_msg = ''
1692
1692
if xyz_code == 'unknown' :
1693
1693
xyz_msg = 'Unknown spatial units'
1694
1694
xyz_code = 'mm'
1695
- if t_zoom is not None :
1695
+ if t_zoom :
1696
1696
if t_code == 'unknown' :
1697
1697
t_msg = 'Unknown time units'
1698
1698
t_code = 'sec'
1699
1699
elif t_code in ('hz' , 'ppm' , 'rads' ):
1700
1700
t_msg = 'Unconvertible temporal units: {}' .format (t_code )
1701
1701
1702
- if raise_unknown and (xyz_msg , t_msg ) != ( '' , '' ):
1703
- if xyz_msg and t_msg :
1702
+ if raise_unknown and (xyz_msg or t_msg . startswith ( 'Unknown' ) ):
1703
+ if xyz_msg and t_msg . startswith ( 'Unknown' ) :
1704
1704
msg = 'Unknown spatial and time units'
1705
1705
else :
1706
1706
msg = xyz_msg or t_msg
@@ -1716,12 +1716,10 @@ def get_zooms(self, units=None, raise_unknown=False):
1716
1716
xyz_factor = {'meter' : 1000 , 'mm' : 1 , 'micron' : 0.001 }[xyz_code ]
1717
1717
xyz_zooms = tuple (np .array (xyz_zooms ) * xyz_factor )
1718
1718
1719
- if t_zoom is not None :
1719
+ if t_zoom :
1720
1720
t_factor = {'sec' : 1 , 'msec' : 0.001 , 'usec' : 0.000001 ,
1721
1721
'hz' : 1 , 'ppm' : 1 , 'rads' : 1 }[t_code ]
1722
- t_zoom = (t_zoom * t_factor ,)
1723
- else :
1724
- t_zoom = ()
1722
+ t_zoom = (t_zoom [0 ] * t_factor ,)
1725
1723
1726
1724
return xyz_zooms + t_zoom
1727
1725
@@ -1772,7 +1770,7 @@ def set_zooms(self, zooms, units=None):
1772
1770
if units not in ('norm' , 'raw' ) and not isinstance (units , tuple ):
1773
1771
raise ValueError ("`units` parameter must be 'norm', 'raw',"
1774
1772
" or a tuple of unit codes (see set_xyzt_units)" )
1775
- super (Nifti1Header , self ).set_zooms (zooms , units = units )
1773
+ super (Nifti1Header , self ).set_zooms (zooms , units = 'raw' )
1776
1774
1777
1775
if isinstance (units , tuple ):
1778
1776
self .set_xyzt_units (* units )
0 commit comments