Skip to content

Commit 0226db3

Browse files
author
Ben Cipollini
committed
Fix filebasedimage docstring.
1 parent 11bd626 commit 0226db3

File tree

2 files changed

+31
-53
lines changed

2 files changed

+31
-53
lines changed

nibabel/filebasedimages.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# copyright and license terms.
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9-
''' Simple interfaces for images'''
9+
''' Common interface for any image format--volume or surface, binary or xml.'''
1010

1111
try:
1212
basestring
@@ -68,11 +68,10 @@ def copy(self):
6868

6969
class FileBasedImage(object):
7070
'''
71-
It also has a ``header`` - some standard set of meta-data that is specific to
72-
the image format, and ``extra`` - a dictionary container for any other
73-
metadata.
71+
This abstract image class defines an interface for loading/saving images
72+
from disk. It doesn't define any image properties.
7473
75-
It has
74+
It has:
7675
7776
attributes:
7877
@@ -85,18 +84,6 @@ class FileBasedImage(object):
8584
* header
8685
* dataobj
8786
88-
You cannot slice an image, and trying to slice an image generates an
89-
informative TypeError.
90-
'''
91-
92-
93-
'''
94-
This abstract image class defines an interface for loading/saving images
95-
from disk. It doesn't define any image properties.
96-
97-
It has
98-
99-
10087
methods:
10188
* .get_header() (deprecated, use header property instead)
10289
* .to_filename(fname) - writes data to filename(s) derived from
@@ -111,6 +98,13 @@ class FileBasedImage(object):
11198
* instance_to_filename(img, fname) - save ``img`` instance to
11299
filename ``fname``.
113100
101+
It also has a ``header`` - some standard set of meta-data that is specific to
102+
the image format, and ``extra`` - a dictionary container for any other
103+
metadata.
104+
105+
You cannot slice an image, and trying to slice an image generates an
106+
informative TypeError.
107+
114108
115109
There are several ways of writing data.
116110
=======================================
@@ -177,24 +171,6 @@ class FileBasedImage(object):
177171
carry the position at which a write (with ``to_files``) should place the
178172
data. The ``file_map`` contents should therefore be such, that this will
179173
work:
180-
181-
>>> # write an image to files
182-
>>> from io import BytesIO
183-
>>> file_map = nib.AnalyzeImage.make_file_map()
184-
>>> file_map['image'].fileobj = BytesIO()
185-
>>> file_map['header'].fileobj = BytesIO()
186-
>>> img = nib.AnalyzeImage(data, np.eye(4))
187-
>>> img.file_map = file_map
188-
>>> img.to_file_map()
189-
>>> # read it back again from the written files
190-
>>> img2 = nib.AnalyzeImage.from_file_map(file_map)
191-
>>> np.all(img2.get_data() == data)
192-
True
193-
>>> # write, read it again
194-
>>> img2.to_file_map()
195-
>>> img3 = nib.AnalyzeImage.from_file_map(file_map)
196-
>>> np.all(img3.get_data() == data)
197-
True
198174
'''
199175
files_types = (('image', None),)
200176
alternate_exts = () # Modified by @ImageOpener.register_ext_from_image

nibabel/spatialimages.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,24 @@
112112
data. The ``file_map`` contents should therefore be such, that this will
113113
work:
114114
115-
>>> # write an image to files
116-
>>> from io import BytesIO
117-
>>> file_map = nib.AnalyzeImage.make_file_map()
118-
>>> file_map['image'].fileobj = BytesIO()
119-
>>> file_map['header'].fileobj = BytesIO()
120-
>>> img = nib.AnalyzeImage(data, np.eye(4))
121-
>>> img.file_map = file_map
122-
>>> img.to_file_map()
123-
>>> # read it back again from the written files
124-
>>> img2 = nib.AnalyzeImage.from_file_map(file_map)
125-
>>> np.all(img2.get_data() == data)
126-
True
127-
>>> # write, read it again
128-
>>> img2.to_file_map()
129-
>>> img3 = nib.AnalyzeImage.from_file_map(file_map)
130-
>>> np.all(img3.get_data() == data)
131-
True
115+
>>> # write an image to files
116+
>>> from io import BytesIO
117+
>>> import nibabel as nib
118+
>>> file_map = nib.AnalyzeImage.make_file_map()
119+
>>> file_map['image'].fileobj = BytesIO()
120+
>>> file_map['header'].fileobj = BytesIO()
121+
>>> img = nib.AnalyzeImage(data, np.eye(4))
122+
>>> img.file_map = file_map
123+
>>> img.to_file_map()
124+
>>> # read it back again from the written files
125+
>>> img2 = nib.AnalyzeImage.from_file_map(file_map)
126+
>>> np.all(img2.get_data() == data)
127+
True
128+
>>> # write, read it again
129+
>>> img2.to_file_map()
130+
>>> img3 = nib.AnalyzeImage.from_file_map(file_map)
131+
>>> np.all(img3.get_data() == data)
132+
True
132133
133134
'''
134135

@@ -140,7 +141,8 @@
140141

141142
import numpy as np
142143

143-
from .filebasedimages import FileBasedHeader, FileBasedImage, ImageFileError
144+
from .filebasedimages import FileBasedHeader, FileBasedImage
145+
from .filebasedimages import ImageFileError # needed for back-compat.
144146
from .volumeutils import shape_zoom_affine
145147

146148

0 commit comments

Comments
 (0)