Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
img2 = nib.load('other_file.nii.gz')
img3 = nib.load('spm_file.img')

data = img1.get_data()
data = img1.get_fdata()
affine = img1.affine

print(img1)
Expand Down
2 changes: 1 addition & 1 deletion nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ def to_file_map(self, file_map=None):
'''
if file_map is None:
file_map = self.file_map
data = self.get_data()
data = np.asanyarray(self.dataobj)
self.update_header()
hdr = self._header
out_dtype = self.get_data_dtype()
Expand Down
2 changes: 1 addition & 1 deletion nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class AFNIImage(SpatialImage):
[ 0. , 0. , 3. , -52.3511],
[ 0. , 0. , 0. , 1. ]])
>>> head = load(os.path.join(datadir, 'example4d+orig.HEAD'))
>>> np.array_equal(head.get_data(), brik.get_data())
>>> np.array_equal(head.get_fdata(), brik.get_fdata())
True
"""

Expand Down
14 changes: 7 additions & 7 deletions nibabel/cifti2/tests/test_cifti2io_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def check_rewrite(arr, axes, extension='.nii'):
(fd, name) = tempfile.mkstemp(extension)
cifti2.Cifti2Image(arr, header=axes).to_filename(name)
img = nib.load(name)
arr2 = img.get_data()
assert (arr == arr2).all()
arr2 = img.get_fdata()
assert np.allclose(arr, arr2)
for idx in range(len(img.shape)):
assert (axes[idx] == img.header.get_axis(idx))
return img
Expand All @@ -103,7 +103,7 @@ def check_rewrite(arr, axes, extension='.nii'):
@needs_nibabel_data('nitest-cifti2')
def test_read_ones():
img = nib.load(os.path.join(test_directory, 'ones.dscalar.nii'))
arr = img.get_data()
arr = img.get_fdata()
axes = [img.header.get_axis(dim) for dim in range(2)]
assert (arr == 1).all()
assert isinstance(axes[0], cifti2_axes.ScalarAxis)
Expand All @@ -118,7 +118,7 @@ def test_read_ones():
@needs_nibabel_data('nitest-cifti2')
def test_read_conte69_dscalar():
img = nib.load(os.path.join(test_directory, 'Conte69.MyelinAndCorrThickness.32k_fs_LR.dscalar.nii'))
arr = img.get_data()
arr = img.get_fdata()
axes = [img.header.get_axis(dim) for dim in range(2)]
assert isinstance(axes[0], cifti2_axes.ScalarAxis)
assert len(axes[0]) == 2
Expand All @@ -132,7 +132,7 @@ def test_read_conte69_dscalar():
@needs_nibabel_data('nitest-cifti2')
def test_read_conte69_dtseries():
img = nib.load(os.path.join(test_directory, 'Conte69.MyelinAndCorrThickness.32k_fs_LR.dtseries.nii'))
arr = img.get_data()
arr = img.get_fdata()
axes = [img.header.get_axis(dim) for dim in range(2)]
assert isinstance(axes[0], cifti2_axes.SeriesAxis)
assert len(axes[0]) == 2
Expand All @@ -147,7 +147,7 @@ def test_read_conte69_dtseries():
@needs_nibabel_data('nitest-cifti2')
def test_read_conte69_dlabel():
img = nib.load(os.path.join(test_directory, 'Conte69.parcellations_VGD11b.32k_fs_LR.dlabel.nii'))
arr = img.get_data()
arr = img.get_fdata()
axes = [img.header.get_axis(dim) for dim in range(2)]
assert isinstance(axes[0], cifti2_axes.LabelAxis)
assert len(axes[0]) == 3
Expand All @@ -162,7 +162,7 @@ def test_read_conte69_dlabel():
@needs_nibabel_data('nitest-cifti2')
def test_read_conte69_ptseries():
img = nib.load(os.path.join(test_directory, 'Conte69.MyelinAndCorrThickness.32k_fs_LR.ptseries.nii'))
arr = img.get_data()
arr = img.get_fdata()
axes = [img.header.get_axis(dim) for dim in range(2)]
assert isinstance(axes[0], cifti2_axes.SeriesAxis)
assert len(axes[0]) == 2
Expand Down
4 changes: 2 additions & 2 deletions nibabel/cifti2/tests/test_cifti2io_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def test_read_and_proxies():
assert_equal(img2.shape, (1, 91282))
# While we cannot reshape arrayproxies, all images are in-memory
assert_true(not img2.in_memory)
data = img2.get_data()
data = img2.get_fdata()
assert_true(data is not img2.dataobj)
# Uncaching has no effect, images are always array images
img2.uncache()
assert_true(data is not img2.get_data())
assert_true(data is not img2.get_fdata())


@needs_nibabel_data('nitest-cifti2')
Expand Down
27 changes: 14 additions & 13 deletions nibabel/cifti2/tests/test_new_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from nibabel.tmpdirs import InTemporaryDirectory

from nose.tools import assert_true, assert_equal, assert_raises
from nibabel.testing import clear_and_catch_warnings, error_warnings, suppress_warnings
from nibabel.testing import (
clear_and_catch_warnings, error_warnings, suppress_warnings, assert_array_equal)

affine = [[-1.5, 0, 0, 90],
[0, 1.5, 0, -85],
Expand Down Expand Up @@ -246,7 +247,7 @@ def test_dtseries():
assert_equal(img2.nifti_header.get_intent()[0],
'ConnDenseSeries')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_series_map(img2.header.matrix.get_index_map(0))
check_geometry_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -268,7 +269,7 @@ def test_dscalar():
img2 = nib.load('test.dscalar.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnDenseScalar')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_scalar_map(img2.header.matrix.get_index_map(0))
check_geometry_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -290,7 +291,7 @@ def test_dlabel():
img2 = nib.load('test.dlabel.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnDenseLabel')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_label_map(img2.header.matrix.get_index_map(0))
check_geometry_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -310,7 +311,7 @@ def test_dconn():
img2 = nib.load('test.dconn.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnDense')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
assert_equal(img2.header.matrix.get_index_map(0),
img2.header.matrix.get_index_map(1))
check_geometry_map(img2.header.matrix.get_index_map(0))
Expand All @@ -333,7 +334,7 @@ def test_ptseries():
img2 = nib.load('test.ptseries.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnParcelSries')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_series_map(img2.header.matrix.get_index_map(0))
check_parcel_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -355,7 +356,7 @@ def test_pscalar():
img2 = nib.load('test.pscalar.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnParcelScalr')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_scalar_map(img2.header.matrix.get_index_map(0))
check_parcel_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -377,7 +378,7 @@ def test_pdconn():
img2 = ci.load('test.pdconn.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnParcelDense')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_geometry_map(img2.header.matrix.get_index_map(0))
check_parcel_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -399,7 +400,7 @@ def test_dpconn():
img2 = ci.load('test.dpconn.nii')
assert_equal(img2.nifti_header.get_intent()[0], 'ConnDenseParcel')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_parcel_map(img2.header.matrix.get_index_map(0))
check_geometry_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -420,7 +421,7 @@ def test_plabel():
img2 = ci.load('test.plabel.nii')
assert_equal(img.nifti_header.get_intent()[0], 'ConnUnknown')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
check_label_map(img2.header.matrix.get_index_map(0))
check_parcel_map(img2.header.matrix.get_index_map(1))
del img2
Expand All @@ -440,7 +441,7 @@ def test_pconn():
img2 = ci.load('test.pconn.nii')
assert_equal(img.nifti_header.get_intent()[0], 'ConnParcels')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
assert_equal(img2.header.matrix.get_index_map(0),
img2.header.matrix.get_index_map(1))
check_parcel_map(img2.header.matrix.get_index_map(0))
Expand All @@ -465,7 +466,7 @@ def test_pconnseries():
img2 = ci.load('test.pconnseries.nii')
assert_equal(img.nifti_header.get_intent()[0], 'ConnPPSr')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
assert_equal(img2.header.matrix.get_index_map(0),
img2.header.matrix.get_index_map(1))
check_parcel_map(img2.header.matrix.get_index_map(0))
Expand All @@ -491,7 +492,7 @@ def test_pconnscalar():
img2 = ci.load('test.pconnscalar.nii')
assert_equal(img.nifti_header.get_intent()[0], 'ConnPPSc')
assert_true(isinstance(img2, ci.Cifti2Image))
assert_true((img2.get_data() == data).all())
assert_array_equal(img2.get_fdata(), data)
assert_equal(img2.header.matrix.get_index_map(0),
img2.header.matrix.get_index_map(1))

Expand Down
2 changes: 1 addition & 1 deletion nibabel/cmdline/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def proc_file(f, opts):
if opts.stats or opts.counts:
# We are doomed to load data
try:
d = vol.get_data()
d = np.asarray(vol.dataobj)
if not opts.stats_zeros:
d = d[np.nonzero(d)]
else:
Expand Down
4 changes: 2 additions & 2 deletions nibabel/dataobj_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def get_data(self, caching='fill'):

We recommend you use the ``get_fdata`` method instead of the
``get_data`` method, because it is easier to predict the return
data type. We will deprecate the ``get_data`` method around April
2018, and remove it around April 2020.
data type. ``get_data`` will be deprecated around November 2019
and removed around November 2021.

If you don't care about the predictability of the return data type,
and you want the minimum possible data size in memory, you can
Expand Down
4 changes: 2 additions & 2 deletions nibabel/ecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def __init__(self, dataobj, affine, header,
>>> frame0 = img.get_frame(0)
>>> frame0.shape == (10, 10, 3)
True
>>> data4d = img.get_data()
>>> data4d = img.get_fdata()
>>> data4d.shape == (10, 10, 3, 1)
True
"""
Expand Down Expand Up @@ -945,7 +945,7 @@ def to_file_map(self, file_map=None):

# It appears to be necessary to load the data before saving even if the
# data itself is not used.
self.get_data()
self.get_fdata()
hdr = self.header
mlist = self._mlist
subheaders = self.get_subheaders()
Expand Down
2 changes: 1 addition & 1 deletion nibabel/filebasedimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FileBasedImage(object):

You can get the data out again with::

img.get_data()
img.get_fdata()

Less commonly, for some image types that support it, you might want to
fetch out the unscaled array via the object containing the data::
Expand Down
2 changes: 1 addition & 1 deletion nibabel/freesurfer/mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def to_file_map(self, file_map=None):
'''
if file_map is None:
file_map = self.file_map
data = self.get_data()
data = np.asanyarray(self.dataobj)
self.update_header()
hdr = self.header
with file_map['image'].get_prepare_fileobj('wb') as mghf:
Expand Down
8 changes: 4 additions & 4 deletions nibabel/freesurfer/tests/test_mghformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_read_mgh():
assert_array_almost_equal(h.get_vox2ras_tkr(), v2rtkr)

