Skip to content

Commit 66b8d38

Browse files
committed
Merge branch 'fixing-parrec' into main-master
* fixing-parrec: (21 commits) RF: rewrite parrec affine routine after testing NF: dot_reduce utility function RF: remove unused inport in funcs RF: refactor parrec affine, possibly breaks stuff DOC: fix tiny typo in docstring DOC: fix errors in top-level docstring TST: add regression tests for affine RF: remove use of deprecated read_img_data RF: error if trying to set par data offset !=0 RF: avoid setting data offset of 0 if already set DOC: pep8 + expand / format docstrings for parrec BF: parrec2nii ignored FH image offset TST: Verify PARREC affines differ in the right places RF: python 3 fixes for openers test RF: some python 3 fixes for par / rec stuff RF: change slice orientation names for par/rec TST: add test of parrec2nii script RF+BF: refactor parrec to use latest nibabel NF: add skeleton for tests for PAR/REC conversion NF: add PAR / REC data for testing ... Conflicts: COPYING
2 parents a80666b + bb0973f commit 66b8d38

24 files changed

+2167
-175
lines changed

COPYING

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ documentation is covered by the MIT license.
1919

2020
The MIT License
2121

22-
Copyright (c) 2009-2011 Matthew Brett <[email protected]>
23-
Copyright (c) 2010-2011 Stephan Gerhard <[email protected]>
22+
Copyright (c) 2009-2014 Matthew Brett <[email protected]>
23+
Copyright (c) 2010-2013 Stephan Gerhard <[email protected]>
2424
Copyright (c) 2006-2010 Michael Hanke <[email protected]>
2525
Copyright (c) 2011 Christian Haselgrove <[email protected]>
2626
Copyright (c) 2010-2011 Jarrod Millman <[email protected]>
27-
Copyright (c) 2011-2012 Yaroslav Halchenko <[email protected]>
27+
Copyright (c) 2011-2014 Yaroslav Halchenko <[email protected]>
2828

2929
Permission is hereby granted, free of charge, to any person obtaining a copy
3030
of this software and associated documentation files (the "Software"), to deal
@@ -45,8 +45,8 @@ documentation is covered by the MIT license.
4545
THE SOFTWARE.
4646

4747

48-
3rd Party Code
49-
==============
48+
3rd party code and data
49+
=======================
5050

5151
Some code distributed within the nibabel sources was developed by other
5252
projects. This code is distributed under its respective licenses that are
@@ -151,7 +151,6 @@ subject to the following conditions:
151151
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
152152
OTHER DEALINGS IN THE SOFTWARE.
153153

154-
155154
mni_icbm152_t1_tal_nlin_asym_09a
156155
--------------------------------
157156

@@ -171,3 +170,24 @@ following license (where 'softwware' refers to the image):
171170
implied warranty. The authors are not responsible for any data loss,
172171
equipment damage, property loss, or injury to subjects or patients
173172
resulting from the use or misuse of this software package.
173+
174+
Philips PAR/REC data
175+
--------------------
176+
177+
The files::
178+
179+
nibabel/tests/data/phantom_EPI_asc_CLEAR_2_1.PAR
180+
nibabel/tests/data/phantom_EPI_asc_CLEAR_2_1.REC
181+
nibabel/tests/data/Phantom_EPI_3mm_cor_20APtrans_15RLrot_SENSE_15_1.PAR
182+
nibabel/tests/data/Phantom_EPI_3mm_cor_SENSE_8_1.PAR
183+
nibabel/tests/data/Phantom_EPI_3mm_sag_15AP_SENSE_13_1.PAR
184+
nibabel/tests/data/Phantom_EPI_3mm_sag_15FH_SENSE_12_1.PAR
185+
nibabel/tests/data/Phantom_EPI_3mm_sag_15RL_SENSE_11_1.PAR
186+
nibabel/tests/data/Phantom_EPI_3mm_sag_SENSE_7_1.PAR
187+
nibabel/tests/data/Phantom_EPI_3mm_tra_-30AP_10RL_20FH_SENSE_14_1.PAR
188+
nibabel/tests/data/Phantom_EPI_3mm_tra_15FH_SENSE_9_1.PAR
189+
nibabel/tests/data/Phantom_EPI_3mm_tra_15RL_SENSE_10_1.PAR
190+
nibabel/tests/data/Phantom_EPI_3mm_tra_SENSE_6_1.PAR
191+
192+
are from http://psydata.ovgu.de/philips_achieva_testfiles, and released under
193+
the PDDL version 1.0 available at http://opendatacommons.org/licenses/pddl/1.0/

