Exemple #1
0
    def __createModelTs(self, tsType, *args, **kwargs):
        """Creates a ``TimeSeries`` instance of the given ``tsType``, and
        sets its display settings  according to those of this
        ``FEATTimeSeries``.

        :arg tsType: The type to create, e.g. :class:`FEATModelFitTimeSeries`,
                     :class:`FEATEVTimeSeries`, etc.

        :arg args:   Passed to the ``tsType`` constructor.

        :arg kwargs: Passed to the ``tsType`` constructor.
        """

        ts = tsType(self.overlay,
                    self.overlayList,
                    self.displayCtx,
                    self.plotPanel,
                    self,
                    *args,
                    **kwargs)

        ts.alpha     = self.alpha
        ts.lineWidth = self.lineWidth
        ts.lineStyle = self.lineStyle

        if isinstance(ts, FEATModelFitTimeSeries) and ts.fitType == 'full':
            ts.colour = (0, 0, 0.8)
        else:
            ts.colour = fslcm.randomDarkColour()

        return ts
def test_randomX():
    c1 = fslcm.randomColour()
    c2 = fslcm.randomBrightColour()
    c3 = fslcm.randomDarkColour()

    for c in [c1, c2, c3]:
        assert c.shape == (3,)
        assert np.all((c >= 0) & (c <= 1))
Exemple #3
0
    def __init__(self, *args, **kwargs):
        """Create a ``ComplexHistogramSeries``. All arguments are passed
        through to the ``ImageHistogramSeries`` constructor.
        """
        ImageHistogramSeries.__init__(self, *args, **kwargs)

        self.__imaghs  = ImaginaryHistogramSeries(*args, **kwargs)
        self.__maghs   = MagnitudeHistogramSeries(*args, **kwargs)
        self.__phasehs = PhaseHistogramSeries(    *args, **kwargs)

        for hs in (self.__imaghs, self.__maghs, self.__phasehs):
            hs.colour = fslcm.randomDarkColour()
            hs.bindProps('alpha',           self)
            hs.bindProps('lineWidth',       self)
            hs.bindProps('lineStyle',       self)
            hs.bindProps('autoBin',         self)
            hs.bindProps('ignoreZeros',     self)
            hs.bindProps('includeOutliers', self)
Exemple #4
0
    def __init__(self, overlay, overlayList, displayCtx, plotPanel):
        """Create a ``ComplexTimeSeries``. All arguments are passed
        through to the :class:`VoxelTimeSeries` constructor.
        """

        VoxelTimeSeries.__init__(
            self, overlay, overlayList, displayCtx, plotPanel)

        self.__imagts = ImaginaryTimeSeries(
            overlay, overlayList, displayCtx, plotPanel)
        self.__magts = MagnitudeTimeSeries(
            overlay, overlayList, displayCtx, plotPanel)
        self.__phasets = PhaseTimeSeries(
            overlay, overlayList, displayCtx, plotPanel)

        for ts in (self.__imagts, self.__magts, self.__phasets):
            ts.colour = fslcm.randomDarkColour()
            ts.bindProps('alpha',     self)
            ts.bindProps('lineWidth', self)
            ts.bindProps('lineStyle', self)
    def __init__(self, overlay, overlayList, displayCtx, plotPanel):
        """Create a ``ComplexPowerSpectrumSeries``. All arguments are
        passed through to the :class:`VoxelPowerSpectrumSeries` constructor.
        """

        VoxelPowerSpectrumSeries.__init__(self, overlay, overlayList,
                                          displayCtx, plotPanel)

        self.__cachedData = (None, None)
        self.__imagps = ImaginaryPowerSpectrumSeries(self, overlay,
                                                     overlayList, displayCtx,
                                                     plotPanel)
        self.__magps = MagnitudePowerSpectrumSeries(self, overlay, overlayList,
                                                    displayCtx, plotPanel)
        self.__phaseps = PhasePowerSpectrumSeries(self, overlay, overlayList,
                                                  displayCtx, plotPanel)

        for ps in (self.__imagps, self.__magps, self.__phaseps):
            ps.colour = fslcm.randomDarkColour()
            ps.bindProps('alpha', self)
            ps.bindProps('lineWidth', self)
            ps.bindProps('lineStyle', self)
