示例#1
0
def _test_ExportDataSeriesAction(panel, overlayList, displayCtx):
    class FileDialog(object):
        ShowModal_return = wx.ID_OK
        GetPath_return = None

        def __init__(self, *a, **kwa):
            pass

        def ShowModal(self):
            return FileDialog.ShowModal_return

        def GetPath(self):
            return FileDialog.GetPath_return

    class MessageDialog(object):
        ShowModal_return = wx.ID_OK

        def __init__(self, *a, **kwa):
            pass

        def ShowModal(self):
            return MessageDialog.ShowModal_return

    displayCtx = panel.displayCtx
    act = eds.ExportDataSeriesAction(overlayList, displayCtx, panel)

    ds1 = ds.DataSeries(None, overlayList, displayCtx, panel)
    ds2 = ds.DataSeries(None, overlayList, displayCtx, panel)
    ds1.setData(np.arange(10), np.random.randint(1, 100, 10))
    ds2.setData(np.arange(10), np.random.randint(1, 100, 10))

    panel.dataSeries.extend((ds1, ds2))
    realYield(500)

    with tempdir.tempdir(), \
         mock.patch('wx.FileDialog', FileDialog), \
         mock.patch('wx.MessageDialog', MessageDialog):

        MessageDialog.ShowModal_return = wx.ID_CANCEL
        act()

        MessageDialog.ShowModal_return = wx.ID_YES
        FileDialog.ShowModal_return = wx.ID_CANCEL
        act()

        MessageDialog.ShowModal_return = wx.ID_NO
        FileDialog.ShowModal_return = wx.ID_OK
        FileDialog.GetPath_return = 'data.txt'
        act()

        assert op.exists('data.txt')
        os.remove('data.txt')

        MessageDialog.ShowModal_return = wx.ID_YES
        FileDialog.ShowModal_return = wx.ID_OK
        FileDialog.GetPath_return = 'data.txt'
        act()
        assert op.exists('data.txt')

    act.destroy()
示例#2
0
    def __addMaskDataSeries(self):
        """Run the ``AddMaskDataSeriesAction``. Prompt the user to select
        a mask, using a :class:`MaskDialog`, then calculates the mean time
        series in that mask, then adds that time series to the
        :class:`.TimeSeriesPanel` that owns this action instance.
        """

        overlay = self.displayCtx.getSelectedOverlay()
        opts    = self.displayCtx.getOpts(overlay)
        options = self.__maskOptions

        frame   = wx.GetApp().GetTopWindow()
        msg     = strings.messages[self, 'selectMask'].format(overlay.name)
        cbmsg   = strings.messages[self, 'weighted']
        title   = strings.titles[  self, 'selectMask'].format(overlay.name)

        dlg = MaskDialog(
            frame,
            [o.name for o in options],
            title=title,
            message=msg,
            checkboxMessage=cbmsg)

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

        maskimg   = options[dlg.GetChoice()]
        weight    = dlg.GetCheckBox()
        ds        = dataseries.DataSeries(overlay,
                                          self.overlayList,
                                          self.displayCtx,
                                          self.__plotPanel)

        data     = overlay.data[opts.index(atVolume=False)]
        mask     = maskimg.data
        maskmask = mask > 0
        ydata    = data[maskmask]

        # Weighted mean
        if weight:
            maskvals = mask[maskmask]
            ydata    = (maskvals * ydata.T).T

        ydata = ydata.mean(axis=0)
        xdata = np.arange(len(ydata))

        ds.colour    = self.__plotPanel.getOverlayPlotColour(overlay)
        ds.lineStyle = self.__plotPanel.getOverlayPlotStyle(overlay)
        ds.lineWidth = 2
        ds.alpha     = 1
        ds.label     = '{} [mask: {}]'.format(overlay.name, maskimg.name)

        # We have to run the data through
        # prepareDataSeries to e.g. scale
        # the x axis by pixdims, and apply
        # other plot settings
        ds.setData(xdata, ydata)
        ds.setData(*self.__plotPanel.prepareDataSeries(ds))

        self.__plotPanel.dataSeries.append(ds)
示例#3
0
    def __addROIHistogram(self):
        """Prompts the user to select an ROI mask, calculates the histogram
        of that mask on the currently selected overlay, and adds the result
        to the ``HistogramPanel``.
        """

        overlay = self.displayCtx.getSelectedOverlay()
        opts = self.displayCtx.getOpts(overlay)
        roiOptions = self.__roiOptions

        frame = wx.GetApp().GetTopWindow()
        msg = strings.messages[self, 'selectMask'].format(overlay.name)
        title = strings.titles[self, 'selectMask'].format(overlay.name)

        dlg = addmaskdataseries.MaskDialog(frame, [o.name for o in roiOptions],
                                           title=title,
                                           message=msg,
                                           checkbox=False)

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

        maskimg = roiOptions[dlg.GetChoice()]
        mask = maskimg[:] > 0

        if overlay.ndim > 3: data = overlay[opts.index()][mask]
        else: data = overlay[mask]

        count = self.__plotPanel.histType == 'count'
        drange = (np.nanmin(data), np.nanmax(data))
        nbins = histogramseries.autoBin(data, drange)
        xdata, ydata, _ = histogramseries.histogram(data,
                                                    nbins,
                                                    drange,
                                                    drange,
                                                    includeOutliers=False,
                                                    count=count)

        ds = dataseries.DataSeries(overlay, self.overlayList, self.displayCtx,
                                   self.__plotPanel)
        ds.colour = self.__plotPanel.getOverlayPlotColour(overlay)
        ds.lineStyle = self.__plotPanel.getOverlayPlotStyle(overlay)
        ds.lineWidth = 2
        ds.alpha = 1
        ds.label = '{} [mask: {}]'.format(overlay.name, maskimg.name)

        # We have to run the data through
        # prepareDataSeries to preprocess
        # (e.g. smooth) it
        ds.setData(xdata, ydata)
        ds.setData(*self.__plotPanel.prepareDataSeries(ds))

        self.__plotPanel.dataSeries.append(ds)