示例#1
0
    def _graph_factory(self, **kw):
        from pychron.graph.stacked_regression_graph import StackedRegressionGraph

        g = StackedRegressionGraph(container_dict=dict(
            stack_order='top_to_bottom', use_backbuffer=True, spacing=5),
                                   **kw)
        return g
示例#2
0
 def _graph_factory(self):
     return StackedRegressionGraph(container_dict=dict(padding=5, bgcolor='gray',
                                                       stack_order=self.stack_order,
                                                       spacing=5),
                                   bind_index=False,
                                   use_data_tool=False,
                                   padding_bottom=35)
示例#3
0
 def setup_graph(self):
     cd = dict(padding=20, spacing=5, stack_order='top_to_bottom')
     g = StackedRegressionGraph(container_dict=cd)
     self.graph = g
     self.refresh_plot()
示例#4
0
    def show_blank_time_series(self):
        g = StackedRegressionGraph(window_height=0.75)
        isotopes = self.blank_selected[0].isotopes
        keys = sort_isotopes([iso.isotope for iso in isotopes], reverse=False)
        _mi, _ma = None, None

        for k in keys:
            iso = next((i for i in isotopes if i.isotope == k))
            # print iso.analyses
            g.new_plot(padding_right=10)
            g.set_time_xaxis()
            g.set_y_title(iso.isotope)

            g.new_series([self.timestamp], [iso.value],
                         marker_size=3,
                         fit=False,
                         type='scatter',
                         marker_color='black')
            vs = iso.values
            if vs:
                ts = [vi.timestamp for vi in vs]
                _mi = min(ts)
                _ma = max(ts)
                g.new_series(ts, [vi.value for vi in vs],
                             yerror=ArrayDataSource([vi.error for vi in vs]),
                             marker_size=3,
                             fit=(iso.fit, 'SD'),
                             type='scatter',
                             marker_color='red')

        if not _mi:
            _mi, _ma = self.timestamp - 86400, self.timestamp + 86400

        g.set_x_limits(_mi, _ma, pad='0.1')
        g.refresh()

        g.set_x_title('Time', plotid=0)
        g.edit_traits()
示例#5
0
    def handle_show_iso_evo(self, obj):
        from pychron.graph.stacked_regression_graph import StackedRegressionGraph

        self.manager.load_raw_data(self.model)

        g = StackedRegressionGraph()
        for ni in obj[::-1]:
            iso = next((i for i in self.model.isotopes.itervalues()
                        if i.name == ni.name), None)
            g.new_plot(padding=[60, 10, 10, 40])
            g.new_series(iso.xs,
                         iso.ys,
                         fit=iso.fit,
                         filter_outliers_dict=iso.filter_outliers_dict)
            g.set_x_limits(min_=0, max_=iso.xs[-1] * 1.1)
            g.set_x_title('Time (s)')
            g.set_y_title(iso.name)

        g.refresh()
        g.window_title = '{} {}'.format(self.name,
                                        ','.join([i.name for i in obj]))
        self.manager.application.open_view(g)
