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

New data type: FEATImage, a subclass of Image which has FEAT

stuff. Overlay load function auto-detects FEAT-like images and creates
FEATImage instances instead of Image instances where necessary.
parent ee3bf5cf
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#
# featimage.py - An Image subclass which has some FEAT-specific functionality.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""This module provides the :class:`FeatImage` class, a subclass of
:class:`.Image` designed for the ``filtered_func_data`` file of a FEAT
analysis.
"""
import os.path as op
import image as fslimage
def isFEATData(path):
keys = ['.feat{}filtered_func_data' .format(op.sep),
'.gfeat{}filtered_func_data'.format(op.sep)]
isfeat = any([k in path for k in keys])
return isfeat
class FEATImage(fslimage.Image):
def __init__(self, image, **kwargs):
fslimage.Image.__init__(self, image, **kwargs)
if not isFEATData(self.dataSource):
raise ValueError('{} does not appear to be data from a '
'FEAT analysis'.format(self.dataSource))
# A FEATImage is an Image which has
# some extra utility methods, something
# like all of the below things:
# def numParameterEstimates(self):
# return 0
# def numCOPEs(self):
# return 0
# def getParameterEstimate(self, num):
# pass
# def getFullModelFit(self):
# pass
# def getPartialModelFIt(self, contrast):
# pass
# def getCOPEs(self):
# pass
# def getZStats(self):
# pass
# def getThresholdedZStats(self):
# pass
# def getSomethingForClusters(self):
# pass
# # Return a copy of this image, transformed
# # to the specified spaced (e.g. MNI152,
# # structural, functional, etc)
# def getInSpace(self, space):
# pass
...@@ -115,7 +115,7 @@ class Image(props.HasProperties): ...@@ -115,7 +115,7 @@ class Image(props.HasProperties):
nibImage, filename = loadImage(addExt(image)) nibImage, filename = loadImage(addExt(image))
self.nibImage = nibImage self.nibImage = nibImage
self.dataSource = image self.dataSource = op.abspath(image)
# if the returned file name is not the same as # if the returned file name is not the same as
# the provided file name, that means that the # the provided file name, that means that the
......
...@@ -17,9 +17,10 @@ import os.path as op ...@@ -17,9 +17,10 @@ import os.path as op
import props import props
import fsl.data.image as fslimage import fsl.data.image as fslimage
import fsl.data.strings as strings import fsl.data.featimage as fslfeatimage
import fsl.data.model as fslmodel import fsl.data.strings as strings
import fsl.data.model as fslmodel
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -153,7 +154,10 @@ def guessDataSourceType(filename): ...@@ -153,7 +154,10 @@ def guessDataSourceType(filename):
else: else:
filename = fslimage.addExt(filename, False) filename = fslimage.addExt(filename, False)
if any([filename.endswith(e) for e in fslimage.ALLOWED_EXTENSIONS]): if any([filename.endswith(e) for e in fslimage.ALLOWED_EXTENSIONS]):
return fslimage.Image, filename if fslfeatimage.isFEATData(filename):
return fslfeatimage.FEATImage, filename
else:
return fslimage.Image, filename
return None, filename return None, filename
...@@ -237,6 +241,7 @@ def loadOverlays(paths, loadFunc='default', errorFunc='default'): ...@@ -237,6 +241,7 @@ def loadOverlays(paths, loadFunc='default', errorFunc='default'):
e = str(e) e = str(e)
msg = strings.messages['overlay.loadOverlays.error'].format(s, e) msg = strings.messages['overlay.loadOverlays.error'].format(s, e)
title = strings.titles[ 'overlay.loadOverlays.error'] title = strings.titles[ 'overlay.loadOverlays.error']
log.debug('Error loading overlay ({}), ({})'.format(s, e))
wx.MessageBox(msg, title, wx.ICON_ERROR | wx.OK) wx.MessageBox(msg, title, wx.ICON_ERROR | wx.OK)
# If loadFunc or errorFunc are explicitly set to # If loadFunc or errorFunc are explicitly set to
...@@ -271,6 +276,8 @@ def loadOverlays(paths, loadFunc='default', errorFunc='default'): ...@@ -271,6 +276,8 @@ def loadOverlays(paths, loadFunc='default', errorFunc='default'):
strings.messages['overlay.loadOverlays.unknownType']) strings.messages['overlay.loadOverlays.unknownType'])
continue continue
log.debug('Loading overlay {} (guessed data type: {}'.format(
path, dtype.__name__))
try: overlays.append(dtype(path)) try: overlays.append(dtype(path))
except Exception as e: errorFunc(path, e) except Exception as e: errorFunc(path, e)
......
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