# data. will be different for your own mri_volsynth invocation
v = mgz.get_data()
v = mgz.get_fdata()
assert_almost_equal(v[1, 2, 3, 0], -0.3047, 4)
assert_almost_equal(v[1, 2, 3, 1], 0.0018, 4)

Expand All @@ -97,7 +97,7 @@ def test_write_mgh():
# read from the tmp file and see if it checks out
mgz = load('tmpsave.mgz')
h = mgz.header
dat = mgz.get_data()
dat = mgz.get_fdata()
# Delete loaded image to allow file deletion by windows
del mgz
# header
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_filename_exts():
save(img, fname)
# read from the tmp file and see if it checks out
img_back = load(fname)
assert_array_equal(img_back.get_data(), v)
assert_array_equal(img_back.get_fdata(), v)
del img_back


Expand Down Expand Up @@ -288,7 +288,7 @@ def test_mgh_load_fileobj():
fm = MGHImage.make_file_map(mapping=dict(image=bio))
img2 = MGHImage.from_file_map(fm)
assert_true(img2.dataobj.file_like is bio)
assert_array_equal(img.get_data(), img2.get_data())
assert_array_equal(img.get_fdata(), img2.get_fdata())


def test_mgh_affine_default():
Expand Down
7 changes: 3 additions & 4 deletions nibabel/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def squeeze_image(img):
if slen == len(shape):
return klass.from_image(img)
shape = shape[:slen]
data = img.get_data()
data = data.reshape(shape)
data = np.asanyarray(img.dataobj).reshape(shape)
return klass(data,
img.affine,
img.header,
Expand Down Expand Up @@ -144,7 +143,7 @@ def concat_images(images, check_affines=True, axis=None):
raise ValueError('Affine for image {0} does not match affine '
'for first image'.format(i))
# Do not fill cache in image if it is empty
out_data[i] = img.get_data(caching='unchanged')
out_data[i] = np.asanyarray(img.dataobj)

if axis is None:
out_data = np.rollaxis(out_data, 0, out_data.ndim)
Expand All @@ -169,7 +168,7 @@ def four_to_three(img):
imgs : list
list of 3D images
'''
arr = img.get_data()
arr = np.asanyarray(img.dataobj)
header = img.header
affine = img.affine
image_maker = img.__class__
Expand Down
4 changes: 2 additions & 2 deletions nibabel/loadsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def read_img_data(img, prefer='scaled'):
""" Read data from image associated with files

If you want unscaled data, please use ``img.dataobj.get_unscaled()``
instead. If you want scaled data, use ``img.get_data()`` (which will cache
instead. If you want scaled data, use ``img.get_fdata()`` (which will cache
the loaded array) or ``np.array(img.dataobj)`` (which won't cache the
array). If you want to load the data as for a modified header, save the
image with the modified header, and reload.
Expand All @@ -164,7 +164,7 @@ def read_img_data(img, prefer='scaled'):
----------
img : ``SpatialImage``
Image with valid image file in ``img.file_map``. Unlike the
``img.get_data()`` method, this function returns the data read
``img.get_fdata()`` method, this function returns the data read
from the image file, as specified by the *current* image header
and *current* image files.
prefer : str, optional
Expand Down
2 changes: 1 addition & 1 deletion nibabel/minc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import nibabel as nib
img = nib.load('my_funny.mnc')
data = img.get_data()
data = img.get_fdata()
print(data.mean())
print(data.max())
print(data.min())
Expand Down
2 changes: 1 addition & 1 deletion nibabel/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def resample_to_output(in_img,
# looks like when resampled into world coordinates
if n_dim < 3: # Expand image to 3D, make voxel sizes match
new_shape = in_shape + (1,) * (3 - n_dim)
data = in_img.get_data().reshape(new_shape) # 2D data should be small
data = np.asanyarray(in_img.dataobj).reshape(new_shape) # 2D data should be small
in_img = out_class(data, in_img.affine, in_img.header)
if voxel_sizes is not None and len(voxel_sizes) == n_dim:
# Need to pad out voxel sizes to match new image dimensions
Expand Down
2 changes: 1 addition & 1 deletion nibabel/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def slice2volume(index, axis, shape=None):
and then use ``whole_aff`` in ``scipy.ndimage.affine_transform``:

rzs, trans = to_matvec(whole_aff)
data = img2.get_data()
data = img2.get_fdata()
new_slice = scipy.ndimage.affine_transform(data, rzs, trans, slice_shape)

Parameters
Expand Down
Loading