示例#6
0
def show_evolutions_factory(record_id, isotopes, show_evo=True, show_equilibration=False, show_baseline=False):
    if WINDOW_CNT > 20:
        information(None, 'You have too many Isotope Evolution windows open. Close some before proceeding')
        return

    from pychron.graph.stacked_regression_graph import StackedRegressionGraph

    if not show_evo:
        xmi = Inf
        xma = -Inf
    else:
        xmi, xma = 0, -Inf

    g = StackedRegressionGraph(resizable=True)
    g.plotcontainer.spacing = 10
    g.window_height = min(275 * len(isotopes), 800)
    g.window_x = OX + XOFFSET * WINDOW_CNT
    g.window_y = OY + YOFFSET * WINDOW_CNT

    isotopes = sort_isotopes(isotopes, reverse=False, key=lambda x: x.name)

    for i, iso in enumerate(isotopes):
        ymi, yma = Inf, -Inf

        p = g.new_plot(padding=[80, 10, 10, 40])
        g.add_limit_tool(p, 'x')
        g.add_limit_tool(p, 'y')
        g.add_axis_tool(p, p.x_axis)
        g.add_axis_tool(p, p.y_axis)

        p.y_axis.title_spacing = 50
        if show_equilibration:
            sniff = iso.sniff
            g.new_series(sniff.xs, sniff.ys,
                         type='scatter',
                         fit=None,
                         color='red')
            ymi, yma = min_max(ymi, yma, sniff.ys)
            xmi, xma = min_max(xmi, xma, sniff.xs)

        if show_evo:
            g.new_series(iso.xs, iso.ys,
                         fit=iso.fit,
                         filter_outliers_dict=iso.filter_outliers_dict,
                         color='black')
            ymi, yma = min_max(ymi, yma, iso.ys)
            xmi, xma = min_max(xmi, xma, iso.xs)

        if show_baseline:
            baseline = iso.baseline
            g.new_series(baseline.xs, baseline.ys,
                         type='scatter', fit=baseline.fit,
                         filter_outliers_dict=baseline.filter_outliers_dict,
                         color='blue')
            ymi, yma = min_max(ymi, yma, baseline.ys)
            xmi, xma = min_max(xmi, xma, baseline.xs)

        g.set_x_limits(min_=xmi, max_=xma, pad='0.025,0.05')
        g.set_y_limits(min_=ymi, max_=yma, pad='0.05', plotid=i)
        g.set_x_title('Time (s)', plotid=i)
        g.set_y_title('{} (fA)'.format(iso.name), plotid=i)

    g.refresh()
    g.window_title = '{} {}'.format(record_id, ','.join([i.name for i in reversed(isotopes)]))

    return g
示例#7
0
    def _show_plot(self, data):
        cd = dict(padding=5, stack_order='top_to_bottom')
        csnames = self.column_names
        xmin = np.Inf
        xmax = -np.Inf

        if self.as_series:
            g = RegressionGraph(container_dict=cd)
            p = g.new_plot(padding=[50, 5, 5, 50],
                           xtitle=''
            )
            p.value_range.tight_bounds = False
            p.value_range.margin = 0.1
        else:
            g = StackedRegressionGraph(container_dict=cd)

        regressable = False
        #        metadata = None
        for i, csi in enumerate(self.data_selectors):
            if not self.as_series:
                p = g.new_plot(padding=[50, 5, 5, 50])
                p.value_range.tight_bounds = False
                p.value_range.margin = 0.1
                plotid = i
            else:
                plotid = 0

            try:
                x = data[csnames.index(csi.index)]
                y = data[csnames.index(csi.value)]
                xmin = min(xmin, min(x))
                xmax = max(xmax, max(x))
                fit = csi.fit if csi.fit != NULL_STR else None
                g.new_series(x, y, fit=fit,
                             filter_outliers=csi.use_filter,
                             type=csi.plot_type,
                             plotid=plotid)

                g.set_x_title(csi.index, plotid=plotid)
                g.set_y_title(csi.value, plotid=plotid)
                if fit:
                    regressable = True

            except IndexError:
                pass

        g.set_x_limits(xmin, xmax, pad='0.1')

        self._graph_count += 1
        if regressable:
            gg = StatsGraph(graph=g)
            gii = gg
        else:
            gii = g

        g._update_graph()

        def show(gi):
            gi.window_title = '{} Graph {}'.format(self.short_name, self._graph_count)
            gi.window_x = self._graph_count * 20 + 400
            gi.window_y = self._graph_count * 20 + 20
            gi.edit_traits()

        show(gii)
