예제 #1
0
def add_analysis_inspector(scatter, items, add_selection=True, value_format=None, convert_index=None):
    from chaco.tools.broadcaster import BroadcasterTool
    from pychron.graph.tools.rect_selection_tool import RectSelectionTool
    from pychron.graph.tools.rect_selection_tool import RectSelectionOverlay
    from pychron.graph.tools.point_inspector import PointInspectorOverlay

    broadcaster = BroadcasterTool()
    scatter.tools.append(broadcaster)
    if add_selection:
        rect_tool = RectSelectionTool(scatter)
        rect_overlay = RectSelectionOverlay(component=scatter,
                                            tool=rect_tool)

        scatter.overlays.append(rect_overlay)
        broadcaster.tools.append(rect_tool)

    if value_format is None:
        value_format = lambda x: '{:0.5f}'.format(x)

    if convert_index is None:
        convert_index = lambda x: '{:0.3f}'.format(x)

    point_inspector = AnalysisPointInspector(scatter,
                                             analyses=items,
                                             convert_index=convert_index,
                                             # index_tag=index_tag,
                                             # index_attr=index_attr,
                                             value_format=value_format)
    # additional_info=additional_info)

    pinspector_overlay = PointInspectorOverlay(component=scatter,
                                               tool=point_inspector)

    scatter.overlays.append(pinspector_overlay)
    broadcaster.tools.append(point_inspector)
예제 #2
0
파일: graph.py 프로젝트: sgallet/pychron
 def add_point_inspector(self, scatter, convert_index=None):
     point_inspector = PointInspector(scatter, convert_index=convert_index)
     pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                tool=point_inspector)
     #
     scatter.overlays.append(pinspector_overlay)
     scatter.tools.append(point_inspector)
예제 #3
0
    def add_tools(self,
                  plot,
                  scatter,
                  line=None,
                  convert_index=None,
                  add_inspector=True):

        # add a regression inspector tool to the line
        if line:
            tool = RegressionInspectorTool(component=line)
            overlay = RegressionInspectorOverlay(component=line, tool=tool)
            line.tools.append(tool)
            line.overlays.append(overlay)

        broadcaster = BroadcasterTool()
        scatter.tools.append(broadcaster)

        if add_inspector:
            point_inspector = PointInspector(scatter,
                                             convert_index=convert_index
                                             or self.convert_index_func)
            pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                       tool=point_inspector)

            scatter.overlays.append(pinspector_overlay)
            broadcaster.tools.append(point_inspector)

        rect_tool = RectSelectionTool(scatter)
        rect_overlay = RectSelectionOverlay(tool=rect_tool)

        scatter.overlays.append(rect_overlay)
        broadcaster.tools.append(rect_tool)
예제 #4
0
    def _add_scatter_inspector(
            self,
            # container,
            scatter,
            add_tool=True,
            value_format=None,
            additional_info=None):
        if add_tool:
            broadcaster = BroadcasterTool()
            scatter.tools.append(broadcaster)

            rect_tool = RectSelectionTool(scatter)
            rect_overlay = RectSelectionOverlay(component=scatter,
                                                tool=rect_tool)

            scatter.overlays.append(rect_overlay)
            broadcaster.tools.append(rect_tool)

            if value_format is None:
                value_format = lambda x: '{:0.5f}'.format(x)
            point_inspector = AnalysisPointInspector(
                scatter,
                analyses=self.sorted_analyses,
                convert_index=lambda x: '{:0.3f}'.format(x),
                value_format=value_format,
                additional_info=additional_info)

            pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                       tool=point_inspector)

            scatter.overlays.append(pinspector_overlay)
            broadcaster.tools.append(point_inspector)

            u = lambda a, b, c, d: self.update_graph_metadata(a, b, c, d)
            scatter.index.on_trait_change(u, 'metadata_changed')
예제 #5
0
    def _add_inspector(self, scatter, ans):
        broadcaster = BroadcasterTool()
        scatter.tools.append(broadcaster)

        rect_tool = RectSelectionTool(scatter)
        rect_overlay = RectSelectionOverlay(component=scatter, tool=rect_tool)

        scatter.overlays.append(rect_overlay)
        broadcaster.tools.append(rect_tool)

        point_inspector = AnalysisPointInspector(
            scatter,
            value_format=floatfmt,
            analyses=ans,
            convert_index=lambda x: '{:0.3f}'.format(x))

        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)

        scatter.overlays.append(pinspector_overlay)
        scatter.tools.append(point_inspector)
        broadcaster.tools.append(point_inspector)

        scatter.index.on_trait_change(self._update_metadata(ans),
                                      'metadata_changed')