bin/parrec2nii

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import gzip
1010
import nibabel
1111
import nibabel.parrec as pr
1212
import nibabel.nifti1 as nifti1
13-
from nibabel.loadsave import read_img_data
1413
from nibabel.filename_parser import splitext_addext
1514
from nibabel.volumeutils import seek_tell
1615

@@ -86,7 +85,7 @@ def proc_file(infile, opts):
8685
pr_img = pr.load(infile)
8786
pr_hdr = pr_img.header
8887
# get the raw unscaled data form the REC file
89-
raw_data = read_img_data(pr_img, prefer='unscaled')
88+
raw_data = pr_img.dataobj.get_unscaled()
9089

9190
# compute affine with desired origin
9291
affine = pr_hdr.get_affine(origin=opts.origin)
@@ -165,10 +164,10 @@ def proc_file(infile, opts):
165164
if opts.compressed:
166165
verbose('Using gzip compression')
167166
outfilename += '.nii.gz'
168-
outfile = gzip.open(outfilename, 'w')
167+
outfile = gzip.open(outfilename, 'wb')
169168
else:
170169
outfilename += '.nii'
171-
outfile = open(outfilename, 'w')
170+
outfile = open(outfilename, 'wb')
172171

173172
verbose('Writing %s' % outfilename)
174173
# first write the header

nibabel/affines.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import numpy as np
77

8+
from .externals.six.moves import reduce
9+
810

911
def apply_affine(aff, pts):
1012
""" Apply affine matrix `aff` to points `pts`
@@ -225,3 +227,23 @@ def append_diag(aff, steps, starts=()):
225227
# Add translations for new affine, plus last 1
226228
aff_plus[old_n_out:,-1] = list(starts) + [1]
227229
return aff_plus
230+
231+
232+
def dot_reduce(*args):
233+
""" Apply numpy dot product function from right to left on arrays
234+
235+
For passed arrays :math:`A, B, C, ... Z` returns :math:`A \dot B \dot C ...
236+
\dot Z` where "." is the numpy array dot product.
237+
238+
Parameters
239+
----------
240+
\*\*args : arrays
241+
Arrays that can be passed to numpy ``dot`` function
242+
243+
Returns
244+
-------
245+
dot_product : array
246+
If there are N arguments, result of ``arg[0].dot(arg[1].dot(arg[2].dot
247+
... arg[N-2].dot(arg[N-1])))...``
248+
"""
249+
return reduce(lambda x, y: np.dot(y, x), args[::-1])

nibabel/funcs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
''' Processor functions for images '''
1111
import numpy as np
1212

13-
from .orientations import (io_orientation, inv_ornt_aff, flip_axis,
13+
from .orientations import (io_orientation, inv_ornt_aff,
1414
apply_orientation, OrientationError)
1515
from .loadsave import load
1616

@@ -204,4 +204,3 @@ def _aff_is_diag(aff):
204204
''' Utility function returning True if affine is nearly diagonal '''
205205
rzs_aff = aff[:3, :3]
206206
return np.allclose(rzs_aff, np.diag(np.diag(rzs_aff)))
207-

nibabel/loadsave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def read_img_data(img, prefer='scaled'):
202202
# the consumed values back from the proxy
203203
if is_proxy(dao) and (default_offset or default_scaling):
204204
hdr = hdr.copy()
205-
if default_offset:
205+
if default_offset and dao.offset != 0:
206206
hdr.set_data_offset(dao.offset)
207207
if default_scaling and (dao.slope, dao.inter) != (1, 0):
208208
hdr.set_slope_inter(dao.slope, dao.inter)

nibabel/openers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def tell(self, *args, **kwargs):
108108
def close(self, *args, **kwargs):
109109
return self.fobj.close(*args, **kwargs)
110110

111+
def __iter__(self):
112+
return iter(self.fobj)
113+
111114
def close_if_mine(self):
112115
""" Close ``self.fobj`` iff we opened it in the constructor
113116
"""

0 commit comments

Comments
 (0)