Skip to content

Commit 9b23a32

Browse files
Merge pull request #507 from grlee77/parrec_keys
MRG: support alternative header field name variants in .PAR files This is a workaround for the alternative header naming variants observed in #505. I modified one of the existing .PAR files. I just truncated it and changed 4 header lines to have the entries from the .PAR file in #505. We can swap the file out for that other actual .par file prior to merging if the license terms permit.
2 parents 27b6607 + 47a8d6a commit 9b23a32

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

nibabel/parrec.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@
206206
'Max. number of gradient orients': ('max_gradient_orient', int),
207207
# Line below added for par / rec version > 4.1
208208
'Number of label types <0=no ASL>': ('nr_label_types', int),
209+
# The following are duplicates of the above fields, but with slightly
210+
# different abbreviation, spelling, or capatilization. Both variants have
211+
# been observed in the wild in V4.2 PAR files:
212+
# https://github.com/nipy/nibabel/issues/505
213+
'Series_data_type': ('series_type',),
214+
'Patient Position': ('patient_position',),
215+
'Repetition time [msec]': ('repetition_time', float, None),
216+
'Diffusion echo time [msec]': ('diffusion_echo_time', float),
209217
}
210218

211219
# Image information as coded into a numpy structured array
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# === DATA DESCRIPTION FILE ======================================================
2+
#
3+
# CAUTION - Investigational device.
4+
# Limited by Federal Law to investigational use.
5+
#
6+
# Dataset name: E:\\Export\phantom_EPI_asc_CLEAR_2_1
7+
#
8+
# CLINICAL TRYOUT Research image export tool V4.2
9+
#
10+
# === GENERAL INFORMATION ========================================================
11+
#
12+
. Patient name : phantom
13+
. Examination name : Konvertertest
14+
. Protocol name : EPI_asc CLEAR
15+
. Examination date/time : 2014.02.14 / 09:00:57
16+
. Series_data_type : Image MRSERIES
17+
. Acquisition nr : 2
18+
. Reconstruction nr : 1
19+
. Scan Duration [sec] : 14
20+
. Max. number of cardiac phases : 1
21+
. Max. number of echoes : 1
22+
. Max. number of slices/locations : 9
23+
. Max. number of dynamics : 3
24+
. Max. number of mixes : 1
25+
. Patient Position : HFS
26+
. Preparation direction : Anterior-Posterior
27+
. Technique : FEEPI
28+
. Scan resolution (x, y) : 64 39
29+
. Scan mode : MS
30+
. Repetition time [msec] : 21225.76
31+
. FOV (ap,fh,rl) [mm] : 240.000 70.000 240.000
32+
. Water Fat shift [pixels] : 11.050
33+
. Angulation midslice(ap,fh,rl)[degr]: -13.265 0.000 0.000
34+
. Off Centre midslice(ap,fh,rl) [mm] : 2.508 30.339 -16.032
35+
. Flow compensation <0=no 1=yes> ? : 0
36+
. Presaturation <0=no 1=yes> ? : 0
37+
. Phase encoding velocity [cm/sec] : 0.000000 0.000000 0.000000
38+
. MTC <0=no 1=yes> ? : 0
39+
. SPIR <0=no 1=yes> ? : 1
40+
. EPI factor <0,1=no EPI> : 39
41+
. Dynamic scan <0=no 1=yes> ? : 1
42+
. Diffusion <0=no 1=yes> ? : 0
43+
. Diffusion echo time [msec] : 0.00
44+
. Max. number of diffusion values : 1
45+
. Max. number of gradient orients : 1
46+
#
47+
# === PIXEL VALUES =============================================================
48+
# PV = pixel value in REC file, FP = floating point value, DV = displayed value on console
49+
# RS = rescale slope, RI = rescale intercept, SS = scale slope
50+
# DV = PV * RS + RI FP = DV / (RS * SS)
51+
#
52+
# === IMAGE INFORMATION DEFINITION =============================================
53+
# The rest of this file contains ONE line per image, this line contains the following information:
54+
#
55+
# slice number (integer)
56+
# echo number (integer)
57+
# dynamic scan number (integer)
58+
# cardiac phase number (integer)
59+
# image_type_mr (integer)
60+
# scanning sequence (integer)
61+
# index in REC file (in images) (integer)
62+
# image pixel size (in bits) (integer)
63+
# scan percentage (integer)
64+
# recon resolution (x y) (2*integer)
65+
# rescale intercept (float)
66+
# rescale slope (float)
67+
# scale slope (float)
68+
# window center (integer)
69+
# window width (integer)
70+
# image angulation (ap,fh,rl in degrees ) (3*float)
71+
# image offcentre (ap,fh,rl in mm ) (3*float)
72+
# slice thickness (in mm ) (float)
73+
# slice gap (in mm ) (float)
74+
# image_display_orientation (integer)
75+
# slice orientation ( TRA/SAG/COR ) (integer)
76+
# fmri_status_indication (integer)
77+
# image_type_ed_es (end diast/end syst) (integer)
78+
# pixel spacing (x,y) (in mm) (2*float)
79+
# echo_time (float)
80+
# dyn_scan_begin_time (float)
81+
# trigger_time (float)
82+
# diffusion_b_factor (float)
83+
# number of averages (integer)
84+
# image_flip_angle (in degrees) (float)
85+
# cardiac frequency (bpm) (integer)
86+
# minimum RR-interval (in ms) (integer)
87+
# maximum RR-interval (in ms) (integer)
88+
# TURBO factor <0=no turbo> (integer)
89+
# Inversion delay (in ms) (float)
90+
# diffusion b value number (imagekey!) (integer)
91+
# gradient orientation number (imagekey!) (integer)
92+
# contrast type (string)
93+
# diffusion anisotropy type (string)
94+
# diffusion (ap, fh, rl) (3*float)
95+
# label type (ASL) (imagekey!) (integer)
96+
#
97+
# === IMAGE INFORMATION ==========================================================
98+
# sl ec dyn ph ty idx pix scan% rec size (re)scale window angulation offcentre thick gap info spacing echo dtime ttime diff avg flip freq RR-int turbo delay b grad cont anis diffusion L.ty
99+
100+
1 1 1 1 0 2 0 16 62 64 64 0.00000 1.29035 4.28404e-003 1070 1860 -13.26 -0.00 -0.00 2.51 -0.81 -8.69 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
101+
2 1 1 1 0 2 1 16 62 64 64 0.00000 1.29035 4.28404e-003 1122 1951 -13.26 -0.00 -0.00 2.51 6.98 -10.53 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
102+
3 1 1 1 0 2 2 16 62 64 64 0.00000 1.29035 4.28404e-003 1137 1977 -13.26 -0.00 -0.00 2.51 14.77 -12.36 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
103+
4 1 1 1 0 2 3 16 62 64 64 0.00000 1.29035 4.28404e-003 1217 2116 -13.26 -0.00 -0.00 2.51 22.55 -14.20 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
104+
5 1 1 1 0 2 4 16 62 64 64 0.00000 1.29035 4.28404e-003 1216 2113 -13.26 -0.00 -0.00 2.51 30.34 -16.03 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
105+
6 1 1 1 0 2 5 16 62 64 64 0.00000 1.29035 4.28404e-003 1141 1983 -13.26 -0.00 -0.00 2.51 38.13 -17.87 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
106+
7 1 1 1 0 2 6 16 62 64 64 0.00000 1.29035 4.28404e-003 1119 1945 -13.26 -0.00 -0.00 2.51 45.91 -19.70 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
107+
8 1 1 1 0 2 7 16 62 64 64 0.00000 1.29035 4.28404e-003 1097 1907 -13.26 -0.00 -0.00 2.51 53.70 -21.54 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
108+
9 1 1 1 0 2 8 16 62 64 64 0.00000 1.29035 4.28404e-003 1146 1991 -13.26 -0.00 -0.00 2.51 61.49 -23.37 6.000 2.000 0 1 0 2 3.750 3.750 30.00 0.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
109+
1 1 2 1 0 2 9 16 62 64 64 0.00000 1.29035 4.28404e-003 1071 1863 -13.26 -0.00 -0.00 2.51 -0.81 -8.69 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
110+
2 1 2 1 0 2 10 16 62 64 64 0.00000 1.29035 4.28404e-003 1123 1953 -13.26 -0.00 -0.00 2.51 6.98 -10.53 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
111+
3 1 2 1 0 2 11 16 62 64 64 0.00000 1.29035 4.28404e-003 1135 1973 -13.26 -0.00 -0.00 2.51 14.77 -12.36 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
112+
4 1 2 1 0 2 12 16 62 64 64 0.00000 1.29035 4.28404e-003 1209 2101 -13.26 -0.00 -0.00 2.51 22.55 -14.20 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
113+
5 1 2 1 0 2 13 16 62 64 64 0.00000 1.29035 4.28404e-003 1215 2113 -13.26 -0.00 -0.00 2.51 30.34 -16.03 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
114+
6 1 2 1 0 2 14 16 62 64 64 0.00000 1.29035 4.28404e-003 1145 1990 -13.26 -0.00 -0.00 2.51 38.13 -17.87 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
115+
7 1 2 1 0 2 15 16 62 64 64 0.00000 1.29035 4.28404e-003 1119 1945 -13.26 -0.00 -0.00 2.51 45.91 -19.70 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
116+
8 1 2 1 0 2 16 16 62 64 64 0.00000 1.29035 4.28404e-003 1093 1899 -13.26 -0.00 -0.00 2.51 53.70 -21.54 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
117+
9 1 2 1 0 2 17 16 62 64 64 0.00000 1.29035 4.28404e-003 1150 1999 -13.26 -0.00 -0.00 2.51 61.49 -23.37 6.000 2.000 0 1 0 2 3.750 3.750 30.00 2.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
118+
1 1 3 1 0 2 18 16 62 64 64 0.00000 1.29035 4.28404e-003 1070 1860 -13.26 -0.00 -0.00 2.51 -0.81 -8.69 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
119+
2 1 3 1 0 2 19 16 62 64 64 0.00000 1.29035 4.28404e-003 1125 1955 -13.26 -0.00 -0.00 2.51 6.98 -10.53 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
120+
3 1 3 1 0 2 20 16 62 64 64 0.00000 1.29035 4.28404e-003 1135 1973 -13.26 -0.00 -0.00 2.51 14.77 -12.36 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
121+
4 1 3 1 0 2 21 16 62 64 64 0.00000 1.29035 4.28404e-003 1211 2105 -13.26 -0.00 -0.00 2.51 22.55 -14.20 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
122+
5 1 3 1 0 2 22 16 62 64 64 0.00000 1.29035 4.28404e-003 1218 2118 -13.26 -0.00 -0.00 2.51 30.34 -16.03 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
123+
6 1 3 1 0 2 23 16 62 64 64 0.00000 1.29035 4.28404e-003 1143 1987 -13.26 -0.00 -0.00 2.51 38.13 -17.87 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
124+
7 1 3 1 0 2 24 16 62 64 64 0.00000 1.29035 4.28404e-003 1120 1947 -13.26 -0.00 -0.00 2.51 45.91 -19.70 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
125+
8 1 3 1 0 2 25 16 62 64 64 0.00000 1.29035 4.28404e-003 1093 1901 -13.26 -0.00 -0.00 2.51 53.70 -21.54 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
126+
9 1 3 1 0 2 26 16 62 64 64 0.00000 1.29035 4.28404e-003 1151 2001 -13.26 -0.00 -0.00 2.51 61.49 -23.37 6.000 2.000 0 1 0 2 3.750 3.750 30.00 4.00 0.00 0.00 0 90.00 0 0 0 39 0.0 1 1 8 0 0.000 0.000 0.000 1
127+
128+
# === END OF DATA DESCRIPTION FILE ===============================================