示例#8
0
def show_evolutions_factory(record_id,
                            isotopes,
                            show_evo=True,
                            show_equilibration=False,
                            show_baseline=False,
                            show_statistics=False,
                            ncols=1,
                            scale_to_equilibration=False):
    if WINDOW_CNT > 20:
        information(
            None,
            'You have too many Isotope Evolution windows open. Close some before proceeding'
        )
        return

    if not show_evo:
        xmi = Inf
        xma = -Inf
    else:
        xmi, xma = 0, -Inf

    if ncols > 1:
        isotopes = sort_isotopes(isotopes,
                                 reverse=True,
                                 key=attrgetter('name'))

        def reorder(l, n):
            l = [l[i:i + n] for i in range(0, len(l), n)]
            nl = []
            for ri in range(len(l[0])):
                for col in l:
                    try:
                        nl.append(col[ri])
                    except IndexError:
                        pass
            return nl

        nrows = ceil(len(isotopes) / ncols)
        isotopes = reorder(isotopes, nrows)
        g = ColumnStackedRegressionGraph(resizable=True,
                                         ncols=ncols,
                                         nrows=nrows,
                                         container_dict={
                                             'padding_top': 15 * nrows,
                                             'spacing': (0, 15),
                                             'padding_bottom': 40
                                         })
        resizable = 'hv'
    else:
        resizable = 'h'
        isotopes = sort_isotopes(isotopes,
                                 reverse=False,
                                 key=attrgetter('name'))
        g = StackedRegressionGraph(resizable=True,
                                   container_dict={'spacing': 15})

    # g.plotcontainer.spacing = 10
    g.window_height = min(275 * len(isotopes), 800)
    g.window_x = OX + XOFFSET * WINDOW_CNT
    g.window_y = OY + YOFFSET * WINDOW_CNT

    for i, iso in enumerate(isotopes):
        ymi, yma = Inf, -Inf

        p = g.new_plot(padding=[80, 10, 10, 40], resizable=resizable)
        g.add_limit_tool(p, 'x')
        g.add_limit_tool(p, 'y')
        g.add_axis_tool(p, p.x_axis)
        g.add_axis_tool(p, p.y_axis)
        if show_statistics:
            g.add_statistics(i)

        p.y_axis.title_spacing = 50
        if show_equilibration:
            sniff = iso.sniff
            if sniff.xs.shape[0]:
                g.new_series(sniff.offset_xs,
                             sniff.ys,
                             type='scatter',
                             fit=None,
                             color='red')
                ymi, yma = min_max(ymi, yma, sniff.ys)
                xmi, xma = min_max(xmi, xma, sniff.offset_xs)

        if show_evo:
            if iso.fit is None:
                iso.fit = 'linear'

            g.new_series(iso.offset_xs,
                         iso.ys,
                         fit=iso.efit,
                         truncate=iso.truncate,
                         filter_outliers_dict=iso.filter_outliers_dict,
                         color='black')
            g.set_regressor(iso.regressor, i)

            xmi, xma = min_max(xmi, xma, iso.offset_xs)
            if not scale_to_equilibration:
                ymi, yma = min_max(ymi, yma, iso.ys)

        if show_baseline:
            baseline = iso.baseline
            g.new_series(baseline.offset_xs,
                         baseline.ys,
                         type='scatter',
                         fit=baseline.efit,
                         filter_outliers_dict=baseline.filter_outliers_dict,
                         color='blue')
            xmi, xma = min_max(xmi, xma, baseline.offset_xs)
            if not scale_to_equilibration:
                ymi, yma = min_max(ymi, yma, baseline.ys)

        xpad = '0.025,0.05'
        ypad = '0.05'
        if scale_to_equilibration:
            ypad = None
            r = (yma - ymi) * 0.02
            # ymi = yma - r

            fit = iso.fit
            if fit != 'average':
                fit, _ = convert_fit(iso.fit)
                fy = polyval(polyfit(iso.offset_xs, iso.ys, fit), 0)
                if ymi > fy:
                    ymi = fy - r

                fy = polyval(polyfit(iso.offset_xs, iso.ys, fit), xma)
                if fy > yma:
                    yma = fy
                elif fy < ymi:
                    ymi = fy - r

            # yma += r

        g.set_x_limits(min_=xmi, max_=xma, pad=xpad)
        g.set_y_limits(min_=ymi, max_=yma, pad=ypad, plotid=i)

        g.set_x_title('Time (s)', plotid=i)
        g.set_y_title('{} ({})'.format(iso.name, iso.units), plotid=i)

    g.refresh()
    g.window_title = '{} {}'.format(
        record_id, ','.join([i.name for i in reversed(isotopes)]))

    return g
