Skip to content

Commit eb9f499

Browse files
committed
NF: add PARREC V4.1 support with tests
Add PARREC 4.1 support from information by Gregory Lee at #277
1 parent 321f309 commit eb9f499

File tree

3 files changed

+141
-4
lines changed

3 files changed

+141
-4
lines changed

nibabel/parrec.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@
160160
'Dynamic scan <0=no 1=yes> ?': ('dyn_scan', int),
161161
'Diffusion <0=no 1=yes> ?': ('diffusion', int),
162162
'Diffusion echo time [ms]': ('diffusion_echo_time', float),
163+
# Lines below added for par / rec versions > 4
163164
'Max. number of diffusion values': ('max_diffusion_values', int),
164165
'Max. number of gradient orients': ('max_gradient_orient', int),
166+
# Line below added for par / rec version > 4.1
165167
'Number of label types <0=no ASL>': ('nr_label_types', int),
166168
}
167169

@@ -205,16 +207,20 @@
205207
('TURBO factor', int,),
206208
('Inversion delay', float)]
207209

208-
# Extra image def fields for 4.2 compared to 4
209-
image_def_dtds['V4.2'] = image_def_dtds['V4'] + [
210+
# Extra image def fields for 4.1 compared to 4
211+
image_def_dtds['V4.1'] = image_def_dtds['V4'] + [
210212
('diffusion b value number', int,), # (imagekey!)
211213
('gradient orientation number', int,), # (imagekey!)
212214
('contrast type', 'S30'), # XXX might be too short?
213215
('diffusion anisotropy type', 'S30'), # XXX might be too short?
214216
('diffusion', float, (3,)),
215-
('label type', int,), # (imagekey!)
216217
]
217218

219+
# Extra image def fields for 4.2 compared to 4.1
220+
image_def_dtds['V4.2'] = image_def_dtds['V4.1'] + [
221+
('label type', int,), # (imagekey!)
222+
]
223+
218224
#: PAR header versions we claim to understand
219225
supported_versions = list(image_def_dtds.keys())
220226

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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.1
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 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 : Head First Supine
26+
. Preparation direction : Anterior-Posterior
27+
. Technique : FEEPI
28+
. Scan resolution (x, y) : 64 39
29+
. Scan mode : MS
30+
. Repetition time [ms] : 2000.000
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 [ms] : 0.0000
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+
#
96+
# === IMAGE INFORMATION ==========================================================
97+
# 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
98+
99+
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
100+
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
101+
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
102+
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
103+
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
104+
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
105+
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
106+
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
107+
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
108+
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
109+
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
110+
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
111+
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
112+
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
113+
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
114+
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
115+
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
116+
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
117+
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
118+
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
119+
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
120+
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
121+
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
122+
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
123+
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
124+
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
125+
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
126+
127+
# === END OF DATA DESCRIPTION FILE ===============================================

nibabel/tests/test_parrec.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
TRUNC_REC = pjoin(DATA_PATH, 'phantom_truncated.REC')
3939
# Fake V4
4040
V4_PAR = pjoin(DATA_PATH, 'phantom_fake_v4.PAR')
41+
# Fake V4.1
42+
V41_PAR = pjoin(DATA_PATH, 'phantom_fake_v4_1.PAR')
4143
# Affine as we determined it mid-2014
4244
AN_OLD_AFFINE = np.array(
4345
[[-3.64994708, 0., 1.83564171, 123.66276611],
@@ -149,7 +151,9 @@ def test_header():
149151
v42_hdr = PARRECHeader(HDR_INFO, HDR_DEFS)
150152
with open(V4_PAR, 'rt') as fobj:
151153
v4_hdr = PARRECHeader.from_fileobj(fobj)
152-
for hdr in (v42_hdr, v4_hdr):
154+
with open(V41_PAR, 'rt') as fobj:
155+
v41_hdr = PARRECHeader.from_fileobj(fobj)
156+
for hdr in (v42_hdr, v41_hdr, v4_hdr):
153157
hdr = PARRECHeader(HDR_INFO, HDR_DEFS)
154158
assert_equal(hdr.get_data_shape(), (64, 64, 9, 3))
155159
assert_equal(hdr.get_data_dtype(), np.dtype('<u2'))

0 commit comments

Comments
 (0)