예제 #6
0
    def _add_scatter_inspector(self, scatter, ans, value_format=None):
        broadcaster = BroadcasterTool()
        scatter.tools.append(broadcaster)

        rect_tool = RectSelectionTool(scatter)
        rect_overlay = RectSelectionOverlay(component=scatter, tool=rect_tool)

        scatter.overlays.append(rect_overlay)
        broadcaster.tools.append(rect_tool)

        if value_format is None:
            value_format = lambda x: '{:0.5f}'.format(x)

        # value_format=self._value_info()
        additional_info = self._index_info()
        point_inspector = AnalysisPointInspector(
            scatter,
            analyses=ans,
            convert_index=lambda x: '{:0.3f}'.format(x),
            value_format=value_format,
            additional_info=additional_info)

        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)

        scatter.overlays.append(pinspector_overlay)
        broadcaster.tools.append(point_inspector)
예제 #7
0
    def setup(self, x, y, ans):
        from pychron.pipeline.plot.plotter.ticks import tick_formatter, StaticTickGenerator, TICKS

        p = self.new_plot()
        p.padding_left = 60
        p.y_axis.tick_label_formatter = tick_formatter
        p.y_axis.tick_generator = StaticTickGenerator()
        p.y_axis.title = 'Analysis Type'

        # p.y_grid.line_style='solid'
        # p.y_grid.line_color='green'
        # p.y_grid.line_weight = 1.5

        self.set_y_limits(min_=-1, max_=len(TICKS))

        p.index_range.tight_bounds = False
        p.x_axis.tick_generator = ScalesTickGenerator(
            scale=CalendarScaleSystem())
        p.x_grid.tick_generator = p.x_axis.tick_generator
        p.x_axis.title = 'Time'

        scatter, _ = self.new_series(x,
                                     y,
                                     type='scatter',
                                     marker_size=1.5,
                                     selection_color='red',
                                     selection_marker='circle',
                                     selection_marker_size=2.5)

        broadcaster = BroadcasterTool()
        scatter.tools.append(broadcaster)

        point_inspector = AnalysisPointInspector(
            scatter,
            analyses=ans,
            value_format=get_analysis_type,
            additional_info=lambda i, x, y, ai:
            ('Time={}'.format(ai.rundate), 'Project={}'.format(ai.project)))

        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)

        rect_tool = RectSelectionTool(scatter)
        rect_overlay = RectSelectionOverlay(component=scatter, tool=rect_tool)

        broadcaster.tools.append(rect_tool)
        broadcaster.tools.append(point_inspector)

        # range_selector = RangeSelection(scatter, left_button_selects=True)
        # broadcaster.tools.append(range_selector)

        # scatter.overlays.append(RangeSelectionOverlay(component=scatter))
        scatter.overlays.append(pinspector_overlay)
        scatter.overlays.append(rect_overlay)

        self.scatter = scatter
예제 #8
0
def add_inspector(scatter, func, **kw):
    from pychron.graph.tools.point_inspector import PointInspector
    from pychron.graph.tools.point_inspector import PointInspectorOverlay

    point_inspector = PointInspector(scatter, additional_info=func, **kw)
    pinspector_overlay = PointInspectorOverlay(component=scatter,
                                               tool=point_inspector)

    scatter.overlays.append(pinspector_overlay)
    scatter.tools.append(point_inspector)
예제 #9
0
    def _add_inspector(self, scatter):
        from pychron.graph.tools.point_inspector import PointInspector
        from pychron.graph.tools.point_inspector import PointInspectorOverlay

        point_inspector = PointInspector(scatter)
        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)
        #
        scatter.overlays.append(pinspector_overlay)
        scatter.tools.append(point_inspector)
예제 #10
0
    def _add_inspector(self, scatter, ans):
        point_inspector = AnalysisPointInspector(scatter,
                                                 analyses=ans,
                                                 convert_index=lambda x: '{:0.3f}'.format(x))

        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)

        scatter.overlays.append(pinspector_overlay)
        scatter.tools.append(point_inspector)
        scatter.index.on_trait_change(self._update_metadata(ans), 'metadata_changed')
예제 #11
0
    def _add_inspector(self, scatter, analyses=None):
        if analyses is None:
            analyses = self.analyses
        value_format = lambda x: '{:0.5f}'.format(x)
        point_inspector = AnalysisPointInspector(
            scatter,
            analyses=analyses,
            convert_index=lambda x: '{:0.3f}'.format(x),
            value_format=value_format)
        # additional_info=additional_info)

        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)

        scatter.overlays.append(pinspector_overlay)
        scatter.tools.append(point_inspector)
