Skip to content

Commit 378edbb

Browse files
authored
Merge pull request #58 from oesteban/fix/nb-get_data
ENH: Update ``spatialimage.get_data()`` -> ``spatialimage.get_fdata()``
2 parents 714e3c5 + 1870f5e commit 378edbb

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

sdcflows/interfaces/fmap.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _run_interface(self, runtime):
5151
from scipy import ndimage as sim
5252

5353
fmap_nii = nb.load(self.inputs.in_file)
54-
data = np.squeeze(fmap_nii.get_data().astype(np.float32))
54+
data = np.squeeze(fmap_nii.get_fdata(dtype='float32'))
5555

5656
# Despike / denoise (no-mask)
5757
if self.inputs.despike:
@@ -60,7 +60,7 @@ def _run_interface(self, runtime):
6060
mask = None
6161
if isdefined(self.inputs.in_mask):
6262
masknii = nb.load(self.inputs.in_mask)
63-
mask = masknii.get_data().astype(np.uint8)
63+
mask = np.asanyarray(masknii.dataobj).astype('uint8')
6464

6565
# Dilate mask
6666
if self.inputs.mask_erode > 0:
@@ -95,7 +95,7 @@ def _run_interface(self, runtime):
9595
smoothed1 = bspobj.get_smoothed()
9696

9797
# Manipulate the difference map
98-
diffmap = data - smoothed1.get_data()
98+
diffmap = data - smoothed1.get_fdata(dtype='float32')
9999
sderror = mad(diffmap[mask > 0])
100100
LOGGER.info('SD of error after B-Spline fitting is %f', sderror)
101101
errormask = np.zeros_like(diffmap)
@@ -118,12 +118,12 @@ def _run_interface(self, runtime):
118118
bspobj2 = fbsp.BSplineFieldmap(diffmapnii, knots_zooms=[24., 24., 4.],
119119
njobs=self.inputs.num_threads)
120120
bspobj2.fit()
121-
smoothed2 = bspobj2.get_smoothed().get_data()
121+
smoothed2 = bspobj2.get_smoothed().get_fdata(dtype='float32')
122122

123-
final = smoothed1.get_data().copy()
123+
final = smoothed1.get_fdata(dtype='float32').copy()
124124
final[..., errorslice[0]:errorslice[-1]] += smoothed2
125125
else:
126-
final = smoothed1.get_data()
126+
final = smoothed1.get_fdata(dtype='float32')
127127

128128
nb.Nifti1Image(final, datanii.affine, datanii.header).to_filename(
129129
self._results['out_file'])
@@ -329,14 +329,16 @@ def _unwrap(fmap_data, mag_file, mask=None):
329329

330330
nb.Nifti1Image(fmap_data, magnii.affine).to_filename('fmap_rad.nii.gz')
331331
nb.Nifti1Image(mask, magnii.affine).to_filename('fmap_mask.nii.gz')
332-
nb.Nifti1Image(magnii.get_data(), magnii.affine).to_filename('fmap_mag.nii.gz')
332+
nb.Nifti1Image(magnii.get_fdata(dtype='float32'),
333+
magnii.affine).to_filename('fmap_mag.nii.gz')
333334

334335
# Run prelude
335336
res = PRELUDE(phase_file='fmap_rad.nii.gz',
336337
magnitude_file='fmap_mag.nii.gz',
337338
mask_file='fmap_mask.nii.gz').run()
338339

339-
unwrapped = nb.load(res.outputs.unwrapped_phase_file).get_data() * (fmapmax / pi)
340+
unwrapped = nb.load(
341+
res.outputs.unwrapped_phase_file).get_fdata(dtype='float32') * (fmapmax / pi)
340342
return unwrapped
341343

342344

@@ -517,7 +519,7 @@ def _torads(in_file, fmap_range=None, newpath=None):
517519

518520
out_file = fname_presuffix(in_file, suffix='_rad', newpath=newpath)
519521
fmapnii = nb.load(in_file)
520-
fmapdata = fmapnii.get_data()
522+
fmapdata = fmapnii.get_fdata(dtype='float32')
521523

522524
if fmap_range is None:
523525
fmap_range = max(abs(fmapdata.min()), fmapdata.max())
@@ -536,7 +538,7 @@ def _tohz(in_file, range_hz, newpath=None):
536538

537539
out_file = fname_presuffix(in_file, suffix='_hz', newpath=newpath)
538540
fmapnii = nb.load(in_file)
539-
fmapdata = fmapnii.get_data()
541+
fmapdata = fmapnii.get_fdata(dtype='float32')
540542
fmapdata = fmapdata * (range_hz / pi)
541543
out_img = nb.Nifti1Image(fmapdata, fmapnii.affine, fmapnii.header)
542544
out_img.set_data_dtype('float32')
@@ -578,7 +580,7 @@ def phdiff2fmap(in_file, delta_te, newpath=None):
578580

579581
out_file = fname_presuffix(in_file, suffix='_fmap', newpath=newpath)
580582
image = nb.load(in_file)
581-
data = (image.get_data().astype(np.float32) / (2. * math.pi * delta_te))
583+
data = (image.get_fdata(dtype='float32') / (2. * math.pi * delta_te))
582584
nii = nb.Nifti1Image(data, image.affine, image.header)
583585
nii.set_data_dtype(np.float32)
584586
nii.to_filename(out_file)

sdcflows/viz/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def plot_registration(anat_nii, div_id, plot_params=None,
2828

2929
out_files = []
3030
if estimate_brightness:
31-
plot_params = robust_set_limits(anat_nii.get_data().reshape(-1),
32-
plot_params)
31+
plot_params = robust_set_limits(
32+
anat_nii.get_fdata(dtype='float32').reshape(-1),
33+
plot_params)
3334

3435
# Plot each cut axis
3536
for i, mode in enumerate(list(order)):
@@ -44,8 +45,8 @@ def plot_registration(anat_nii, div_id, plot_params=None,
4445
display = plot_anat(anat_nii, **plot_params)
4546
if overlay is not None:
4647
_overlay_params = {
47-
'vmin': overlay.get_fdata().min(),
48-
'vmax': overlay.get_fdata().max(),
48+
'vmin': overlay.get_fdata(dtype='float32').min(),
49+
'vmax': overlay.get_fdata(dtype='float32').max(),
4950
'cmap': plt.cm.gray,
5051
'interpolation': 'nearest',
5152
}

sdcflows/workflows/pepolar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def _fix_hdr(in_file, newpath=None):
312312
hdr.set_data_dtype('<f4')
313313
hdr.set_intent('vector', (), '')
314314
out_file = fname_presuffix(in_file, "_warpfield", newpath=newpath)
315-
nb.Nifti1Image(nii.get_data().astype('<f4'), nii.affine, hdr).to_filename(
315+
nb.Nifti1Image(nii.get_fdata(dtype='float32'), nii.affine, hdr).to_filename(
316316
out_file)
317317
return out_file
318318

0 commit comments

Comments
 (0)