示例#9
0
    def setup_graph(self, iso):
        self.klass = None
        self.pklass = str(self.clf.predict_isotope(iso))

        g = StackedRegressionGraph()
        g.new_plot(padding=[60, 10, 10, 40])
        if iso:
            g.new_series(iso.xs,
                         iso.ys,
                         fit=iso.fit,
                         filter_outliers_dict=iso.filter_outliers_dict)
            g.set_x_limits(min_=0, max_=iso.xs[-1] * 1.1)
            g.set_y_title(iso.name)

        g.set_x_title('Time (s)')

        g.refresh()
        self.graph = g
示例#10
0
def show_evolutions_factory(record_id,
                            isotopes,
                            show_evo=True,
                            show_equilibration=False,
                            show_baseline=False):
    if WINDOW_CNT > 20:
        information(
            None,
            'You have too many Isotope Evolution windows open. Close some before proceeding'
        )
        return

    from pychron.graph.stacked_regression_graph import StackedRegressionGraph

    if not show_evo:
        xmi = Inf
        xma = -Inf
    else:
        xmi, xma = 0, -Inf

    g = StackedRegressionGraph(resizable=True)
    g.plotcontainer.spacing = 10
    g.window_height = min(275 * len(isotopes), 800)
    g.window_x = OX + XOFFSET * WINDOW_CNT
    g.window_y = OY + YOFFSET * WINDOW_CNT

    isotopes = sort_isotopes(isotopes, reverse=False, key=lambda x: x.name)

    for i, iso in enumerate(isotopes):
        ymi, yma = Inf, -Inf

        p = g.new_plot(padding=[80, 10, 10, 40])
        g.add_limit_tool(p, 'x')
        g.add_limit_tool(p, 'y')
        g.add_axis_tool(p, p.x_axis)
        g.add_axis_tool(p, p.y_axis)

        p.y_axis.title_spacing = 50
        if show_equilibration:
            sniff = iso.sniff
            g.new_series(sniff.xs,
                         sniff.ys,
                         type='scatter',
                         fit=None,
                         color='red')
            ymi, yma = min_max(ymi, yma, sniff.ys)
            xmi, xma = min_max(xmi, xma, sniff.xs)

        if show_evo:
            g.new_series(iso.xs,
                         iso.ys,
                         fit=iso.fit,
                         filter_outliers_dict=iso.filter_outliers_dict,
                         color='black')
            ymi, yma = min_max(ymi, yma, iso.ys)
            xmi, xma = min_max(xmi, xma, iso.xs)

        if show_baseline:
            baseline = iso.baseline
            g.new_series(baseline.xs,
                         baseline.ys,
                         type='scatter',
                         fit=baseline.fit,
                         filter_outliers_dict=baseline.filter_outliers_dict,
                         color='blue')
            ymi, yma = min_max(ymi, yma, baseline.ys)
            xmi, xma = min_max(xmi, xma, baseline.xs)

        g.set_x_limits(min_=xmi, max_=xma, pad='0.025,0.05')
        g.set_y_limits(min_=ymi, max_=yma, pad='0.05', plotid=i)
        g.set_x_title('Time (s)', plotid=i)
        g.set_y_title('{} (fA)'.format(iso.name), plotid=i)

    g.refresh()
    g.window_title = '{} {}'.format(
        record_id, ','.join([i.name for i in reversed(isotopes)]))

    return g
