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

BF: VoxelwiseConfoundEV was missing image attribute. Refactored so that

VoxelwiseEV and VoxelwiseConfoundEV classes share a common base class.
parent 9c452125
No related branches found
No related tags found
No related merge requests found
...@@ -219,6 +219,59 @@ class FEATFSFDesign(object): ...@@ -219,6 +219,59 @@ class FEATFSFDesign(object):
return design return design
class VoxelwiseEVMixin(object):
"""Mixin class for voxelwise EVs.
``VoxelwiseEVMixin`` instances contain the following attributes:
============ ======================================================
``filename`` Path to the image file containing the data for this EV
``image`` Reference to the :class:`.Image` object
============ ======================================================
"""
def __init__(self, filename):
"""Create a ``VoxelwiseEVMixin``.
:arg filename: Path to the file containing the data for this
``VoxelwiseEV``.
"""
if op.exists(filename):
self.__filename = filename
else:
log.warning('Voxelwise EV file does not '
'exist: {}'.format(filename))
self.__filename = None
self.__image = None
def __del__(self):
"""Clears any reference to the voxelwise EV image. """
self.__image = None
@property
def filename(self):
"""Returns the path to the image file containing the data for this EV.
"""
return self.__filename
@property
def image(self):
"""Returns the :class:`.Image` containing the voxelwise EV data. """
if self.__filename is None:
return None
if self.__image is not None:
return self.__image
self.__image = fslimage.Image(self.__filename, mmap=False)
return self.__image
class EV(object): class EV(object):
"""Class representing an explanatory variable in a FEAT design matrix. """Class representing an explanatory variable in a FEAT design matrix.
...@@ -276,7 +329,7 @@ class BasisFunctionEV(NormalEV): ...@@ -276,7 +329,7 @@ class BasisFunctionEV(NormalEV):
pass pass
class VoxelwiseEV(NormalEV): class VoxelwiseEV(NormalEV, VoxelwiseEVMixin):
"""Class representing an EV with different values for each voxel in the """Class representing an EV with different values for each voxel in the
analysis. analysis.
...@@ -308,34 +361,7 @@ class VoxelwiseEV(NormalEV): ...@@ -308,34 +361,7 @@ class VoxelwiseEV(NormalEV):
``VoxelwiseEV``. ``VoxelwiseEV``.
""" """
NormalEV.__init__(self, realIdx, origIdx, title) NormalEV.__init__(self, realIdx, origIdx, title)
VoxelwiseEVMixin.__init__(self, filename)
if op.exists(filename):
self.filename = filename
else:
log.warning('Voxelwise EV file does not '
'exist: {}'.format(filename))
self.filename = None
self.__image = None
def __del__(self):
"""Clears any reference to the voxelwise EV image. """
self.__image = None
@property
def image(self):
"""Returns the :class:`.Image` containing the voxelwise EV data. """
if self.filename is None:
return None
if self.__image is not None:
return self.__image
self.__image = fslimage.Image(self.filename, mmap=False)
return self.__image
class ConfoundEV(EV): class ConfoundEV(EV):
...@@ -386,7 +412,7 @@ class MotionParameterEV(EV): ...@@ -386,7 +412,7 @@ class MotionParameterEV(EV):
self.motionIndex = motionIndex self.motionIndex = motionIndex
class VoxelwiseConfoundEV(EV): class VoxelwiseConfoundEV(EV, VoxelwiseEVMixin):
"""Class representing a voxelwise confound EV. """Class representing a voxelwise confound EV.
``VoxelwiseConfoundEV`` instances contain the following attributes (in ``VoxelwiseConfoundEV`` instances contain the following attributes (in
...@@ -396,6 +422,7 @@ class VoxelwiseConfoundEV(EV): ...@@ -396,6 +422,7 @@ class VoxelwiseConfoundEV(EV):
``voxIndex`` Index of this ``VoxelwiseConfoundEV`` (starting from 0) in ``voxIndex`` Index of this ``VoxelwiseConfoundEV`` (starting from 0) in
relation to all other voxelwise confound EVs. relation to all other voxelwise confound EVs.
``filename`` Path to the image file containing the data for this EV ``filename`` Path to the image file containing the data for this EV
``image`` Reference to the :class:`.Image` object
============ ========================================================== ============ ==========================================================
""" """
def __init__(self, index, voxIndex, title, filename): def __init__(self, index, voxIndex, title, filename):
...@@ -407,17 +434,13 @@ class VoxelwiseConfoundEV(EV): ...@@ -407,17 +434,13 @@ class VoxelwiseConfoundEV(EV):
``VoxelwiseConfoundEV`` in relation to all other ``VoxelwiseConfoundEV`` in relation to all other
voxelwise confound EVs. voxelwise confound EVs.
:arg title: Name of this ``VoxelwiseConfoundEV``. :arg title: Name of this ``VoxelwiseConfoundEV``.
:arg filename: Path to the file containing the data for this
``VoxelwiseConfoundEV``.
""" """
EV.__init__(self, index, title) EV.__init__(self, index, title)
VoxelwiseEVMixin.__init__(self, filename)
self.voxIndex = voxIndex self.voxIndex = voxIndex
if op.exists(filename):
self.filename = filename
else:
log.warning('Voxelwise confound EV file does '
'not exist: {}'.format(filename))
self.filename = None
def getFirstLevelEVs(featDir, settings, designMat): def getFirstLevelEVs(featDir, settings, designMat):
"""Derives the EVs for the given first level FEAT analysis. """Derives the EVs for the given first level FEAT analysis.
......
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