-
Notifications
You must be signed in to change notification settings - Fork 530
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
Enh/wip/fix/brk topup for odd dimensions. help needed #2832
base: master
Are you sure you want to change the base?
Conversation
fix: completed outputspec for EddyQuad
fix: made the outputdir be mandatory and use the default val
- Remove redundant `__init__` method in `EddyQuad` class. - Use `os.path.abspath()` earlier in order to remove from later statements. - Improve `EddyQuad`'s `base_name` input description. - Remove unnecessary `mandatory=False` params. - Rename `slspec` to `slice_spec`. - Use default for `EddyQuad`'s `base_name` input. - Use a name template for `EddyQuad`'s `output_dir` input.
Nevermind about the applytopup, it turns out I was testing this on a pretty large file :) thanks @oesteban for the help! |
Codecov Report
@@ Coverage Diff @@
## master #2832 +/- ##
==========================================
+ Coverage 67.45% 67.54% +0.09%
==========================================
Files 341 341
Lines 43355 44091 +736
Branches 5379 5626 +247
==========================================
+ Hits 29245 29783 +538
- Misses 13413 13592 +179
- Partials 697 716 +19
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #2832 +/- ##
==========================================
- Coverage 66.9% 66.84% -0.07%
==========================================
Files 341 342 +1
Lines 43454 43648 +194
Branches 5392 5436 +44
==========================================
+ Hits 29074 29175 +101
- Misses 13653 13741 +88
- Partials 727 732 +5
Continue to review full report at Codecov.
|
nipype/interfaces/fsl/epi.py
Outdated
sizes = np.array(data.shape[:3]) | ||
|
||
if self._offsets is None: | ||
self._offsets = np.array(sizes % 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since sizes
is an array, this should already be an array.
self._offsets = np.array(sizes % 2) | |
self._offsets = sizes % 2 |
def _cropfile(self, fname, postfix=''): | ||
import nibabel as nb | ||
im = nb.load(fname) | ||
data = im.get_data() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_data()
is deprecated, but we can get away with not directly loading it. See below.
nipype/interfaces/fsl/epi.py
Outdated
if self._offsets is None: | ||
self._offsets = np.array(sizes % 2) | ||
|
||
if np.any(self._offsets == 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of the work in here is built into nibabel and nipype, so you can reduce this quite a lot:
What about this:
if self._offsets.any():
cropped = im.slicer[:self._offsets[0], :self._offsets[1], :self._offsets[2]]
# Remembering to import fname_presuffix from ..utils.filemanip
out_fname = fname_presuffix(fname, suffix='_cropped' + postfix, newpath=os.getcwd())
cropped._to_filename(out_fname)
else:
out_fname = fname
return out_fname
nipype/interfaces/fsl/epi.py
Outdated
s = imdata.shape | ||
dests = np.array(s) | ||
dests[:3] = s[:3] + self._offsets | ||
data = np.zeros(dests, dtype=im.get_data_dtype()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data = np.zeros(dests, dtype=im.get_data_dtype()) | |
data = np.zeros(dests, dtype=imdata.dtype) |
nipype/interfaces/fsl/epi.py
Outdated
dests = np.array(s) | ||
dests[:3] = s[:3] + self._offsets | ||
data = np.zeros(dests, dtype=im.get_data_dtype()) | ||
data[0:s[0], 0:s[1], 0:s[2], ...] = imdata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a little briefer:
data[0:s[0], 0:s[1], 0:s[2], ...] = imdata | |
data[:s[0], :s[1], :s[2]] = imdata |
nipype/interfaces/fsl/epi.py
Outdated
fixfname, ext2 = op.splitext(fixfname) | ||
ext = ext2 + ext | ||
|
||
fixfname = op.abspath(fixfname + '_fix' + ext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do all of this in one line:
fixfname = fname_presuffix(fname, suffix='_fix', newpath=os.getcwd())
nipype/interfaces/fsl/epi.py
Outdated
|
||
fixfname = op.abspath(fixfname + '_fix' + ext) | ||
|
||
hdr = im.get_header().copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to manually set the header. Shape gets overwritten by the actual data array shape.
hdr = im.get_header().copy() |
nipype/interfaces/fsl/epi.py
Outdated
fixfname = op.abspath(fixfname + '_fix' + ext) | ||
|
||
hdr = im.get_header().copy() | ||
hdr.set_data_shape(data.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hdr.set_data_shape(data.shape) |
nipype/interfaces/fsl/epi.py
Outdated
|
||
hdr = im.get_header().copy() | ||
hdr.set_data_shape(data.shape) | ||
nb.Nifti1Image(data, im.get_affine(), hdr).to_filename(fixfname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_affine
is deprecated, and we can make this work with non-NIfTI-1 images:
nb.Nifti1Image(data, im.get_affine(), hdr).to_filename(fixfname) | |
img.__class__(data, im.affine, im.header).to_filename(fixfname) |
for name, spec in sorted(self.inputs.traits(**check).items()): | ||
if spec.checksize and self.inputs.checksize: | ||
value = self._checksize(name) | ||
setattr(self.inputs, name, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to cause it to be rerun every time? I would verify.
Would you consider adding a file dependency? There is a second cnf that works for volumes with odd numbers of slices. here's
|
Summary
Attempts to fix #948 -- its 4 years later and we are still having this problem! I slightly modified @oesteban 's original commit with a flag called
checksize
, which, if set toTrue
will make the size even before running TOPUP and ApplyTOPUP. It's set toFalse
by default.Problem is, the ApplyTOPUP interface doesn't work!! The process just gets killed. Someone help please!
List of changes proposed in this PR (pull-request)
Acknowledgment