示例#11
0
    def setup_graph(self, iso):
        self.is_good = None

        g = StackedRegressionGraph()
        g.new_plot(padding=[60, 10, 10, 40])
        if iso:
            g.new_series(iso.xs, iso.ys,
                         fit=iso.fit,
                         filter_outliers_dict=iso.filter_outliers_dict)
            g.set_x_limits(min_=0, max_=iso.xs[-1] * 1.1)
            g.set_y_title(iso.name)

        g.set_x_title('Time (s)')

        g.refresh()
        self.graph = g
示例#12
0
    def show_blank_time_series(self):
        g = StackedRegressionGraph(window_height=0.75)
        isotopes = self.blank_selected[0].isotopes
        keys = sort_isotopes([iso.isotope for iso in isotopes], reverse=False)
        _mi, _ma = None, None

        for k in keys:
            iso = next((i for i in isotopes if i.isotope == k))
            # print iso.analyses
            g.new_plot(padding_right=10)
            g.set_time_xaxis()
            g.set_y_title(iso.isotope)

            g.new_series([self.timestamp], [iso.value],
                         marker_size=3,
                         fit=False,
                         type='scatter', marker_color='black')
            vs = iso.values
            if vs:
                ts = [vi.timestamp for vi in vs]
                _mi = min(ts)
                _ma = max(ts)
                g.new_series(ts,
                             [vi.value for vi in vs],
                             yerror=ArrayDataSource([vi.error for vi in vs]),
                             marker_size=3,
                             fit=(iso.fit, 'SD'),
                             type='scatter', marker_color='red')

        if not _mi:
            _mi, _ma = self.timestamp - 86400, self.timestamp + 86400

        g.set_x_limits(_mi, _ma, pad='0.1')
        g.refresh()

        g.set_x_title('Time', plotid=0)
        g.edit_traits()
示例#13
0
 def _graph_default(self):
     return StackedRegressionGraph(container_dict=dict(
         stack_order='top_to_bottom'))
示例#14
0
    def setup_graph(self, an):

        container = HPlotContainer()

        sg = StackedGraph()
        sg.plotcontainer.spacing = 5
        sg.plotcontainer.stack_order = 'top_to_bottom'

        isos = an.sorted_values(reverse=False)
        for i, iso in enumerate(isos):
            sniff = iso.sniff
            sg.new_plot(ytitle=iso.name, xtitle='Time (s)', title='Equilibration')
            if sniff.xs.shape[0]:
                sg.new_series(sniff.offset_xs, sniff.ys, marker='circle', type='scatter')
            sg.set_y_limits(pad='0.1', plotid=i)

        bg = StackedRegressionGraph()
        bg.plotcontainer.spacing = 5
        bg.plotcontainer.stack_order = 'top_to_bottom'

        for i, iso in enumerate(isos):
            baseline = iso.baseline
            bg.new_plot(ytitle=baseline.detector, xtitle='Time (s)', title='Baseline')
            if baseline.xs.shape[0]:
                bg.new_series(baseline.offset_xs, baseline.ys,
                              color='red', type='scatter', fit=baseline.fit)
            bg.set_y_limits(pad='0.1', plotid=i)

        ig = StackedRegressionGraph()
        ig.plotcontainer.spacing = 5
        ig.plotcontainer.stack_order = 'top_to_bottom'

        for i, iso in enumerate(isos):
            ig.new_plot(ytitle=iso.name, xtitle='Time (s)', title='Isotope')
            if iso.xs.shape[0]:
                ig.new_series(iso.offset_xs, iso.ys,
                              color='blue', type='scatter', fit=iso.fit)
            ig.set_y_limits(pad='0.1', plotid=i)

        container.add(sg.plotcontainer)
        container.add(ig.plotcontainer)
        container.add(bg.plotcontainer)

        self.container = container