Exemple #6
0
    def __init__(self, overlay, overlayList, displayCtx, plotPanel):
        """Create a ``ComplexPowerSpectrumSeries``. All arguments are
        passed through to the :class:`VoxelPowerSpectrumSeries` constructor.
        """

        VoxelPowerSpectrumSeries.__init__(self, overlay, overlayList,
                                          displayCtx, plotPanel)

        # Separate DataSeries for the imaginary/
        # magnitude/phase signals, returned by
        # the extraSeries method
        self.__imagps = ImaginaryPowerSpectrumSeries(self, overlay,
                                                     overlayList, displayCtx,
                                                     plotPanel)
        self.__magps = MagnitudePowerSpectrumSeries(self, overlay, overlayList,
                                                    displayCtx, plotPanel)
        self.__phaseps = PhasePowerSpectrumSeries(self, overlay, overlayList,
                                                  displayCtx, plotPanel)

        for ps in (self.__imagps, self.__magps, self.__phaseps):
            ps.colour = fslcm.randomDarkColour()
            ps.bindProps('alpha', self)
            ps.bindProps('lineWidth', self)
            ps.bindProps('lineStyle', self)
Exemple #7
0
    def __doImport(self):

        import wx

        frame = wx.GetApp().GetTopWindow()

        # Ask the user where to get the data
        msg = strings.messages[self, 'selectFile']
        fromDir = fslsettings.read('loadSaveOverlayDir', os.getcwd())
        dlg = wx.FileDialog(frame,
                            message=msg,
                            defaultDir=fromDir,
                            style=wx.FD_OPEN)

        if dlg.ShowModal() != wx.ID_OK:
            return

        filePath = dlg.GetPath()
        fileName = op.basename(filePath)

        # Load the file, show an
        # error if it fails
        try:

            # Assuming that the data series
            # to plot are stored as columns
            data = np.loadtxt(filePath, dtype=np.float).T

            # Make sure the data is 2D, to
            # make code below easier and
            # happier.
            if len(data.shape) == 1:
                data = data.reshape((1, -1))

        except Exception as e:
            title = strings.titles[self, 'error']
            msg = strings.messages[self, 'error'].format(
                filePath, '{}: {}'.format(type(e).__name__, str(e)))

            wx.MessageBox(msg, title, wx.ICON_ERROR | wx.OK)
            return

        fslsettings.write('loadSaveOverlayDir', filePath)

        # Ask the user the x axis scaling factor.
        # If the currently selected overlay is
        # Nifti and 4D, default to its pixdim[3]
        overlay = self.__displayCtx.getSelectedOverlay()

        if overlay is not None                 and \
           isinstance(overlay, fslimage.Nifti) and \
           len(overlay.shape) == 4             and \
           self.__plotPanel.usePixdim:
            xscale = overlay.pixdim[3]

        else:
            xscale = 1

        title = strings.titles[self, 'selectXScale']
        msg = strings.messages[self, 'selectXScale']

        # If the user pushes 'Ok', the entered value
        # is used as a fixed X axis interval. Otherwise,
        # it is assumed that the first column in the
        # file is the x axis data.
        dlg = numdlg.NumberDialog(frame,
                                  title=title,
                                  message=msg,
                                  initial=xscale,
                                  minValue=1e-5,
                                  cancelText=strings.labels[self,
                                                            'firstColumnIsX'])

        firstColumnIsX = dlg.ShowModal() != wx.ID_OK
        xscale = dlg.GetValue()

        # Add the data series
        series = []

        if firstColumnIsX:
            xdata = data[0, :]
            ydata = data[1:, :]
        else:
            xdata = np.arange(0,
                              data.shape[1] * xscale,
                              xscale,
                              dtype=np.float)
            ydata = data

        for i, ydata in enumerate(ydata):

            x = np.array(xdata)
            y = np.array(ydata)
            fin = np.isfinite(x) & np.isfinite(y)
            x = x[fin]
            y = y[fin]

            ds = plotting.DataSeries(None, self.__overlayList,
                                     self.__displayCtx, self.__plotPanel)
            ds.setData(x, y)

            # If we recognise the file name,
            # we can give it a useful label.
            label = strings.plotLabels.get('{}.{}'.format(fileName, i),
                                           '{} [{}]'.format(fileName, i))

            ds.label = label
            ds.lineWidth = 1
            ds.colour = fslcm.randomDarkColour()

            series.append(ds)

        self.__plotPanel.dataSeries.extend(series)