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

Nifti.meta* methods are now in a base-class. Also used by TriangleMesh.

parent 52d7a125
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ import scipy.ndimage as ndimage
import nibabel as nib
import nibabel.fileslice as fileslice
import fsl.utils.meta as meta
import fsl.utils.transform as transform
import fsl.utils.notifier as notifier
import fsl.utils.memoize as memoize
......@@ -57,7 +58,7 @@ import fsl.data.imagewrapper as imagewrapper
log = logging.getLogger(__name__)
class Nifti(notifier.Notifier):
class Nifti(notifier.Notifier, meta.Meta):
"""The ``Nifti`` class is intended to be used as a base class for
things which either are, or are associated with, a NIFTI image.
The ``Nifti`` class is intended to represent information stored in
......@@ -162,19 +163,8 @@ class Nifti(notifier.Notifier):
**Metadata**
The ``Image`` class has a handful of methods allowing you to add and access
additional metadata associated with the image. These methods are used by
the :class:`.DicomImage` and :class:`.MGHImage` to store additional
meta-data that cannot be stored in the NIFTI header:
.. autosummary::
:nosignatures:
metaKeys
metaValues
metaItems
getMeta
setMeta
The ``Image`` class inherits from the :class:`.Meta` class - its methods
can be used to store and query any meta-data associated with the image.
**Notification**
......@@ -212,7 +202,6 @@ class Nifti(notifier.Notifier):
worldToVoxMat = transform.invert(voxToWorldMat)
self.header = header
self.__meta = collections.OrderedDict()
self.__shape = shape
self.__intent = header.get('intent_code',
constants.NIFTI_INTENT_NONE)
......@@ -687,39 +676,6 @@ class Nifti(notifier.Notifier):
return code
def metaKeys(self):
"""Returns the keys contained in the image metadata dictionary
(``dict.keys``).
"""
return self.__meta.keys()
def metaValues(self):
"""Returns the values contained in the image metadata dictionary
(``dict.values``).
"""
return self.__meta.values()
def metaItems(self):
"""Returns the items contained in the image metadata dictionary
(``dict.items``).
"""
return self.__meta.items()
def getMeta(self, *args, **kwargs):
"""Returns the metadata value with the specified key (``dict.get``).
"""
return self.__meta.get(*args, **kwargs)
def setMeta(self, *args, **kwargs):
"""Add some metadata with the specified key (``dict.__setitem__``).
"""
self.__meta.__setitem__(*args, **kwargs)
class Image(Nifti):
"""Class which represents a NIFTI image. Internally, the image is
loaded/stored using a :mod:`nibabel.nifti1.Nifti1Image` or
......
......@@ -27,6 +27,7 @@ import numpy as np
import six
import fsl.utils.meta as meta
import fsl.utils.memoize as memoize
import fsl.utils.transform as transform
......@@ -36,7 +37,7 @@ from . import image as fslimage
log = logging.getLogger(__name__)
class TriangleMesh(object):
class TriangleMesh(meta.Meta):
"""The ``TriangleMesh`` class represents a 3D model. A mesh is defined by a
collection of ``N`` vertices, and ``M`` triangles. The triangles are
defined by ``(M, 3)`` indices into the list of vertices.
......
#!/usr/bin/env python
#
# meta.py - The Meta class/mixin.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""This module provides the :class:`Meta` class. """
import collections
class Meta(object):
"""The ``Meta`` class is intended to be used as a mixin for other classes. It
is simply a wrapper for a dictionary of key-value pairs.
It has a handful of methods allowing you to add and access additional
metadata associated with an object.
.. autosummary::
:nosignatures:
metaKeys
metaValues
metaItems
getMeta
setMeta
"""
def __init__(self):
self.__meta = collections.OrderedDict()
def metaKeys(self):
"""Returns the keys contained in the metadata dictionary
(``dict.keys``).
"""
return self.__meta.keys()
def metaValues(self):
"""Returns the values contained in the metadata dictionary
(``dict.values``).
"""
return self.__meta.values()
def metaItems(self):
"""Returns the items contained in the metadata dictionary
(``dict.items``).
"""
return self.__meta.items()
def getMeta(self, *args, **kwargs):
"""Returns the metadata value with the specified key (``dict.get``).
"""
return self.__meta.get(*args, **kwargs)
def setMeta(self, *args, **kwargs):
"""Add some metadata with the specified key (``dict.__setitem__``).
"""
self.__meta.__setitem__(*args, **kwargs)
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