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

ENH: Image class has ability to be created from another Image, and allows

intent code to be changed. Nifti class emits new "header" notifier topic
when intent changes.
parent d27bfa49
No related branches found
No related tags found
No related merge requests found
...@@ -223,7 +223,9 @@ class Nifti(notifier.Notifier, meta.Meta): ...@@ -223,7 +223,9 @@ class Nifti(notifier.Notifier, meta.Meta):
=============== ======================================================== =============== ========================================================
``'transform'`` The affine transformation matrix has changed. This topic ``'transform'`` The affine transformation matrix has changed. This topic
will occur when the ``voxToWorldMat`` is changed. will occur when the :meth:`voxToWorldMat` is changed.
``'header A header field has changed. This will occur when the
:meth:`intent` is changed.
=============== ======================================================== =============== ========================================================
""" """
...@@ -250,14 +252,10 @@ class Nifti(notifier.Notifier, meta.Meta): ...@@ -250,14 +252,10 @@ class Nifti(notifier.Notifier, meta.Meta):
shape, shape,
pixdim) pixdim)
self.header = header self.header = header
self.__shape = shape self.__shape = shape
self.__origShape = origShape self.__origShape = origShape
self.__pixdim = pixdim self.__pixdim = pixdim
self.__intent = header.get('intent_code',
constants.NIFTI_INTENT_NONE)
self.__affines = affines self.__affines = affines
self.__isNeurological = isneuro self.__isNeurological = isneuro
...@@ -463,9 +461,17 @@ class Nifti(notifier.Notifier, meta.Meta): ...@@ -463,9 +461,17 @@ class Nifti(notifier.Notifier, meta.Meta):
@property @property
def intent(self): def intent(self):
"""Returns the NIFTI intent code of this image. """Returns the NIFTI intent code of this image. """
""" return self.header.get('intent_code', constants.NIFTI_INTENT_NONE)
return self.__intent
@intent.setter
def intent(self, val):
"""Sets the NIFTI intent code of this image. """
# analyze has no intent
if self.niftiVersion > 0:
self.header.set_intent(val, allow_unknown=True)
self.notify(topic='header')
@property @property
...@@ -950,7 +956,13 @@ class Image(Nifti): ...@@ -950,7 +956,13 @@ class Image(Nifti):
nibImage = ctr(image, xform, header=header) nibImage = ctr(image, xform, header=header)
# otherwise, we assume that it is a nibabel image # If it's an Image object, we
# just take the nibabel image
elif isinstance(image, Image):
nibImage = image.nibImage
# otherwise, we assume that
# it is a nibabel image
else: else:
nibImage = image nibImage = image
...@@ -985,9 +997,10 @@ class Image(Nifti): ...@@ -985,9 +997,10 @@ class Image(Nifti):
threaded=threaded) threaded=threaded)
# Listen to ourself for changes # Listen to ourself for changes
# to the voxToWorldMat, so we # to header attributse so we
# can update the saveState. # can update the saveState.
self.register(self.name, self.__transformChanged, topic='transform') self.register(self.name, self.__headerChanged, topic='transform')
self.register(self.name, self.__headerChanged, topic='header')
if calcRange: if calcRange:
self.calcRange() self.calcRange()
...@@ -1126,8 +1139,8 @@ class Image(Nifti): ...@@ -1126,8 +1139,8 @@ class Image(Nifti):
self.__nibImage.set_sform(xform, code) self.__nibImage.set_sform(xform, code)
def __transformChanged(self, *args, **kwargs): def __headerChanged(self, *args, **kwargs):
"""Called when the ``voxToWorldMat`` of this :class:`Nifti` instance """Called when header properties of this :class:`Nifti` instance
changes. Updates the :attr:`saveState` accordinbgly. changes. Updates the :attr:`saveState` accordinbgly.
""" """
if self.__saveState: if self.__saveState:
......
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