示例#15
0
    def handle_show_iso_evo(self, obj):
        from pychron.graph.stacked_regression_graph import StackedRegressionGraph

        self.manager.load_raw_data(self.model)

        g = StackedRegressionGraph()
        for ni in obj[::-1]:
            iso = next((i for i in self.model.isotopes.itervalues() if i.name == ni.name), None)
            g.new_plot(padding=[60, 10, 10, 40])
            g.new_series(iso.xs, iso.ys,
                         fit=iso.fit,
                         filter_outliers_dict=iso.filter_outliers_dict)
            g.set_x_limits(min_=0, max_=iso.xs[-1] * 1.1)
            g.set_x_title('Time (s)')
            g.set_y_title(iso.name)

        g.refresh()
        g.window_title = '{} {}'.format(self.name, ','.join([i.name for i in obj]))
        self.manager.application.open_view(g)
示例#16
0
    def setup_graph(self, an):

        container = HPlotContainer()

        container_dict = {'spacing': 5, 'stack_order': 'top_to_bottom'}
        sg = StackedGraph(container_dict=container_dict)
        sg.plotcontainer.spacing = 5
        sg.plotcontainer.stack_order = 'top_to_bottom'

        isos = an.sorted_values(reverse=False)
        add_sniff = True

        sisos = [iso for iso in isos if iso.sniff.offset_xs.shape[0]]
        for i, iso in enumerate(sisos):
            sniff = iso.sniff
            sg.new_plot(ytitle=iso.name,
                        xtitle='Time (s)',
                        title='Equilibration')
            sg.new_series(sniff.offset_xs,
                          sniff.ys,
                          marker='circle',
                          type='scatter')
            sg.set_y_limits(pad='0.1', plotid=i)
            sg.set_x_limits(min_=0, max_=max(sniff.offset_xs) * 1.05, plotid=i)

        bg = StackedRegressionGraph(container_dict=container_dict)
        add_baseline = True

        ig = StackedRegressionGraph(container_dict=container_dict)

        iisos = [iso for iso in isos if iso.offset_xs.shape[0]]
        baselines = []
        for i, iso in enumerate(iisos):
            if iso.baseline.offset_xs.shape[0]:
                baselines.append(iso.baseline)
            ig.new_plot(ytitle='{}({})'.format(iso.name, iso.detector),
                        xtitle='Time (s)',
                        title='Isotope')
            ig.new_series(iso.offset_xs,
                          iso.ys,
                          display_filter_bounds=True,
                          filter_outliers_dict=iso.filter_outliers_dict,
                          color='blue',
                          type='scatter',
                          fit=iso.efit)
            ig.set_regressor(iso.regressor, i)
            ig.set_y_limits(pad='0.1', plotid=i)
            ig.set_x_limits(min_=0, max_=max(iso.offset_xs) * 1.05, plotid=i)

        ig.refresh()

        # bisos = [iso for iso in isos if iso.baseline.offset_xs.shape[0]]
        # plotted_baselines = []
        # for i, iso in enumerate(bisos):
        # baseline = iso.baseline
        # if baseline.detector in plotted_baselines:
        #     continue
        # plotted_baselines.append(baseline.detector)

        # for iso in bisos:
        for i, baseline in enumerate(baselines):

            bg.new_plot(ytitle=baseline.detector,
                        xtitle='Time (s)',
                        title='Baseline')
            bg.new_series(baseline.offset_xs,
                          baseline.ys,
                          filter_outliers_dict=baseline.filter_outliers_dict,
                          display_filter_bounds=True,
                          color='red',
                          type='scatter',
                          fit=baseline.efit)
            bg.set_regressor(baseline.regressor, i)
            bg.set_y_limits(pad='0.1', plotid=i)
            bg.set_x_limits(pad='0.025', plotid=i)

        bg.refresh()

        container.add(sg.plotcontainer)
        container.add(ig.plotcontainer)
        container.add(bg.plotcontainer)

        self.container = container