Skip to content

Commit 2407015

Browse files
committed
DOC: Improve docstring
1 parent e147cb2 commit 2407015

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

nibabel/filebasedimages.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class FileBasedImage(object):
7979
8080
methods:
8181
82-
* .get_header() (deprecated, use header property instead)
83-
* .to_filename(fname) - writes data to filename(s) derived from
82+
* get_header() (deprecated, use header property instead)
83+
* to_filename(fname) - writes data to filename(s) derived from
8484
``fname``, where the derivation may differ between formats.
8585
* to_file_map() - save image to files with which the image is already
8686
associated.
@@ -524,37 +524,43 @@ class SerializableImage(FileBasedImage):
524524
525525
methods:
526526
527-
* .to_bytes() - serialize image to byte string
527+
* to_bytes() - serialize image to byte string
528528
529529
classmethods:
530530
531531
* from_bytes(bytestring) - make instance by deserializing a byte string
532532
533-
The following properties should hold:
533+
Loading from byte strings should provide round-trip equivalence:
534534
535-
* ``klass.from_bytes(bstr).to_bytes() == bstr``
536-
* if ``img = orig.__class__.from_bytes(orig.to_bytes())``, then
537-
``img.header == orig.header`` and ``img.get_data() == orig.get_data()``
535+
.. code:: python
536+
537+
img_a = klass.from_bytes(bstr)
538+
img_b = klass.from_bytes(img_a.to_bytes())
539+
540+
np.allclose(img_a.get_fdata(), img_b.get_fdata())
541+
np.allclose(img_a.affine, img_b.affine)
538542
539543
Further, for images that are single files on disk, the following methods of loading
540544
the image must be equivalent:
541545
546+
.. code:: python
547+
542548
img = klass.from_filename(fname)
543549
544550
with open(fname, 'rb') as fobj:
545551
img = klass.from_bytes(fobj.read())
546552
547553
And the following methods of saving a file must be equivalent:
548554
555+
.. code:: python
556+
549557
img.to_filename(fname)
550558
551559
with open(fname, 'wb') as fobj:
552560
fobj.write(img.to_bytes())
553561
554-
Images that consist of separate header and data files will generally
555-
place the header with the data, but if the header is not of fixed
556-
size and does not define its own size, a new format may need to be
557-
defined.
562+
Images that consist of separate header and data files (e.g., Analyze
563+
images) currently do not support this interface.
558564
'''
559565
@classmethod
560566
def from_bytes(klass, bytestring):

0 commit comments

Comments
 (0)