Skip to content

ENH: Add get/set_zooms(units='norm') to manipulate zooms in mm/s units #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3f3b450
ENH: Add get_norm_zooms for zooms in mm/s units
effigies Oct 24, 2017
d26acfb
ENH: Add get_norm_zooms for MGHHeader
effigies Dec 18, 2017
de9323c
ENH: Add set_norm_zooms
effigies Dec 21, 2017
5c30366
FIX: Various unit issues
effigies Dec 21, 2017
4b86d3e
TEST: Test get/set_norm_zooms
effigies Dec 21, 2017
eb1d8ff
TEST: Fix warnings
effigies Dec 21, 2017
6ba8b66
RF: get_norm_zooms -> get_zooms(units="canonical")
effigies Jan 12, 2018
1357a3b
TEST: Update get_zooms tests
effigies Jan 13, 2018
096da88
FIX: Set default t_code even if no t_zoom
effigies Jan 13, 2018
798fc4e
TEST: Add units specification to tests
effigies Feb 19, 2018
f31aba5
TEST: Add setup/teardown to try to catch warnings properly [WIP]
effigies Feb 19, 2018
27234c3
TEST: Try using clear_and_catch_warnings
effigies Feb 19, 2018
8899bc7
RF: Add units parameter to set_zooms
effigies Mar 12, 2018
da54665
TEST: More complete zoom testing, revert unnecessary change
effigies Mar 12, 2018
1620f31
TEST: Improve warning filters, check set_zooms behavior more thoroughly
effigies Mar 12, 2018
5d96f5c
TEST: Explicitly test non-temporal t_units during set_zooms(units="no…
effigies Mar 12, 2018
233f7f0
TEST: Filter warnings for unmodified superclass tests only
effigies Mar 12, 2018
4babf08
ENH: Add units/raise_unknown to MINC/ECAT get_zooms
effigies Mar 12, 2018
6cd83f7
ENH: Validate units parameter in all get/set_zooms
effigies Mar 13, 2018
94cbd0d
FIX: Correct and simplify NIFTI logic
effigies Mar 14, 2018
cfc5abe
TEST: Clear nifti1 module warnings
effigies Mar 20, 2018
3562921
TEST: Check edge cases
effigies Mar 20, 2018
d9199ca
TEST: Add unit to bad set_zoom call
effigies Mar 20, 2018
98e43a0
TEST: Check get_zooms units arg in MINC/ECAT
effigies Mar 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
FIX: Correct and simplify NIFTI logic
  • Loading branch information
effigies committed Dec 27, 2022
commit 94cbd0dfd3ac02b4e57fa76f2a0991177482aa59
16 changes: 7 additions & 9 deletions nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,22 +1726,22 @@ def get_zooms(self, units=None, raise_unknown=False):
raise ValueError("`units` parameter must be 'norm' or 'raw'")

xyz_zooms = raw_zooms[:3]
t_zoom = raw_zooms[3] if len(raw_zooms) > 3 else None
t_zoom = raw_zooms[3:4] # Tuple of length 0 or 1

xyz_code, t_code = self.get_xyzt_units()
xyz_msg = t_msg = ''
if xyz_code == 'unknown':
xyz_msg = 'Unknown spatial units'
xyz_code = 'mm'
if t_zoom is not None:
if t_zoom:
if t_code == 'unknown':
t_msg = 'Unknown time units'
t_code = 'sec'
elif t_code in ('hz', 'ppm', 'rads'):
t_msg = 'Unconvertible temporal units: {}'.format(t_code)

if raise_unknown and (xyz_msg, t_msg) != ('', ''):
if xyz_msg and t_msg:
if raise_unknown and (xyz_msg or t_msg.startswith('Unknown')):
if xyz_msg and t_msg.startswith('Unknown'):
msg = 'Unknown spatial and time units'
else:
msg = xyz_msg or t_msg
Expand All @@ -1757,12 +1757,10 @@ def get_zooms(self, units=None, raise_unknown=False):
xyz_factor = {'meter': 1000, 'mm': 1, 'micron': 0.001}[xyz_code]
xyz_zooms = tuple(np.array(xyz_zooms) * xyz_factor)

if t_zoom is not None:
if t_zoom:
t_factor = {'sec': 1, 'msec': 0.001, 'usec': 0.000001,
'hz': 1, 'ppm': 1, 'rads': 1}[t_code]
t_zoom = (t_zoom * t_factor,)
else:
t_zoom = ()
t_zoom = (t_zoom[0] * t_factor,)

return xyz_zooms + t_zoom

Expand Down Expand Up @@ -1813,7 +1811,7 @@ def set_zooms(self, zooms, units=None):
if units not in ('norm', 'raw') and not isinstance(units, tuple):
raise ValueError("`units` parameter must be 'norm', 'raw',"
" or a tuple of unit codes (see set_xyzt_units)")
super(Nifti1Header, self).set_zooms(zooms, units=units)
super(Nifti1Header, self).set_zooms(zooms, units='raw')

if isinstance(units, tuple):
self.set_xyzt_units(*units)
Expand Down