Skip to content

Commit 92aa66c

Browse files
committed
Merge pull request #312 from matthew-brett/fix-par-parsing
MRG: fix and test for bug in PAR header reading Fix for reading empty parrec fields, floating point window values. Add test. Closes #311
2 parents 2e575eb + 41e9076 commit 92aa66c

File tree

5 files changed

+207
-3
lines changed

5 files changed

+207
-3
lines changed

COPYING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,8 @@ The files::
204204

205205
are from https://github.com/yarikoptic/nitest-balls1, also released under the
206206
the PDDL version 1.0 available at http://opendatacommons.org/licenses/pddl/1.0/
207+
208+
nibabel/nibabel/tests/data/umass_anonymized.PAR
209+
210+
is courtesy of the University of Massachusetts Medical School, also released
211+
under the PDDL.

nibabel/parrec.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@
185185
('rescale intercept', float),
186186
('rescale slope', float),
187187
('scale slope', float),
188-
('window center', int,),
189-
('window width', int,),
188+
# Window center, width recorded as integer but can be float
189+
('window center', float,),
190+
('window width', float,),
190191
('image angulation', float, (3,)),
191192
('image offcentre', float, (3,)),
192193
('slice thickness', float),
@@ -244,6 +245,9 @@ class PARRECError(Exception):
244245
pass
245246

246247

248+
# Value after colon may be absent
249+
GEN_RE = re.compile(r".\s+(.*?)\s*:\s*(.*)")
250+
247251
def _split_header(fobj):
248252
""" Split header into `version`, `gen_dict`, `image_lines` """
249253
version = None
@@ -276,7 +280,6 @@ def _split_header(fobj):
276280
return version, gen_dict, image_lines
277281

278282

279-
GEN_RE = re.compile(r".\s+(.*?)\s*:\s+(.*)")
280283

281284

282285
def _process_gen_dict(gen_dict):

nibabel/tests/data/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ Nibabel data files
66

77
``phantom_truncated.PAR`` is a slightly edited copy of
88
``phantom_EPI_asc_CLEAR_2_1.PAR``.
9+
10+
``umass_anonymized.PAR`` courtesy of Github user ``cccbauer``, data from the
11+
University of Massachusetts medical school.

0 commit comments

Comments
 (0)