nibabel/tests/test_parrec.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
# Fake varying scaling
5050
VARY_PAR = pjoin(DATA_PATH, 'phantom_varscale.PAR')
5151
VARY_REC = pjoin(DATA_PATH, 'phantom_varscale.REC')
52+
# V4.2 PAR with variant field names in the header
53+
VARIANT_PAR = pjoin(DATA_PATH, 'variant_v4_2_header.PAR')
5254
# Affine as we determined it mid-2014
5355
AN_OLD_AFFINE = np.array(
5456
[[-3.64994708, 0., 1.83564171, 123.66276611],
@@ -829,3 +831,15 @@ def test_dualTR():
829831
expected_TRs)
830832
# zoom on 4th dimensions is the first TR (in seconds)
831833
assert_equal(dualTR_hdr.get_zooms()[3], expected_TRs[0]/1000)
834+
835+
836+
def test_alternative_header_field_names():
837+
# some V4.2 files had variant spellings for some of the fields in the
838+
# header. This test reads one such file and verifies that the fields with
839+
# the alternate spelling were read.
840+
with ImageOpener(VARIANT_PAR, 'rt') as _fobj:
841+
HDR_INFO, HDR_DEFS = parse_PAR_header(_fobj)
842+
assert_equal(HDR_INFO['series_type'], 'Image MRSERIES')
843+
assert_equal(HDR_INFO['diffusion_echo_time'], 0.0)
844+
assert_equal(HDR_INFO['repetition_time'], npa([ 21225.76]))
845+
assert_equal(HDR_INFO['patient_position'], 'HFS')

0 commit comments

Comments
 (0)