예제 #12
0
    def _plot_baseline(self, i, iso, p, xma, xmi, yma, ymi):
        xs = iso.baseline.xs
        ys = iso.baseline.ys
        plot, scatter, line = self.graph.new_series(
            xs,
            ys,
            marker=p.marker,
            marker_size=p.marker_size,
            type='scatter',
            plotid=i,
            fit=iso.baseline.fit,
            filter_outliers_dict=iso.baseline.filter_outliers_dict,
            add_tools=False,
            color='black')

        pinspector = PointInspector(scatter, use_pane=False)
        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=pinspector)
        scatter.overlays.append(pinspector_overlay)
        xmi, xma = min_max(xmi, xma, xs)
        ymi, yma = min_max(ymi, yma, ys)
        return xma, xmi, yma, ymi, scatter, pinspector
예제 #13
0
    def _add_scatter_inspector(self,
                               scatter,
                               inspector=None,
                               add_tool=True,
                               add_selection=True,
                               value_format=None,
                               additional_info=None,
                               index_tag=None,
                               index_attr=None,
                               convert_index=None,
                               items=None,
                               update_meta_func=None):
        if add_tool:
            broadcaster = BroadcasterTool()
            scatter.tools.append(broadcaster)
            if add_selection:
                rect_tool = RectSelectionTool(scatter)
                rect_overlay = RectSelectionOverlay(component=scatter,
                                                    tool=rect_tool)

                scatter.overlays.append(rect_overlay)
                broadcaster.tools.append(rect_tool)

            if inspector is None:
                if value_format is None:

                    def value_format(x):
                        return '{:0.5f}'.format(x)

                if convert_index is None:

                    def convert_index(x):
                        return '{:0.3f}'.format(x)

                if items is None:
                    items = self.sorted_analyses
                inspector = AnalysisPointInspector(
                    scatter,
                    use_pane=False,
                    analyses=items,
                    convert_index=convert_index,
                    index_tag=index_tag,
                    index_attr=index_attr,
                    value_format=value_format,
                    additional_info=additional_info)

                pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                           tool=inspector)
                scatter.overlays.append(pinspector_overlay)
                broadcaster.tools.append(inspector)
            else:
                if not isinstance(inspector, (list, tuple)):
                    inspector = (inspector, )

                for i in inspector:
                    broadcaster.tools.append(i)
                    # # pinspector_overlay = PointInspectorOverlay(component=scatter,
                    # #                                            tool=point_inspector)
                    # # print 'fff', inspector
                    #
                    # event_queue = {}
                    # for i in inspector:
                    #     i.event_queue = event_queue
                    #     i.on_trait_change(self._handle_inspection, 'inspector_item')
                    #     # scatter.overlays.append(pinspector_overlay)
                    #     broadcaster.tools.append(i)

            if update_meta_func is None:
                update_meta_func = self.update_graph_metadata
            # u = lambda a, b, c, d: self.update_graph_metadata(a, b, c, d)
            scatter.index.on_trait_change(update_meta_func, 'metadata_changed')
예제 #14
0
    def setup(self, x, y, ans, atypes, mapping):
        from pychron.pipeline.plot.plotter.ticks import StaticTickGenerator

        def get_analysis_type(x):
            x = int(math.floor(x))
            return next((k for k, v in mapping.items() if v == x))

        p = self.new_plot()
        p.padding_left = 200

        def tickformatter(x):
            return atypes[int(x)]

        p.y_axis.tick_label_rotate_angle = 60
        p.y_axis.tick_label_formatter = tickformatter
        p.y_axis.tick_generator = StaticTickGenerator(_nticks=len(atypes))
        p.y_axis.title = 'Analysis Type'
        p.y_axis.title_font = 'modern 18'
        p.y_axis.tick_label_font = 'modern 14'

        self.add_axis_tool(p, p.x_axis)
        self.add_axis_tool(p, p.y_axis)
        self.add_limit_tool(p, 'x')
        self.add_limit_tool(p, 'y')

        self.set_y_limits(min_=-1, max_=len(atypes))

        p.index_range.tight_bounds = False
        p.x_axis.tick_generator = ScalesTickGenerator(
            scale=CalendarScaleSystem())
        p.x_grid.tick_generator = p.x_axis.tick_generator
        p.x_axis.title = 'Time'
        p.x_axis.title_font = 'modern 18'
        p.x_axis.tick_label_font = 'modern 14'

        t = GroupingTool(component=p)
        p.tools.append(t)
        o = GroupingOverlay(component=p, tool=t)
        p.overlays.append(o)

        self.grouping_tool = t

        scatter, _ = self.new_series(x,
                                     y,
                                     type='scatter',
                                     marker_size=1.5,
                                     selection_color='red',
                                     selection_marker='circle',
                                     selection_marker_size=2.5)

        broadcaster = BroadcasterTool()
        scatter.tools.append(broadcaster)

        point_inspector = AnalysisPointInspector(
            scatter,
            analyses=ans,
            value_format=get_analysis_type,
            additional_info=lambda i, x, y, ai:
            ('Time={}'.format(ai.rundate), 'Project={}'.format(ai.project)))

        pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                   tool=point_inspector)

        rect_tool = RectSelectionTool(scatter)
        rect_overlay = RectSelectionOverlay(component=scatter, tool=rect_tool)

        broadcaster.tools.append(rect_tool)
        broadcaster.tools.append(point_inspector)

        scatter.overlays.append(pinspector_overlay)
        scatter.overlays.append(rect_overlay)

        self.scatter = scatter
