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