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

'Current' plot settings can be changed; Contrast vectors are scaled correctly

parent d9e12198
No related branches found
No related tags found
No related merge requests found
...@@ -206,14 +206,18 @@ class FEATImage(fslimage.Image): ...@@ -206,14 +206,18 @@ class FEATImage(fslimage.Image):
return self.__copes[num] return self.__copes[num]
def fit(self, contrast, xyz): def fit(self, contrast, xyz, fullmodel=False):
if not fullmodel:
contrast = np.array(contrast)
contrast /= np.sqrt(contrast.sum() ** 2)
x, y, z = xyz x, y, z = xyz
numEVs = self.numEVs() numEVs = self.numEVs()
if len(contrast) != numEVs: if len(contrast) != numEVs:
raise ValueError('Contrast is wrong length') raise ValueError('Contrast is wrong length')
X = self.__design X = self.__design
data = self.data[x, y, z, :] data = self.data[x, y, z, :]
modelfit = np.zeros(len(data)) modelfit = np.zeros(len(data))
...@@ -221,7 +225,7 @@ class FEATImage(fslimage.Image): ...@@ -221,7 +225,7 @@ class FEATImage(fslimage.Image):
for i in range(numEVs): for i in range(numEVs):
pe = self.getPE(i)[x, y, z] pe = self.getPE(i)[x, y, z]
modelfit += np.dot(X[:, i], pe) * contrast[i] modelfit += X[:, i] * pe * contrast[i]
return modelfit + data.mean() return modelfit + data.mean()
......
...@@ -213,11 +213,13 @@ labels = TypeDict({ ...@@ -213,11 +213,13 @@ labels = TypeDict({
'PlotPanel.xlabel' : 'X', 'PlotPanel.xlabel' : 'X',
'PlotPanel.ylabel' : 'Y', 'PlotPanel.ylabel' : 'Y',
'TimeSeriesControlPanel.currentSettings' : 'Settings for current '
'voxel time course',
'TimeSeriesControlPanel.currentFEATSettings' : 'FEAT settings for ' 'TimeSeriesControlPanel.currentFEATSettings' : 'FEAT settings for '
'selected overlay ({})', 'selected overlay ({})',
'FEATModelFitTimeSeries.full' : 'Full model fit', 'FEATModelFitTimeSeries.full' : 'Full model fit',
'FEATModelFitTimeSeries.cope' : 'COPE{} fit ({})', 'FEATModelFitTimeSeries.cope' : 'COPE{} fit: {}',
'FEATModelFitTimeSeries.pe' : 'PE{} fit', 'FEATModelFitTimeSeries.pe' : 'PE{} fit',
}) })
...@@ -266,6 +268,11 @@ properties = TypeDict({ ...@@ -266,6 +268,11 @@ properties = TypeDict({
'TimeSeriesPanel.demean' : 'Demean', 'TimeSeriesPanel.demean' : 'Demean',
'TimeSeriesPanel.usePixdim' : 'Use pixdims', 'TimeSeriesPanel.usePixdim' : 'Use pixdims',
'TimeSeriesPanel.showCurrent' : 'Plot time series for current voxel', 'TimeSeriesPanel.showCurrent' : 'Plot time series for current voxel',
'TimeSeriesPanel.currentColour' : 'Colour for current time course',
'TimeSeriesPanel.currentAlpha' : 'Transparency for current '
'time course',
'TimeSeriesPanel.currentLineWidth' : 'Line width for current time course',
'TimeSeriesPanel.currentLineStyle' : 'Line style for current time course',
'TimeSeriesPanel.plotFullModelFit' : 'Plot full model fit', 'TimeSeriesPanel.plotFullModelFit' : 'Plot full model fit',
'TimeSeriesPanel.plotResiduals' : 'Plot residuals', 'TimeSeriesPanel.plotResiduals' : 'Plot residuals',
......
...@@ -30,6 +30,11 @@ class TimeSeriesControlPanel(fslpanel.FSLViewPanel): ...@@ -30,6 +30,11 @@ class TimeSeriesControlPanel(fslpanel.FSLViewPanel):
tsProps = ['demean', tsProps = ['demean',
'usePixdim', 'usePixdim',
'showCurrent'] 'showCurrent']
curProps = ['currentColour',
'currentAlpha',
'currentLineWidth',
'currentLineStyle']
plotProps = ['xLogScale', plotProps = ['xLogScale',
'yLogScale', 'yLogScale',
'smooth', 'smooth',
...@@ -43,6 +48,22 @@ class TimeSeriesControlPanel(fslpanel.FSLViewPanel): ...@@ -43,6 +48,22 @@ class TimeSeriesControlPanel(fslpanel.FSLViewPanel):
props.makeWidget(self.__widgets, tsPanel, prop), props.makeWidget(self.__widgets, tsPanel, prop),
displayName=strings.properties[tsPanel, prop]) displayName=strings.properties[tsPanel, prop])
self.__widgets.AddGroup('currentSettings',
strings.labels[self, 'currentSettings'])
# TODO Hide these when tsPanel.showCurrent is false
for prop in curProps:
if prop == 'currentAlpha':
kwargs = {'showLimits' : False, 'spin' : False}
else:
kwargs = {}
self.__widgets.AddWidget(
props.makeWidget(self.__widgets, tsPanel, prop, **kwargs),
displayName=strings.properties[tsPanel, prop],
groupName='currentSettings')
self.__widgets.AddGroup( self.__widgets.AddGroup(
'plotSettings', 'plotSettings',
strings.labels[tsPanel, 'plotSettings']) strings.labels[tsPanel, 'plotSettings'])
......
...@@ -12,6 +12,7 @@ of overlay objects stored in an :class:`.OverlayList`. ...@@ -12,6 +12,7 @@ of overlay objects stored in an :class:`.OverlayList`.
""" """
import copy
import logging import logging
import numpy as np import numpy as np
...@@ -78,6 +79,9 @@ class FEATTimeSeries(TimeSeries): ...@@ -78,6 +79,9 @@ class FEATTimeSeries(TimeSeries):
plotPEFits = props.List(props.Boolean(default=False)) plotPEFits = props.List(props.Boolean(default=False))
plotCOPEFits = props.List(props.Boolean(default=False)) plotCOPEFits = props.List(props.Boolean(default=False))
# TODO 'None', or any PE/COPE
reduceDataAgainst = props.Choice()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
TimeSeries.__init__(self, *args, **kwargs) TimeSeries.__init__(self, *args, **kwargs)
...@@ -226,8 +230,8 @@ class FEATTimeSeries(TimeSeries): ...@@ -226,8 +230,8 @@ class FEATTimeSeries(TimeSeries):
if not TimeSeries.update(self, coords): if not TimeSeries.update(self, coords):
return False return False
if self.__fullModelTs is not None: for modelTs in self.getModelTimeSeries():
self.__fullModelTs.update(coords) modelTs.update(coords)
return True return True
...@@ -254,10 +258,11 @@ class FEATModelFitTimeSeries(TimeSeries): ...@@ -254,10 +258,11 @@ class FEATModelFitTimeSeries(TimeSeries):
def updateModelFit(self): def updateModelFit(self):
x, y, z = self.coords
self.data = self.overlay.fit(self.contrast, (x, y, z)) fitType = self.fitType
contrast = self.contrast
xyz = self.coords
self.data = self.overlay.fit(contrast, xyz, fitType == 'full')
class TimeSeriesPanel(plotpanel.PlotPanel): class TimeSeriesPanel(plotpanel.PlotPanel):
...@@ -269,13 +274,26 @@ class TimeSeriesPanel(plotpanel.PlotPanel): ...@@ -269,13 +274,26 @@ class TimeSeriesPanel(plotpanel.PlotPanel):
""" """
demean = props.Boolean(default=True) demean = props.Boolean(default=True)
usePixdim = props.Boolean(default=False) usePixdim = props.Boolean(default=False)
showCurrent = props.Boolean(default=True) showCurrent = props.Boolean(default=True)
# TODO
percentChange = props.Boolean(default=False)
currentColour = copy.copy(TimeSeries.colour)
currentAlpha = copy.copy(TimeSeries.alpha)
currentLineWidth = copy.copy(TimeSeries.lineWidth)
currentLineStyle = copy.copy(TimeSeries.lineStyle)
def __init__(self, parent, overlayList, displayCtx): def __init__(self, parent, overlayList, displayCtx):
self.currentColour = (0, 0, 0)
self.currentAlpha = 1
self.currentLineWidth = 1
self.currentLineStyle = ':'
actionz = { actionz = {
'toggleTimeSeriesList' : lambda *a: self.togglePanel( 'toggleTimeSeriesList' : lambda *a: self.togglePanel(
fslcontrols.TimeSeriesListPanel, False, self), fslcontrols.TimeSeriesListPanel, False, self),
...@@ -304,11 +322,33 @@ class TimeSeriesPanel(plotpanel.PlotPanel): ...@@ -304,11 +322,33 @@ class TimeSeriesPanel(plotpanel.PlotPanel):
self.addListener('usePixdim', self._name, self.draw) self.addListener('usePixdim', self._name, self.draw)
self.addListener('showCurrent', self._name, self.draw) self.addListener('showCurrent', self._name, self.draw)
csc = self.__currentSettingsChanged
self.addListener('currentColour', self._name, csc)
self.addListener('currentAlpha', self._name, csc)
self.addListener('currentLineWidth', self._name, csc)
self.addListener('currentLineStyle', self._name, csc)
self.__currentOverlay = None self.__currentOverlay = None
self.__currentTs = None self.__currentTs = None
self.Layout() self.Layout()
self.draw() self.draw()
def __currentSettingsChanged(self, *a):
if self.__currentTs is None:
return
tss = [self.__currentTs]
if isinstance(self.__currentTs, FEATTimeSeries):
tss.extend(self.__currentTs.getModelTimeSeries())
for ts in tss:
ts.colour = self.currentColour
ts.alpha = self.currentAlpha
ts.lineWidth = self.currentLineWidth
ts.lineStyle = self.currentLineStyle
def destroy(self): def destroy(self):
plotpanel.PlotPanel.destroy(self) plotpanel.PlotPanel.destroy(self)
...@@ -378,12 +418,17 @@ class TimeSeriesPanel(plotpanel.PlotPanel): ...@@ -378,12 +418,17 @@ class TimeSeriesPanel(plotpanel.PlotPanel):
else: else:
ts = TimeSeries(self, overlay, vox) ts = TimeSeries(self, overlay, vox)
ts.colour = [0, 0, 0] ts.colour = self.currentColour
ts.alpha = 1 ts.alpha = self.currentAlpha
ts.lineWidth = 2 ts.lineWidth = self.currentLineWidth
ts.lineStyle = ':' ts.lineStyle = self.currentLineStyle
ts.label = None ts.label = None
ts.bindProps('colour' , self, 'currentColour')
ts.bindProps('alpha' , self, 'currentAlpha')
ts.bindProps('lineWidth', self, 'currentLineWidth')
ts.bindProps('lineStyle', self, 'currentLineStyle')
self.__currentTs = ts self.__currentTs = ts
self.__currentOverlay = overlay self.__currentOverlay = overlay
......
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