예제 #15
0
    def _plot(self, i, p):
        ai = self.analyses[0]

        # name is either an isotope "Ar40" or a detector "H1"
        # if its a detector only plot the baseline
        name = p.name

        is_baseline = False
        try:
            iso = ai.isotopes[name]
        except KeyError as e:
            is_baseline = True
            iso = ai.get_isotope(detector=name)
            # iso = next((iso for iso in six.itervalues(ai.isotopes) if iso.detector == name), None)
            if iso is None:
                print('iso_evo _plot', ai.record_id, ai.isotopes_keys, name)
                return

        ymi, yma = Inf, -Inf
        xmi, xma = 0, -Inf
        inspectors = []
        if is_baseline:
            xma, xmi, yma, ymi, scatter, ins = self._plot_baseline(
                i, iso, p, xma, xmi, yma, ymi)
            self._add_scatter_inspector(scatter, inspector=inspectors)
            # print xma, xmi, yma, ymi
        else:
            if self.options.show_sniff:
                # if self.show_sniff:
                xs, ys = iso.sniff.xs, iso.sniff.ys
                scatter, _ = self.graph.new_series(xs,
                                                   ys,
                                                   marker=p.marker,
                                                   marker_size=p.marker_size,
                                                   type='scatter',
                                                   plotid=i,
                                                   fit=None,
                                                   add_inspector=False,
                                                   color='red')
                psinspector = PointInspector(scatter)
                pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                           tool=psinspector)
                scatter.overlays.append(pinspector_overlay)
                inspectors.append(psinspector)

                ymi, yma = min_max(ymi, yma, iso.sniff.ys)
                xmi, xma = min_max(xmi, xma, iso.sniff.xs)

            xs = iso.xs
            ys = iso.ys

            plot, scatter, line = self.graph.new_series(
                xs,
                ys,
                marker=p.marker,
                marker_size=p.marker_size,
                type='scatter',
                plotid=i,
                fit=iso.fit,
                filter_outliers_dict=iso.filter_outliers_dict,
                color='black',
                add_inspector=False)

            pinspector = PointInspector(scatter, use_pane=False)
            pinspector_overlay = PointInspectorOverlay(component=scatter,
                                                       tool=pinspector)
            scatter.overlays.append(pinspector_overlay)
            inspectors.append(pinspector)

            linspector = RegressionInspectorTool(component=line,
                                                 use_pane=False)
            scatter.overlays.append(
                RegressionInspectorOverlay(component=line, tool=linspector))
            inspectors.append(linspector)

            # if psinspector:
            #     inspectors = [linspector, pinspector, psinspector]
            # else:
            #     inspectors = [linspector, pinspector]

            ymi, yma = min_max(ymi, yma, iso.ys)
            xmi, xma = min_max(xmi, xma, iso.xs)

            if self.show_baseline:
                xma, xmi, yma, ymi, scatter, ins = self._plot_baseline(
                    i, iso, p, xma, xmi, yma, ymi)
                inspectors.append(ins)

            self._add_scatter_inspector(scatter, inspector=inspectors)

        self.graph.set_x_limits(min_=xmi, max_=xma * 1.05, plotid=i)
        self.graph.set_y_limits(min_=ymi, max_=yma, pad='0.05', plotid=i)
        self.graph.refresh()