Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
effigies wants to merge24 commits intonipy:master
base:master
Choose a base branch
Loading
fromeffigies:enh/norm_units
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
24 commits
Select commitHold shift + click to select a range
3f3b450
ENH: Add get_norm_zooms for zooms in mm/s units
effigiesOct 24, 2017
d26acfb
ENH: Add get_norm_zooms for MGHHeader
effigiesDec 18, 2017
de9323c
ENH: Add set_norm_zooms
effigiesDec 21, 2017
5c30366
FIX: Various unit issues
effigiesDec 21, 2017
4b86d3e
TEST: Test get/set_norm_zooms
effigiesDec 21, 2017
eb1d8ff
TEST: Fix warnings
effigiesDec 21, 2017
6ba8b66
RF: get_norm_zooms -> get_zooms(units="canonical")
effigiesJan 12, 2018
1357a3b
TEST: Update get_zooms tests
effigiesJan 13, 2018
096da88
FIX: Set default t_code even if no t_zoom
effigiesJan 13, 2018
798fc4e
TEST: Add units specification to tests
effigiesFeb 19, 2018
f31aba5
TEST: Add setup/teardown to try to catch warnings properly [WIP]
effigiesFeb 19, 2018
27234c3
TEST: Try using clear_and_catch_warnings
effigiesFeb 19, 2018
8899bc7
RF: Add units parameter to set_zooms
effigiesMar 12, 2018
da54665
TEST: More complete zoom testing, revert unnecessary change
effigiesMar 12, 2018
1620f31
TEST: Improve warning filters, check set_zooms behavior more thoroughly
effigiesMar 12, 2018
5d96f5c
TEST: Explicitly test non-temporal t_units during set_zooms(units="no…
effigiesMar 12, 2018
233f7f0
TEST: Filter warnings for unmodified superclass tests only
effigiesMar 12, 2018
4babf08
ENH: Add units/raise_unknown to MINC/ECAT get_zooms
effigiesMar 12, 2018
6cd83f7
ENH: Validate units parameter in all get/set_zooms
effigiesMar 13, 2018
94cbd0d
FIX: Correct and simplify NIFTI logic
effigiesMar 14, 2018
cfc5abe
TEST: Clear nifti1 module warnings
effigiesMar 20, 2018
3562921
TEST: Check edge cases
effigiesMar 20, 2018
d9199ca
TEST: Add unit to bad set_zoom call
effigiesMar 20, 2018
98e43a0
TEST: Check get_zooms units arg in MINC/ECAT
effigiesMar 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
PrevPrevious commit
NextNext commit
ENH: Validate units parameter in all get/set_zooms
  • Loading branch information
@effigies
effigies committedDec 27, 2022
commit6cd83f7fa0476daaed2a69bfdfeb9ace08b01cfd
4 changes: 4 additions & 0 deletionsnibabel/analyze.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -690,6 +690,8 @@ def get_zooms(self, units='norm', raise_unknown=False):
>>> hdr.get_zooms()
(3.0, 4.0)
"""
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
hdr = self._structarr
dims = hdr['dim']
ndim = dims[0]
Expand All@@ -712,6 +714,8 @@ def set_zooms(self, zooms, units='norm'):
spatial/temporal or as raw values to be interpreted according to
format specification.
"""
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
hdr = self._structarr
dims = hdr['dim']
ndim = dims[0]
Expand Down
2 changes: 2 additions & 0 deletionsnibabel/ecat.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -580,6 +580,8 @@ def get_frame_affine(self, frame=0):

def get_zooms(self, frame=0, units='norm', raise_unknown=False):
"""returns zooms ...pixdims"""
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
subhdr = self.subheaders[frame]
x_zoom = subhdr['x_pixel_size'] * 10
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I wasn't sure whether to make'raw' change this factor to 1.

y_zoom = subhdr['y_pixel_size'] * 10
Expand Down
4 changes: 4 additions & 0 deletionsnibabel/freesurfer/mghformat.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -301,7 +301,11 @@ def set_zooms(self, zooms, units='norm'):
Zooms are specified in normalized units of mm/sec for
spatial/temporal dimensions or as raw values to be stored in
header.

.. _mghformat: https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat#line-82
"""
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

too frequent of a code pattern. In current design I guess the only way to mitigate is to come up withself._check_units(units) to centralize it

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could do something like that.

hdr = self._structarr
zooms = np.asarray(zooms)
ndims = self._ndims()
Expand Down
2 changes: 2 additions & 0 deletionsnibabel/minc1.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -92,6 +92,8 @@ def get_data_shape(self):

def get_zooms(self, units='norm', raise_unknown=False):
""" Get real-world sizes of voxels """
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
# zooms must be positive; but steps in MINC can be negative
return tuple([abs(float(dim.step)) if hasattr(dim, 'step') else 1.0
for dim in self._dims])
Expand Down
6 changes: 3 additions & 3 deletionsnibabel/nifti1.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1810,6 +1810,9 @@ def set_zooms(self, zooms, units=None):
''.format(self.__class__.__name__),
FutureWarning, stacklevel=2)

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)

if isinstance(units, tuple):
Expand All@@ -1822,9 +1825,6 @@ def set_zooms(self, zooms, units=None):
elif len(zooms) > 3 and t_code in ('unknown', 'sec', 'msec', 'usec'):
t_code = 'sec'
self.set_xyzt_units(xyz_code, t_code)
elif units != 'raw':
raise ValueError("`units` parameter must be 'norm', 'raw',"
" or a tuple of unit codes (see set_xyzt_units)")

def _clean_after_mapping(self):
""" Set format-specific stuff after converting header from mapping
Expand Down
4 changes: 4 additions & 0 deletionsnibabel/spatialimages.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,6 +241,8 @@ def get_zooms(self, units='norm', raise_unknown=False):
zooms : tuple
Spacing between voxels along each axis
'''
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
return self._zooms

def set_zooms(self, zooms, units='norm'):
Expand All@@ -255,6 +257,8 @@ def set_zooms(self, zooms, units='norm'):
spatial/temporal or as raw values to be interpreted according to
format specification.
'''
if units not in ('norm', 'raw'):
raise ValueError("`units` parameter must be 'norm' or 'raw'")
zooms = tuple(float(z) for z in zooms)
shape = self.get_data_shape()
ndim = len(shape)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp