@@ -1685,22 +1685,22 @@ def get_zooms(self, units=None, raise_unknown=False):
16851685 raise ValueError ("`units` parameter must be 'norm' or 'raw'" )
16861686
16871687 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
16891689
16901690 xyz_code , t_code = self .get_xyzt_units ()
16911691 xyz_msg = t_msg = ''
16921692 if xyz_code == 'unknown' :
16931693 xyz_msg = 'Unknown spatial units'
16941694 xyz_code = 'mm'
1695- if t_zoom is not None :
1695+ if t_zoom :
16961696 if t_code == 'unknown' :
16971697 t_msg = 'Unknown time units'
16981698 t_code = 'sec'
16991699 elif t_code in ('hz' , 'ppm' , 'rads' ):
17001700 t_msg = 'Unconvertible temporal units: {}' .format (t_code )
17011701
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' ) :
17041704 msg = 'Unknown spatial and time units'
17051705 else :
17061706 msg = xyz_msg or t_msg
@@ -1716,12 +1716,10 @@ def get_zooms(self, units=None, raise_unknown=False):
17161716 xyz_factor = {'meter' : 1000 , 'mm' : 1 , 'micron' : 0.001 }[xyz_code ]
17171717 xyz_zooms = tuple (np .array (xyz_zooms ) * xyz_factor )
17181718
1719- if t_zoom is not None :
1719+ if t_zoom :
17201720 t_factor = {'sec' : 1 , 'msec' : 0.001 , 'usec' : 0.000001 ,
17211721 '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 ,)
17251723
17261724 return xyz_zooms + t_zoom
17271725
@@ -1772,7 +1770,7 @@ def set_zooms(self, zooms, units=None):
17721770 if units not in ('norm' , 'raw' ) and not isinstance (units , tuple ):
17731771 raise ValueError ("`units` parameter must be 'norm', 'raw',"
17741772 " 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' )
17761774
17771775 if isinstance (units , tuple ):
17781776 self .set_xyzt_units (* units )
0 commit comments