Skip to content
Snippets Groups Projects
Commit e20fff6e authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Nifti1 renamed to Nifti. Intent is to have it support both Nifti1 and Nifti2.

parent a16bc50a
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,8 @@ voxel or world space: ...@@ -20,8 +20,8 @@ voxel or world space:
ORIENT_UNKNOWN ORIENT_UNKNOWN
These constants relate to the *space* in which a NIFTI1 image is assumed to be These constants relate to the *space* in which a NIFTI image is assumed to be
(i.e. the transformed coordinate space); they are defined in the NIFTI1 (i.e. the transformed coordinate space); they are defined in the NIFTI
specification: specification:
.. autosummary:: .. autosummary::
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
# #
# Author: Paul McCarthy <pauldmccarthy@gmail.com> # Author: Paul McCarthy <pauldmccarthy@gmail.com>
# #
"""This module provides the :class:`Nifti1` and :class:`Image` classes, for """This module provides the :class:`Nifti` and :class:`Image` classes, for
representing 3D/4D NIFTI1 images. The ``nibabel`` package is used for file representing 3D/4D NIFI1 images. The ``nibabel`` package is used for file
I/O. I/O.
.. note:: Currently, only NIFTI1 images are supported. .. note:: Support for ANALYZE75 and NIFTI2 images has not been tested.
It is very easy to load a NIFTI image:: It is very easy to load a NIFTI image::
...@@ -49,15 +49,15 @@ import fsl.data.imagewrapper as imagewrapper ...@@ -49,15 +49,15 @@ import fsl.data.imagewrapper as imagewrapper
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class Nifti1(object): class Nifti(object):
"""The ``Nifti1`` class is intended to be used as a base class for """The ``Nifti`` class is intended to be used as a base class for
things which either are, or are associated with, a NIFTI1 image. things which either are, or are associated with, a NIFTI image.
The ``Nifti1`` class is intended to represent information stored in The ``Nifti`` class is intended to represent information stored in
the header of a NIFTI1 file - if you want to load the data from the header of a NIFTI file - if you want to load the data from
a file, use the :class:`Image` class instead. a file, use the :class:`Image` class instead.
When a ``Nifti1`` instance is created, it adds the following attributes When a ``Nifti`` instance is created, it adds the following attributes
to itself: to itself:
...@@ -78,13 +78,13 @@ class Nifti1(object): ...@@ -78,13 +78,13 @@ class Nifti1(object):
.. note:: The ``shape`` attribute may not precisely match the image shape .. note:: The ``shape`` attribute may not precisely match the image shape
as reported in the NIFTI1 header, because trailing dimensions of as reported in the NIFTI header, because trailing dimensions of
size 1 are squeezed out. See the :meth:`__determineShape` and size 1 are squeezed out. See the :meth:`__determineShape` and
:meth:`mapIndices` methods. :meth:`mapIndices` methods.
""" """
def __init__(self, header): def __init__(self, header):
"""Create a ``Nifti1`` object. """Create a ``Nifti`` object.
:arg header: A :class:`nibabel.nifti1.Nifti1Header` to be used as :arg header: A :class:`nibabel.nifti1.Nifti1Header` to be used as
the image header. the image header.
...@@ -112,7 +112,7 @@ class Nifti1(object): ...@@ -112,7 +112,7 @@ class Nifti1(object):
def __determineTransform(self, header): def __determineTransform(self, header):
"""Called by :meth:`__init__`. Figures out the voxel-to-world """Called by :meth:`__init__`. Figures out the voxel-to-world
coordinate transformation matrix that is associated with this coordinate transformation matrix that is associated with this
``Nifti1`` instance. ``Nifti`` instance.
""" """
# We have to treat FSL/FNIRT images # We have to treat FSL/FNIRT images
...@@ -135,7 +135,7 @@ class Nifti1(object): ...@@ -135,7 +135,7 @@ class Nifti1(object):
# n.b. For images like this, nibabel returns # n.b. For images like this, nibabel returns
# a scaling matrix where the centre voxel # a scaling matrix where the centre voxel
# corresponds to world location (0, 0, 0). # corresponds to world location (0, 0, 0).
# This goes against the NIFTI1 spec - it # This goes against the NIFTI spec - it
# should just be a straight scaling matrix. # should just be a straight scaling matrix.
elif header['qform_code'] == 0 or header['sform_code'] == 0: elif header['qform_code'] == 0 or header['sform_code'] == 0:
pixdims = header.get_zooms() pixdims = header.get_zooms()
...@@ -211,7 +211,7 @@ class Nifti1(object): ...@@ -211,7 +211,7 @@ class Nifti1(object):
def getXFormCode(self, code=None): def getXFormCode(self, code=None):
"""This method returns the code contained in the NIFTI1 header, """This method returns the code contained in the NIFTI header,
indicating the space to which the (transformed) image is oriented. indicating the space to which the (transformed) image is oriented.
The ``code`` parameter may be either ``sform`` (the default) or The ``code`` parameter may be either ``sform`` (the default) or
...@@ -259,7 +259,7 @@ class Nifti1(object): ...@@ -259,7 +259,7 @@ class Nifti1(object):
@memoize.Instanceify(memoize.memoize) @memoize.Instanceify(memoize.memoize)
def isNeurological(self): def isNeurological(self):
"""Returns ``True`` if it looks like this ``Nifti1`` object is in """Returns ``True`` if it looks like this ``Nifti`` object is in
neurological orientation, ``False`` otherwise. This test is purely neurological orientation, ``False`` otherwise. This test is purely
based on the determinant of the voxel-to-mm transformation matrix - based on the determinant of the voxel-to-mm transformation matrix -
if it has a positive determinant, the image is assumed to be in if it has a positive determinant, the image is assumed to be in
...@@ -316,13 +316,13 @@ class Nifti1(object): ...@@ -316,13 +316,13 @@ class Nifti1(object):
return code return code
class Image(Nifti1, notifier.Notifier): class Image(Nifti, notifier.Notifier):
"""Class which represents a 3D/4D NIFTI1 image. Internally, the image """Class which represents a 3D/4D NIFTI image. Internally, the image
is loaded/stored using a :mod:`nibabel.nifti1.Nifti1Image`, and data is loaded/stored using a :mod:`nibabel.nifti1.Nifti1Image`, and data
access managed by a :class:`.ImageWrapper`. access managed by a :class:`.ImageWrapper`.
In addition to the attributes added by the :meth:`Nifti1.__init__` method, In addition to the attributes added by the :meth:`Nifti.__init__` method,
the following attributes/properties are present on an ``Image`` instance the following attributes/properties are present on an ``Image`` instance
as properties (https://docs.python.org/2/library/functions.html#property): as properties (https://docs.python.org/2/library/functions.html#property):
...@@ -485,7 +485,7 @@ class Image(Nifti1, notifier.Notifier): ...@@ -485,7 +485,7 @@ class Image(Nifti1, notifier.Notifier):
else: else:
name = 'Nibabel image' name = 'Nibabel image'
Nifti1.__init__(self, nibImage.get_header()) Nifti.__init__(self, nibImage.get_header())
self.name = name self.name = name
self.__dataSource = dataSource self.__dataSource = dataSource
...@@ -572,7 +572,7 @@ class Image(Nifti1, notifier.Notifier): ...@@ -572,7 +572,7 @@ class Image(Nifti1, notifier.Notifier):
else: drange = self.__imageWrapper.dataRange else: drange = self.__imageWrapper.dataRange
# Fall back to the cal_min/max # Fall back to the cal_min/max
# fields in the NIFTI1 header # fields in the NIFTI header
# if we don't yet know anything # if we don't yet know anything
# about the image data range. # about the image data range.
if drange[0] is None or drange[1] is None: if drange[0] is None or drange[1] is None:
...@@ -760,11 +760,11 @@ below. ...@@ -760,11 +760,11 @@ below.
""" """
EXTENSION_DESCRIPTIONS = ['Compressed NIFTI1 images', EXTENSION_DESCRIPTIONS = ['Compressed NIFTI images',
'NIFTI1 images', 'NIFTI images',
'ANALYZE75 images', 'ANALYZE75 images',
'NIFTI1/ANALYZE75 headers', 'NIFTI/ANALYZE75 headers',
'Compressed NIFTI1/ANALYZE75 images', 'Compressed NIFTI/ANALYZE75 images',
'Compressed images'] 'Compressed images']
"""Descriptions for each of the extensions in :data:`ALLOWED_EXTENSIONS`. """ """Descriptions for each of the extensions in :data:`ALLOWED_EXTENSIONS`. """
...@@ -816,7 +816,7 @@ def addExt(prefix, mustExist=True): ...@@ -816,7 +816,7 @@ def addExt(prefix, mustExist=True):
def loadIndexedImageFile(filename): def loadIndexedImageFile(filename):
"""Loads the given image file using ``nibabel`` and ``indexed_gzip``. """Loads the given image file using ``nibabel`` and ``indexed_gzip``.
Returns a tuple containing the ``Nifti1Image``, and the open Returns a tuple containing the ``nibabel.Nifti1Image``, and the open
``IndexedGzipFile`` handle. ``IndexedGzipFile`` handle.
""" """
......
...@@ -87,7 +87,7 @@ def isPathToTensorData(path): ...@@ -87,7 +87,7 @@ def isPathToTensorData(path):
return getTensorDataPrefix(path) is not None return getTensorDataPrefix(path) is not None
class TensorImage(fslimage.Nifti1): class TensorImage(fslimage.Nifti):
"""The ``TensorImage`` class is able to load and encapsulate the diffusion """The ``TensorImage`` class is able to load and encapsulate the diffusion
tensor data generated by the FSL ``dtifit`` tool. tensor data generated by the FSL ``dtifit`` tool.
""" """
...@@ -133,7 +133,7 @@ class TensorImage(fslimage.Nifti1): ...@@ -133,7 +133,7 @@ class TensorImage(fslimage.Nifti1):
self.__l2 = fslimage.Image(paths['l2']) self.__l2 = fslimage.Image(paths['l2'])
self.__l3 = fslimage.Image(paths['l3']) self.__l3 = fslimage.Image(paths['l3'])
fslimage.Nifti1.__init__(self, self.__l1.header) fslimage.Nifti.__init__(self, self.__l1.header)
l1dir = op.abspath(op.dirname(paths['l1'])) l1dir = op.abspath(op.dirname(paths['l1']))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment