Skip to content

Commit 6f5f766

Browse files
authoredJul 13, 2020
Merge pull request #931 from effigies/fix/parrec2nii_t_units
FIX: Use seconds as time units when converting PARRECHeader to Nifti1Header
2 parents 97a0467 + 7759954 commit 6f5f766

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎nibabel/parrec.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,8 @@ def as_analyze_map(self):
775775
self.general_info['exam_date'].replace(' ', ''),
776776
self.general_info['protocol_name']))[:80] # max len
777777
is_fmri = (self.general_info['max_dynamics'] > 1)
778-
t = 'msec' if is_fmri else 'unknown'
778+
# PAR/REC uses msec, but in _calc_zooms we convert to sec
779+
t = 'sec' if is_fmri else 'unknown'
779780
xyzt_units = unit_codes['mm'] + unit_codes[t]
780781
return dict(descr=descr, xyzt_units=xyzt_units) # , pixdim=pixdim)
781782

‎nibabel/tests/test_parrec.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from numpy import array as npa
1010

1111
from .. import load as top_load
12-
from ..nifti1 import Nifti1Image, Nifti1Extension
12+
from ..nifti1 import Nifti1Image, Nifti1Extension, Nifti1Header
1313
from .. import parrec
1414
from ..parrec import (parse_PAR_header, PARRECHeader, PARRECError, vol_numbers,
1515
vol_is_full, PARRECImage, PARRECArrayProxy, exts2pars)
@@ -549,6 +549,18 @@ def test_epi_params():
549549
assert_almost_equal(epi_hdr.get_zooms()[-1], 2.0)
550550

551551

552+
def test_xyzt_unit_conversion():
553+
# Check conversion to NIfTI-like has sensible units
554+
for par_root in ('T2_-interleaved', 'T2_', 'phantom_EPI_asc_CLEAR_2_1'):
555+
epi_par = pjoin(DATA_PATH, par_root + '.PAR')
556+
with open(epi_par, 'rt') as fobj:
557+
epi_hdr = PARRECHeader.from_fileobj(fobj)
558+
nifti_hdr = Nifti1Header.from_header(epi_hdr)
559+
assert len(nifti_hdr.get_data_shape()) == 4
560+
assert_almost_equal(nifti_hdr.get_zooms()[-1], 2.0)
561+
assert nifti_hdr.get_xyzt_units() == ('mm', 'sec')
562+
563+
552564
def test_truncations():
553565
# Test tests for truncation
554566
par = pjoin(DATA_PATH, 'T2_.PAR')

0 commit comments

Comments
 (0)
Please sign in to comment.