Skip to content

Commit 11bd626

Browse files
author
Ben Cipollini
committed
get_header => header; deprecate get_header
1 parent 249e77a commit 11bd626

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

doc/source/old/examples.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ and we have made a temporary directory for the files we are going to write:
3232
and we've got the path to the nifti example data:
3333

3434
>>> from nibabel.testing import data_path as example_data_path
35-
35+
3636
Loading and saving NIfTI files
3737
==============================
3838

@@ -77,7 +77,7 @@ The relevant header information is extracted from the NumPy array. If you
7777
query the header information about the dimensionality of the image, it returns
7878
the desired values:
7979

80-
>>> print nim.get_header()['dim']
80+
>>> print nim.header['dim']
8181
[ 4 32 32 16 100 1 1 1]
8282

8383
First value shows the number of dimensions in the datset: 4 (good, that's what
@@ -110,8 +110,8 @@ preserving as much header information as possible
110110

111111
>>> nim2 = nib.Nifti1Image(nim.get_data()[..., :10],
112112
... nim.get_affine(),
113-
... nim.get_header())
114-
>>> print nim2.get_header()['dim']
113+
... nim.header)
114+
>>> print nim2.header['dim']
115115
[ 4 32 32 16 10 1 1 1]
116116
>>> # a filename in our temporary directory
117117
>>> fname = pjoin(tmpdir, 'part.hdr.gz')
@@ -136,7 +136,7 @@ will first create a NIfTI image with just a single voxel and 50 timepoints
136136
>>> nim = nib.Nifti1Image(
137137
... (np.linspace(0,100) + np.random.randn(50)).reshape(1,1,1,50),
138138
... np.eye(4))
139-
>>> print nim.get_header()['dim']
139+
>>> print nim.header['dim']
140140
[ 4 1 1 1 50 1 1 1]
141141

142142
Depending on the datatype of the input image the detrending process might
@@ -154,4 +154,4 @@ source image.
154154

155155
>>> nim_detrended = nib.Nifti1Image(data_detrended,
156156
... nim.get_affine(),
157-
... nim.get_header())
157+
... nim.header)

doc/source/old/orientation.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Every image in ``nibabel`` has an orientation. The orientation is the
88
relationship between the voxels in the image array, and millimeters in
9-
some space.
9+
some space.
1010

1111
Affines as orientation
1212
----------------------
@@ -85,7 +85,7 @@ the affine after loading, as in::
8585
img = nibabel.load('some_image.img')
8686
aff = img.get_affine()
8787
x_flipper = np.diag([-1,1,1,1])
88-
lr_img = nibabel.Nifti1Image(img.get_data, np.dot(x_flipper, aff), img.get_header())
88+
lr_img = nibabel.Nifti1Image(img.get_data, np.dot(x_flipper, aff), img.header)
8989

9090
Affines for Analyze, SPM analyze, and NIFTI
9191
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

nibabel/ecat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def to_file_map(self, file_map=None):
929929
# It appears to be necessary to load the data before saving even if the
930930
# data itself is not used.
931931
self.get_data()
932-
hdr = self.get_header()
932+
hdr = self.header
933933
mlist = self._mlist
934934
subheaders = self.get_subheaders()
935935
dir_pos = 512
@@ -944,7 +944,7 @@ def to_file_map(self, file_map=None):
944944
hdr.write_to(hdrf)
945945

946946
# Write every frames
947-
for index in range(0, self.get_header()['num_frames']):
947+
for index in range(0, self.header['num_frames']):
948948
# Move to subheader offset
949949
frame_offset = subheaders._get_frame_offset(index) - 512
950950
imgf.seek(frame_offset)

nibabel/filebasedimages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class FileBasedImage(object):
9898
9999
100100
methods:
101+
* .get_header() (deprecated, use header property instead)
101102
* .to_filename(fname) - writes data to filename(s) derived from
102103
``fname``, where the derivation may differ between formats.
103104
* to_file_map() - save image to files with which the image is already
@@ -250,6 +251,10 @@ def get_header(self):
250251
Please use the `header` property instead of `get_header`; we will
251252
deprecate this method in future versions of nibabel.
252253
"""
254+
warnings.warn('``get_header`` is deprecated.\n'
255+
'Please use the ``img.header`` property '
256+
'instead',
257+
DeprecationWarning, stacklevel=2)
253258
return self.header
254259

255260
def get_filename(self):

nibabel/tests/test_image_api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
assert_equal, assert_not_equal)
4444

4545
from numpy.testing import (assert_almost_equal, assert_array_equal)
46-
46+
from ..testing import clear_and_catch_warnings
4747
from ..tmpdirs import InTemporaryDirectory
4848

4949
from .test_api_validators import ValidateAPI
@@ -134,9 +134,12 @@ def validate_header(self, imaker, params):
134134

135135
def validate_header_deprecated(self, imaker, params):
136136
# Check deprecated header API
137-
img = imaker()
138-
hdr = img.get_header()
139-
assert_true(hdr is img.get_header())
137+
with clear_and_catch_warnings() as w:
138+
warnings.simplefilter('always', DeprecationWarning)
139+
img = imaker()
140+
hdr = img.get_header()
141+
assert_equal(len(w), 1)
142+
assert_true(hdr is img.header)
140143

141144
def validate_shape(self, imaker, params):
142145
# Validate shape

0 commit comments

Comments
 (0)