@@ -1726,22 +1726,22 @@ def get_zooms(self, units=None, raise_unknown=False):
17261726 raise ValueError ("`units` parameter must be 'norm' or 'raw'" )
17271727
17281728 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
17301730
17311731 xyz_code , t_code = self .get_xyzt_units ()
17321732 xyz_msg = t_msg = ''
17331733 if xyz_code == 'unknown' :
17341734 xyz_msg = 'Unknown spatial units'
17351735 xyz_code = 'mm'
1736- if t_zoom is not None :
1736+ if t_zoom :
17371737 if t_code == 'unknown' :
17381738 t_msg = 'Unknown time units'
17391739 t_code = 'sec'
17401740 elif t_code in ('hz' , 'ppm' , 'rads' ):
17411741 t_msg = 'Unconvertible temporal units: {}' .format (t_code )
17421742
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' ) :
17451745 msg = 'Unknown spatial and time units'
17461746 else :
17471747 msg = xyz_msg or t_msg
@@ -1757,12 +1757,10 @@ def get_zooms(self, units=None, raise_unknown=False):
17571757 xyz_factor = {'meter' : 1000 , 'mm' : 1 , 'micron' : 0.001 }[xyz_code ]
17581758 xyz_zooms = tuple (np .array (xyz_zooms ) * xyz_factor )
17591759
1760- if t_zoom is not None :
1760+ if t_zoom :
17611761 t_factor = {'sec' : 1 , 'msec' : 0.001 , 'usec' : 0.000001 ,
17621762 '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 ,)
17661764
17671765 return xyz_zooms + t_zoom
17681766
@@ -1813,7 +1811,7 @@ def set_zooms(self, zooms, units=None):
18131811 if units not in ('norm' , 'raw' ) and not isinstance (units , tuple ):
18141812 raise ValueError ("`units` parameter must be 'norm', 'raw',"
18151813 " 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' )
18171815
18181816 if isinstance (units , tuple ):
18191817 self .set_xyzt_units (* units )
0 commit comments