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

Commitc112e26

Browse files
committed
ENH: Add get_norm_zooms for zooms in mm/s units
1 parentb1bf5e7 commitc112e26

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

‎nibabel/analyze.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ def set_zooms(self, zooms):
710710
pixdims=hdr['pixdim']
711711
pixdims[1:ndim+1]=zooms[:]
712712

713+
defget_norm_zooms(self):
714+
''' Get zooms in mm/s units '''
715+
returnself.get_zooms()
716+
713717
defas_analyze_map(self):
714718
""" Return header as mapping for conversion to Analyze types
715719

‎nibabel/nifti1.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,39 @@ def set_xyzt_units(self, xyz=None, t=None):
16261626
t_code=unit_codes[t]
16271627
self.structarr['xyzt_units']=xyz_code+t_code
16281628

1629+
defget_norm_zooms(self,raise_unknown=False):
1630+
''' Get zooms in mm/s units '''
1631+
raw_zooms=self.get_zooms()
1632+
xyz_zooms=raw_zooms[:3]
1633+
t_zoom=raw_zooms[3]iflen(raw_zooms)>3elseNone
1634+
1635+
xyz_code,t_code=self.get_xyzt_units()
1636+
xyz_msg=t_msg=''
1637+
ifxyz_code=='unknown':
1638+
xyz_msg='Unknown spatial units'
1639+
xyz_code='mm'
1640+
ift_code=='unknown'andt_zoomisnotNone:
1641+
t_msg='Unknown time units'
1642+
t_code='sec'
1643+
ifraise_unknownand (xyz_msg,t_msg)!= ('',''):
1644+
ifxyz_msgandt_msg:
1645+
msg='Unknown spatial and time units'
1646+
else:
1647+
msg=xyz_msgort_msg
1648+
raiseValueError("Error: {}".format(msg))
1649+
ifxyz_msg:
1650+
warnings.warn('{} - assuming mm'.format(xyz_msg))
1651+
ift_msg:
1652+
warnings.warn('{} - assuming sec'.format(t_msg))
1653+
1654+
xyz_factor= {'meter':0.001,'mm':1,'usec':1000}[xyz_code]
1655+
t_factor= {'sec':1,'msec':1000,'usec':1000000}[t_code]
1656+
1657+
xyz_zooms=tuple(np.array(xyz_zooms)/xyz_factor)
1658+
t_zoom= (t_zoom/t_factor,)ift_zoomisnotNoneelse ()
1659+
1660+
returnxyz_zooms+t_zoom
1661+
16291662
def_clean_after_mapping(self):
16301663
''' Set format-specific stuff after converting header from mapping
16311664

‎nibabel/spatialimages.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ def set_zooms(self, zooms):
241241
raiseHeaderDataError('zooms must be positive')
242242
self._zooms=zooms
243243

244+
defget_norm_zooms(self,raise_unknown=False):
245+
''' Get zooms in mm/s units '''
246+
returnself.get_zooms()
247+
244248
defget_base_affine(self):
245249
shape=self.get_data_shape()
246250
zooms=self.get_zooms()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp