Exemplo n.º 1
0
    def _post_init(PD, Options={}):
        # --- Perform data manipulation on the fly
        #print(Options)
        keys = Options.keys()
        if 'RemoveOutliers' in keys:
            if Options['RemoveOutliers']:
                from pydatview.tools.signal import reject_outliers
                try:
                    PD.x, PD.y = reject_outliers(
                        PD.y, PD.x, m=Options['OutliersMedianDeviation'])
                except:
                    raise Exception(
                        'Warn: Outlier removal failed. Desactivate it or use a different signal. '
                    )
        if 'Filter' in keys:
            if Options['Filter']:
                from pydatview.tools.signal import applyFilter
                PD.y = applyFilter(PD.x, PD.y, Options['Filter'])

        if 'Sampler' in keys:
            if Options['Sampler']:
                from pydatview.tools.signal import applySampler
                PD.x, PD.y = applySampler(PD.x, PD.y, Options['Sampler'])

        # --- Store stats
        n = len(PD.y)
        if n > 1000:
            if (PD.xIsString):
                raise Exception(
                    'Error: x values contain more than 1000 string. This is not suitable for plotting.\n\nPlease select another column for table: {}\nProblematic column: {}\n'
                    .format(PD.st, PD.sx))
            if (PD.yIsString):
                raise Exception(
                    'Error: y values contain more than 1000 string. This is not suitable for plotting.\n\nPlease select another column for table: {}\nProblematic column: {}\n'
                    .format(PD.st, PD.sy))

        PD.needChineseFont = has_chinese_char(PD.sy) or has_chinese_char(PD.sx)
        # Stats of the raw data (computed once and for all, since it can be expensive for large dataset
        PD.computeRange()
        # Store the values of the original data (labelled "0"), since the data might be modified later by PDF or MinMax etc.
        PD._y0Min = PD._yMin
        PD._y0Max = PD._yMax
        PD._x0Min = PD._xMin
        PD._x0Max = PD._xMax
        PD._y0Std = PD.yStd()
        PD._y0Mean = PD.yMean()
        PD._n0 = (n, '{:d}'.format(n))
        PD.x0 = PD.x
        PD.y0 = PD.y
Exemplo n.º 2
0
    def onPlot(self, event=None):
        """ 
        Overlay on current axis the filter
        """
        from pydatview.tools.signal import applyFilter
        if len(self.parent.plotData) != 1:
            Error(self,
                  'Plotting only works for a single plot. Plot less data.')
            return
        filt = self._GUI2Filt()

        PD = self.parent.plotData[0]
        y_filt = applyFilter(PD.x0, PD.y0, filt)
        ax = self.parent.fig.axes[0]

        PD_new = PlotData()
        PD_new.fromXY(PD.x0, y_filt)
        self.parent.transformPlotData(PD_new)
        ax.plot(PD_new.x, PD_new.y, '-')
        self.parent.canvas.draw()