예제 #1
0
    def __createCorrelateOverlay(self, overlay, data):
        """Creates a *correlate* overlay for the given ``overlay``, adds
        it to the :class:`.OverlayList`, and initialises some display
        properties.
        """

        display = self.displayCtx.getDisplay(overlay)
        name = '{}/correlation'.format(display.name)
        corrOvl = fslimage.Image(data, name=name, header=overlay.header)

        self.overlayList.append(corrOvl, overlayType='volume')
        self.__correlateOverlays[overlay] = corrOvl
        self.__overlayCorrelates[corrOvl] = overlay

        corrOpts = self.displayCtx.getOpts(corrOvl)

        with props.suppressAll(corrOpts), \
             props.suppressAll(display):
            corrOpts.cmap = 'red-yellow'
            corrOpts.negativeCmap = 'blue-lightblue'
            corrOpts.useNegativeCmap = True
            corrOpts.displayRange = [0.05, 1]
            corrOpts.clippingRange.xlo = 0.05

        return corrOvl
예제 #2
0
    def __volumeChanged(self, *args, **kwargs):
        """Called when the :attr:`volume` property changes, and also by the
        :meth:`__init__` method.

        Re-calculates some things for the new overlay volume.
        """

        opts = self.__opts
        overlay = self.overlay

        # We cache the following for each volume
        # so they don't need to be recalculated:
        #  - finite data
        #  - non-zero data
        #  - finite minimum
        #  - finite maximum
        #
        # The cache size is restricted (see its
        # creation in __init__) so we don't blow
        # out RAM
        volkey = (opts.volumeDim, opts.volume)
        volprops = self.__volCache.get(volkey, None)

        if volprops is None:
            log.debug('Volume changed {} - extracting '
                      'finite/non-zero data'.format(volkey))
            finData = overlay[opts.index()]
            finData = finData[np.isfinite(finData)]
            nzData = finData[finData != 0]
            dmin = finData.min()
            dmax = finData.max()
            self.__volCache.put(volkey, (finData, nzData, dmin, dmax))
        else:
            log.debug('Volume changed {} - got finite/'
                      'non-zero data from cache'.format(volkey))
            finData, nzData, dmin, dmax = volprops

        dist = (dmax - dmin) / 10000.0

        with props.suppressAll(self):

            self.dataRange.xmin = dmin
            self.dataRange.xmax = dmax + dist
            self.dataRange.xlo = dmin
            self.dataRange.xhi = dmax + dist
            self.nbins = autoBin(nzData, self.dataRange.x)

            self.__finiteData = finData
            self.__nonZeroData = nzData

            self.__dataRangeChanged()

        with props.skip(self, 'dataRange', self.__name):
            self.propNotify('dataRange')
예제 #3
0
    def resetDisplay(self):
        """Resets the :class:`.Scene3DCanvas` camera settings to their
        defaults.
        """

        opts = self.__canvas.opts

        with props.suppressAll(opts):
            opts.zoom     = 75
            opts.offset   = [0, 0]
            opts.rotation = np.eye(3)
        self.__canvas.Refresh()
예제 #4
0
    def __refreshColourBar(self, *a):
        """Called when the :class:`.ColourBarCanvas` needs to be refreshed. """

        cmap            = None
        negativeCmap    = None
        useNegativeCmap = False
        cmapResolution  = 256
        invert          = False
        dmin, dmax      = 0.0, 0.0
        label           = ''

        overlay = self.__selectedOverlay

        if overlay is not None:
            display         = self.displayCtx.getDisplay(overlay)
            opts            = self.displayCtx.getOpts(   overlay)
            cmap            = opts.cmap
            negativeCmap    = opts.negativeCmap
            useNegativeCmap = opts.useNegativeCmap
            cmapResolution  = opts.cmapResolution
            invert          = opts.invert
            dmin, dmax      = opts.displayRange.x
            label           = display.name

        with props.suppressAll(self.__cbCanvas):
            self.__cbCanvas.cmap            = cmap
            self.__cbCanvas.negativeCmap    = negativeCmap
            self.__cbCanvas.useNegativeCmap = useNegativeCmap
            self.__cbCanvas.cmapResolution  = cmapResolution
            self.__cbCanvas.invert          = invert
            self.__cbCanvas.vrange          = dmin, dmax
            self.__cbCanvas.label           = label

        # Using inside knowledge about the
        # ColourBarCanvas here - it will
        # refresh itself on any property
        # change.
        self.__cbCanvas.propNotify('cmap')
예제 #5
0
    def setHistogramData(self, data, key):
        """Must be called by sub-classes whenever the underlying histogram data
        changes.

        :arg data: A ``numpy`` array containing the data that the histogram is
                   to be calculated on. Pass in ``None``  to indicate that
                   there is currently no histogram data.

        :arg key:  Something which identifies the ``data``, and can be used as
                   a ``dict`` key.
        """

        if data is None:
            self.__nvals              = 0
            self.__dataKey            = None
            self.__xdata              = np.array([])
            self.__ydata              = np.array([])
            self.__finiteData         = np.array([])
            self.__nonZeroData        = np.array([])
            self.__clippedFiniteData  = np.array([])
            self.__clippedNonZeroData = np.array([])

            # force the panel to refresh
            with props.skip(self, 'dataRange', self.name):
                self.propNotify('dataRange')
            return

        # We cache the following data, based
        # on the provided key, so they don't
        # need to be recalculated:
        #  - finite data
        #  - non-zero data
        #  - finite minimum
        #  - finite maximum
        #
        # The cache size is restricted (see its
        # creation in __init__) so we don't blow
        # out RAM
        cached = self.__dataCache.get(key, None)

        if cached is None:

            log.debug('New histogram data {} - extracting '
                      'finite/non-zero data'.format(key))

            finData = data[np.isfinite(data)]
            nzData  = finData[finData != 0]
            dmin    = finData.min()
            dmax    = finData.max()

            self.__dataCache.put(key, (finData, nzData, dmin, dmax))
        else:
            log.debug('Got histogram data {} from cache'.format(key))
            finData, nzData, dmin, dmax = cached

        # The upper bound on the dataRange
        # is exclusive, so we initialise it
        # to a bit more than the data max.
        dist = (dmax - dmin) / 10000.0

        with props.suppressAll(self):

            self.dataRange.xmin = dmin
            self.dataRange.xmax = dmax + dist
            self.dataRange.xlo  = dmin
            self.dataRange.xhi  = dmax + dist
            self.nbins          = autoBin(nzData, self.dataRange.x)

            self.__dataKey     = key
            self.__finiteData  = finData
            self.__nonZeroData = nzData

            self.__dataRangeChanged()

        with props.skip(self, 'dataRange', self.name):
            self.propNotify('dataRange')