Skip to content

FIX: Use seconds as time units when converting PARRECHeader to Nifti1Header #931

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

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion nibabel/parrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ def as_analyze_map(self):
self.general_info['exam_date'].replace(' ', ''),
self.general_info['protocol_name']))[:80] # max len
is_fmri = (self.general_info['max_dynamics'] > 1)
t = 'msec' if is_fmri else 'unknown'
# PAR/REC uses msec, but in _calc_zooms we convert to sec
t = 'sec' if is_fmri else 'unknown'
xyzt_units = unit_codes['mm'] + unit_codes[t]
return dict(descr=descr, xyzt_units=xyzt_units) # , pixdim=pixdim)

Expand Down
14 changes: 13 additions & 1 deletion nibabel/tests/test_parrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from numpy import array as npa

from .. import load as top_load
from ..nifti1 import Nifti1Image, Nifti1Extension
from ..nifti1 import Nifti1Image, Nifti1Extension, Nifti1Header
from .. import parrec
from ..parrec import (parse_PAR_header, PARRECHeader, PARRECError, vol_numbers,
vol_is_full, PARRECImage, PARRECArrayProxy, exts2pars)
Expand Down Expand Up @@ -549,6 +549,18 @@ def test_epi_params():
assert_almost_equal(epi_hdr.get_zooms()[-1], 2.0)


def test_xyzt_unit_conversion():
# Check conversion to NIfTI-like has sensible units
for par_root in ('T2_-interleaved', 'T2_', 'phantom_EPI_asc_CLEAR_2_1'):
epi_par = pjoin(DATA_PATH, par_root + '.PAR')
with open(epi_par, 'rt') as fobj:
epi_hdr = PARRECHeader.from_fileobj(fobj)
nifti_hdr = Nifti1Header.from_header(epi_hdr)
assert len(nifti_hdr.get_data_shape()) == 4
assert_almost_equal(nifti_hdr.get_zooms()[-1], 2.0)
assert nifti_hdr.get_xyzt_units() == ('mm', 'sec')


def test_truncations():
# Test tests for truncation
par = pjoin(DATA_PATH, 'T2_.PAR')
Expand Down