コード例 #1
0
ファイル: flux_editor.py プロジェクト: OSUPychron/pychron
    def _rebuild_hole_vs_j(self, x, y, r, reg):
        g = Graph()
        self.graph = g

        p = g.new_plot(xtitle='Hole (Theta)',
                       ytitle='J',
                       padding=[90, 5, 5, 40])

        p.y_axis.tick_label_formatter = lambda x: floatfmt(x, n=2, s=3)

        xs = arctan2(x, y)
        ys = reg.ys
        yserr = reg.yserr

        scatter, _ = g.new_series(xs, ys,
                                  yerror=yserr,
                                  type='scatter', marker='circle')

        ebo = ErrorBarOverlay(component=scatter,
                              orientation='y')
        scatter.overlays.append(ebo)
        self._add_inspector(scatter)

        a = max((abs(min(xs)), abs(max(xs))))

        fxs = linspace(-a, a)

        a = r * sin(fxs)
        b = r * cos(fxs)
        pts = vstack((a, b)).T

        fys = reg.predict(pts)

        g.new_series(fxs, fys)
        g.set_x_limits(-3.2, 3.2)
コード例 #2
0
ファイル: patterns.py プロジェクト: OSUPychron/pychron
    def _graph_factory(self, **kw):
        g = Graph(
            window_height=250,
            window_width=300,
            container_dict=dict(padding=0))
        g.new_plot(
            bounds=[250, 250],
            resizable='',
            padding=[30, 0, 0, 30])

        cx = self.cx
        cy = self.cy
        cbx = self.xbounds
        cby = self.ybounds
        tr = self.target_radius

        g.set_x_limits(*cbx)
        g.set_y_limits(*cby)

        lp, _plot = g.new_series()
        t = TargetOverlay(component=lp,
                          cx=cx,
                          cy=cy,
                          target_radius=tr)

        lp.overlays.append(t)
        overlap_overlay = OverlapOverlay(component=lp,
                                         visible=self.show_overlap)
        lp.overlays.append(overlap_overlay)

        self._graph_factory_hook(lp)

        g.new_series(type='scatter', marker='circle')
        g.new_series(type='line', color='red')
        return g
コード例 #3
0
ファイル: csv_grapher.py プロジェクト: NMGRL/pychron
    def _gc(self, p, det, kind):
        g = Graph(container_dict=dict(padding=5), window_width=1000, window_height=800, window_x=40, window_y=20)
        with open(p, "r") as rfile:
            # gather data
            reader = csv.reader(rfile)
            header = reader.next()
            groups = self._parse_data(reader)
            """
                groups= [data,]
                data shape = nrow,ncols
                
            """
            data = groups[0]
            x = data[0]
            y = data[header.index(det)]

        sy = smooth(y, window_len=120)  # , window='flat')

        x = x[::50]
        y = y[::50]
        sy = sy[::50]

        # smooth

        # plot
        g.new_plot(zoom=True, xtitle="Time (s)", ytitle="{} Baseline Intensity (fA)".format(det))
        g.new_series(x, y, type=kind, marker="dot", marker_size=2)
        g.new_series(x, sy, line_width=2)
        #        g.set_x_limits(500, 500 + 60 * 30)
        #        g.edit_traits()
        return g
コード例 #4
0
ファイル: patterns.py プロジェクト: stephen-e-cox/pychron
    def _graph_factory(self, **kw):
        g = Graph(
            window_height=250,
            window_width=300,
            container_dict=dict(padding=0))
        g.new_plot(
            bounds=[250, 250],
            resizable='',
            padding=[30, 0, 0, 30])

        cx = self.cx
        cy = self.cy
        cbx = self.xbounds
        cby = self.ybounds
        tr = self.target_radius

        g.set_x_limits(*cbx)
        g.set_y_limits(*cby)

        lp, _plot = g.new_series()
        t = TargetOverlay(component=lp,
                          cx=cx,
                          cy=cy,
                          target_radius=tr)

        lp.overlays.append(t)
        overlap_overlay = OverlapOverlay(component=lp,
                                         visible=self.show_overlap)
        lp.overlays.append(overlap_overlay)

        self._graph_factory_hook(lp)

        g.new_series(type='scatter', marker='circle')
        g.new_series(type='line', color='red')
        return g
コード例 #5
0
    def _graph_factory(self):
        graph = Graph(container_dict=dict(padding=5, bgcolor='lightgray'))

        graph.new_plot(
            padding=[50, 5, 5, 50],
            #                       title='{}'.format(self.title),
            xtitle='CDD Operating Voltage (V)',
            ytitle='Intensity (fA)',
        )
        graph.new_series(type='scatter', marker='pixel')
        return graph
コード例 #6
0
    def _execute_power_calibration_check(self):
        """

        """
        g = Graph()
        g.new_plot()
        g.new_series()
        g.new_series(x=[0, 100], y=[0, 100], line_style='dash')
        do_later(self._open_graph, graph=g)

        self._stop_signal = TEvent()
        callback = lambda pi, r: None
        self._iterate(self.check_parameters, g, False, callback)
コード例 #7
0
    def _graph_factory(self):
        graph = Graph(container_dict=dict(padding=5,
                                          bgcolor='lightgray'))

        graph.new_plot(
                       padding=[50, 5, 5, 50],
#                       title='{}'.format(self.title),
                       xtitle='CDD Operating Voltage (V)',
                       ytitle='Intensity (fA)',
                       )
        graph.new_series(type='scatter',
                         marker='pixel')
        return graph
コード例 #8
0
    def _graph_factory(self):
        g = Graph(window_title='Coincidence Scan',
                  container_dict=dict(padding=5, bgcolor='lightgray')
                  )
        g.new_plot(padding=[50, 5, 5, 50],
                   ytitle='Intensity (fA)',
                   xtitle='Operating Voltage (V)')

        for di in self.spectrometer.detectors:
            g.new_series(
                         name=di.name,
                         color=di.color)

        return g
コード例 #9
0
    def _graph_factory(self):
        g = Graph(window_title='Coincidence Scan',
                  container_dict=dict(padding=5, bgcolor='lightgray')
                  )
        g.new_plot(padding=[50, 5, 5, 50],
                   ytitle='Intensity (fA)',
                   xtitle='Operating Voltage (V)')

        for di in self.spectrometer.detectors:
            g.new_series(
                         name=di.name,
                         color=di.color)

        return g
コード例 #10
0
    def _graph_factory(self):
        gc = self.graph_cnt
        cnt = '' if not gc else gc
        self.graph_cnt += 1
        name = self.parent.name if self.parent else 'Foo'

        g = Graph(window_title='{} Power Calibration {}'.format(name, cnt),
                  container_dict=dict(padding=5),
                  window_x=500 + gc * 25,
                  window_y=25 + gc * 25)

        g.new_plot(xtitle='Setpoint (%)', ytitle='Measured Power (W)')
        g.new_series()
        return g
コード例 #11
0
ファイル: peak_center.py プロジェクト: sgallet/pychron
    def _graph_factory(self, graph=None):
        if graph is None:
            graph = Graph(container_dict=dict(padding=5, bgcolor='lightgray'))

        graph.new_plot(
            padding=[50, 5, 5, 50],
            #                       title='{}'.format(self.title),
            xtitle='DAC (V)',
            ytitle='Intensity (fA)',
            show_legend='ul',
            legend_kw=dict(font='modern 8', line_spacing=1))

        graph.new_series(line_width=2)

        graph.set_series_label('*{}'.format(self.reference_detector))
        self._markup_idx = 1
        spec = self.spectrometer
        for di in self.additional_detectors:
            det = spec.get_detector(di)
            c = det.color
            graph.new_series(line_color=c)
            graph.set_series_label(di)
            self._markup_idx += 1

        graph.new_series(type='scatter',
                         marker='circle',
                         marker_size=4,
                         color='green')
        graph.new_series(type='scatter',
                         marker='circle',
                         marker_size=4,
                         color='green')

        #graph.plots[0].value_range.tight_bounds = False
        return graph
コード例 #12
0
    def _execute_power_calibration_check(self):
        '''
        
        '''
        g = Graph()
        g.new_plot()
        g.new_series()
        g.new_series(x=[0, 100], y=[0, 100], line_style='dash')
        do_later(self._open_graph, graph=g)

        self._stop_signal = TEvent()
        callback = lambda pi, r: None
        self._iterate(self.check_parameters,
                      g, False, callback)
コード例 #13
0
    def __init__(self, *args, **kw):
        super(Scanner, self).__init__(*args, **kw)
        graph = Graph()
        self.graph = graph

        p = graph.new_plot(padding_top=30, padding_right=10)

        self._add_bounds(p)
        self._add_mftable_overlay(p)
        self._add_limit_tool(p)
        p.index_range.on_trait_change(self._handle_xbounds_change, 'updated')
        # graph.set_x_limits(self.min_dac, self.max_dac)
        graph.new_series()
        graph.set_x_title('Magnet DAC (Voltage)')
        graph.set_y_title('Intensity')

        self._use_mftable_limits_fired()
コード例 #14
0
ファイル: scanner.py プロジェクト: OSUPychron/pychron
    def __init__(self, *args, **kw):
        super(Scanner, self).__init__(*args, **kw)
        graph = Graph()
        self.graph = graph

        p = graph.new_plot(padding_top=30, padding_right=10)

        self._add_bounds(p)
        self._add_mftable_overlay(p)
        self._add_limit_tool(p)
        p.index_range.on_trait_change(self._handle_xbounds_change, 'updated')
        # graph.set_x_limits(self.min_dac, self.max_dac)
        graph.new_series()
        graph.set_x_title('Magnet DAC (Voltage)')
        graph.set_y_title('Intensity')

        self._use_mftable_limits_fired()
コード例 #15
0
    def _graph_factory(self):
        gc = self.graph_cnt
        cnt = '' if not gc else gc
        self.graph_cnt += 1
        name = self.parent.name if self.parent else 'Foo'

        g = Graph(window_title='{} Power Calibration {}'.format(name, cnt),
                               container_dict=dict(padding=5),
                               window_x=500 + gc * 25,
                               window_y=25 + gc * 25
                               )

        g.new_plot(
                   xtitle='Setpoint (%)',
                   ytitle='Measured Power (W)')
        g.new_series()
        return g
コード例 #16
0
ファイル: seek_tester.py プロジェクト: NMGRL/pychron
 def _pos_graph_default(self):
     g = Graph()
     p = g.new_plot()
     s, p = g.new_series()
     cp = CurrentPointOverlay(component=s)
     s.overlays.append(cp)
     self._cp = cp
     return g
コード例 #17
0
ファイル: seek_tester.py プロジェクト: ael-noblegas/pychron
 def _pos_graph_default(self):
     g = Graph()
     p = g.new_plot()
     s, p = g.new_series()
     cp = CurrentPointOverlay(component=s)
     s.overlays.append(cp)
     self._cp = cp
     return g
コード例 #18
0
ファイル: autofocus_manager.py プロジェクト: NMGRL/pychron
    def passive_focus(self, block=False, **kw):

        self._evt_autofocusing = TEvent()
        self._evt_autofocusing.clear()
#        manager = self.laser_manager
        oper = self.parameters.operator
        self.info('passive focus. operator = {}'.format(oper))

        g = self.graph
        if not g:
            g = Graph(plotcontainer_dict=dict(padding=10),
                      window_x=0.70,
                      window_y=20,
                      window_width=325,
                      window_height=325,
                      window_title='Autofocus'
                      )
            self.graph = g

        g.clear()

        g.new_plot(padding=[40, 10, 10, 40],
                   xtitle='Z (mm)',
                   ytitle='Focus Measure ({})'.format(oper)
                   )
        g.new_series()
        g.new_series()

        invoke_in_main_thread(self._open_graph)

        target = self._passive_focus
        self._passive_focus_thread = Thread(name='autofocus', target=target,
                                            args=(self._evt_autofocusing,

                                                  ),
                                            kwargs=kw
                                            )
        self._passive_focus_thread.start()
        if block:
#             while 1:
#                 if not self._passive_focus_thread.isRunning():
#                     break
#                 time.sleep(0.25)
            self._passive_focus_thread.join()
コード例 #19
0
ファイル: patterns.py プロジェクト: sgallet/pychron
    def _graph_factory(self, with_image=False):
        g = Graph(window_height=250,
                  window_width=300,
                  container_dict=dict(padding=0))
        g.new_plot(bounds=[250, 250], resizable='', padding=[30, 0, 0, 30])

        cx = self.cx
        cy = self.cy
        cbx = self.xbounds
        cby = self.ybounds
        tr = self.target_radius

        #        if with_image:
        #            px = self.pxpermm  #px is in mm
        #            cbx, cby = self._get_crop_bounds()
        #            #g.set_axis_traits(tick_label_formatter=lambda x: '{:0.2f}'.format((x - w / 2) / px))
        #            #g.set_axis_traits(tick_label_formatter=lambda x: '{:0.2f}'.format((x - h / 2) / px), axis='y')
        #
        #            bx, by = g.plots[0].bounds
        #            g.plots[0].x_axis.mapper = LinearMapper(high_pos=bx,
        #                                                    range=DataRange1D(low_setting=self.xbounds[0],
        #                                                                      high_setting=self.xbounds[1]))
        #            g.plots[0].y_axis.mapper = LinearMapper(high_pos=by,
        #                                                    range=DataRange1D(low_setting=self.ybounds[0],
        #                                                                      high_setting=self.ybounds[1]))
        #            cx += self.image_width / 2
        #            cy += self.image_height / 2
        #            tr *= px

        g.set_x_limits(*cbx)
        g.set_y_limits(*cby)

        lp, _plot = g.new_series()
        t = TargetOverlay(component=lp, cx=cx, cy=cy, target_radius=tr)

        lp.overlays.append(t)
        overlap_overlay = OverlapOverlay(component=lp,
                                         visible=self.show_overlap)
        lp.overlays.append(overlap_overlay)

        g.new_series(type='scatter', marker='circle')
        g.new_series(type='line', color='red')
        return g
コード例 #20
0
ファイル: scan_line.py プロジェクト: jirhiker/pychron
    def graph(poly, opoly, line):
        from pychron.graph.graph import Graph

        g = Graph()
        g.new_plot()

        for po in (poly, opoly):
            po = np.array(po)
            try:
                xs, ys = po.T
            except ValueError:
                xs, ys, _ = po.T
            xs = np.hstack((xs, xs[0]))
            ys = np.hstack((ys, ys[0]))
            g.new_series(xs, ys)

        #    for i, (p1, p2) in enumerate(lines):
        #        xi, yi = (p1[0], p2[0]), (p1[1], p2[1])
        #        g.new_series(xi, yi, color='black')
        return g
コード例 #21
0
ファイル: scan_line.py プロジェクト: waffle-iron/pychron
    def graph(poly, opoly, line):
        from pychron.graph.graph import Graph

        g = Graph()
        g.new_plot()

        for po in (poly, opoly):
            po = np.array(po)
            try:
                xs, ys = po.T
            except ValueError:
                xs, ys, _ = po.T
            xs = np.hstack((xs, xs[0]))
            ys = np.hstack((ys, ys[0]))
            g.new_series(xs, ys)

    #    for i, (p1, p2) in enumerate(lines):
    #        xi, yi = (p1[0], p2[0]), (p1[1], p2[1])
    #        g.new_series(xi, yi, color='black')
        return g
コード例 #22
0
    def passive_focus(self, block=False, **kw):

        self._evt_autofocusing = TEvent()
        self._evt_autofocusing.clear()
        #        manager = self.laser_manager
        oper = self.parameters.operator
        self.info('passive focus. operator = {}'.format(oper))

        g = self.graph
        if not g:
            g = Graph(plotcontainer_dict=dict(padding=10),
                      window_x=0.70,
                      window_y=20,
                      window_width=325,
                      window_height=325,
                      window_title='Autofocus')
            self.graph = g

        g.clear()

        g.new_plot(padding=[40, 10, 10, 40],
                   xtitle='Z (mm)',
                   ytitle='Focus Measure ({})'.format(oper))
        g.new_series()
        g.new_series()

        invoke_in_main_thread(self._open_graph)

        target = self._passive_focus
        self._passive_focus_thread = Thread(name='autofocus',
                                            target=target,
                                            args=(self._evt_autofocusing, ),
                                            kwargs=kw)
        self._passive_focus_thread.start()
        if block:
            #             while 1:
            #                 if not self._passive_focus_thread.isRunning():
            #                     break
            #                 time.sleep(0.25)
            self._passive_focus_thread.join()
コード例 #23
0
ファイル: patterns.py プロジェクト: jirhiker/pychron
    def _graph_factory(self, with_image=False):
        g = Graph(window_height=250, window_width=300, container_dict=dict(padding=0))
        g.new_plot(bounds=[250, 250], resizable="", padding=[30, 0, 0, 30])

        cx = self.cx
        cy = self.cy
        cbx = self.xbounds
        cby = self.ybounds
        tr = self.target_radius

        #        if with_image:
        #            px = self.pxpermm  #px is in mm
        #            cbx, cby = self._get_crop_bounds()
        #            #g.set_axis_traits(tick_label_formatter=lambda x: '{:0.2f}'.format((x - w / 2) / px))
        #            #g.set_axis_traits(tick_label_formatter=lambda x: '{:0.2f}'.format((x - h / 2) / px), axis='y')
        #
        #            bx, by = g.plots[0].bounds
        #            g.plots[0].x_axis.mapper = LinearMapper(high_pos=bx,
        #                                                    range=DataRange1D(low_setting=self.xbounds[0],
        #                                                                      high_setting=self.xbounds[1]))
        #            g.plots[0].y_axis.mapper = LinearMapper(high_pos=by,
        #                                                    range=DataRange1D(low_setting=self.ybounds[0],
        #                                                                      high_setting=self.ybounds[1]))
        #            cx += self.image_width / 2
        #            cy += self.image_height / 2
        #            tr *= px

        g.set_x_limits(*cbx)
        g.set_y_limits(*cby)

        lp, _plot = g.new_series()
        t = TargetOverlay(component=lp, cx=cx, cy=cy, target_radius=tr)

        lp.overlays.append(t)
        overlap_overlay = OverlapOverlay(component=lp, visible=self.show_overlap)
        lp.overlays.append(overlap_overlay)

        g.new_series(type="scatter", marker="circle")
        g.new_series(type="line", color="red")
        return g
コード例 #24
0
    def _graph_default(self):
        g = Graph(container_dict=dict(padding=5,

                                      kind='h'))
        g.new_plot(xtitle='weight (mg)', ytitle='40Ar* (fA)',
                   padding=[60, 20, 60, 60]
#                   padding=60
                   )

        g.new_series()
        g.new_plot(xtitle='40Ar* (fA)', ytitle='%Error in Age',
                   padding=[30, 30, 60, 60]
                   )
        g.new_series()
#        fp = create_line_plot(([], []), color='red')
#        left, bottom = add_default_axes(fp)
#        bottom.visible = False
#        left.orientation = 'right'
#        left.axis_line_visible = False
#        bottom.axis_line_visible = False
#        left.visible = False

#        if self.kind == 'weight':
#            bottom.visible = True
#            bottom.orientation = 'top'
#            bottom.title = 'Error (ka)'
#            bottom.tick_color = 'red'
#            bottom.tick_label_color = 'red'
#            bottom.line_color = 'red'
#            bottom.title_color = 'red'
#        else:
#            left.title = 'Weight (mg)'
#        fp.visible = False
#        gd = GuideOverlay(fp, value=0.01, orientation='v')
#        fp.overlays.append(gd)
#        g.plots[0].add(fp)
#        self.secondary_plot = fp

        return g
コード例 #25
0
    def _graph_default(self):
        g = Graph(container_dict=dict(padding=5,

                                      kind='h'))
        g.new_plot(xtitle='weight (mg)', ytitle='40Ar* (fA)',
                   padding=[60, 20, 60, 60]
#                   padding=60
                   )

        g.new_series()
        g.new_plot(xtitle='40Ar* (fA)', ytitle='%Error in Age',
                   padding=[30, 30, 60, 60]
                   )
        g.new_series()
#        fp = create_line_plot(([], []), color='red')
#        left, bottom = add_default_axes(fp)
#        bottom.visible = False
#        left.orientation = 'right'
#        left.axis_line_visible = False
#        bottom.axis_line_visible = False
#        left.visible = False

#        if self.kind == 'weight':
#            bottom.visible = True
#            bottom.orientation = 'top'
#            bottom.title = 'Error (ka)'
#            bottom.tick_color = 'red'
#            bottom.tick_label_color = 'red'
#            bottom.line_color = 'red'
#            bottom.title_color = 'red'
#        else:
#            left.title = 'Weight (mg)'
#        fp.visible = False
#        gd = GuideOverlay(fp, value=0.01, orientation='v')
#        fp.overlays.append(gd)
#        g.plots[0].add(fp)
#        self.secondary_plot = fp

        return g
コード例 #26
0
    def _finish_calibration(self):
        super(FusionsCO2PowerCalibrationManager, self)._finish_calibration()
        g = Graph()
        g.new_plot()

        # plot W vs 8bit dac
        x = self.graph.get_data(axis=1)
        _, y = self.graph.get_aux_data()

        xf = self.graph.get_data(axis=1, series=2)
        _, yf = self.graph.get_aux_data(series=3)

#        print xf
#        print yf
        x, y = zip(*zip(x, y))
        xf, yf = zip(*zip(xf, yf))
        g.new_series(x, y)
        g.new_series(xf, yf)

        self._ipm_coeffs_w_v_r = self._regress(x, y, FITDEGREES['linear'])
        self. _ipm_coeffs_w_v_r1 = self._regress(xf, yf, FITDEGREES['linear'])

        self._open_graph(graph=g)
コード例 #27
0
    def make_component(self, padding):
        cg = ContourGraph()

        cg.new_plot(title='Beam Space',
                    xtitle='X mm',
                    ytitle='Y mm',
                    aspect_ratio=1)

        g = Graph()
        g.new_plot(
            title='Motor Space',
            xtitle='X mm',
            ytitle='Power',
        )
        g.new_series()

        self.graph = g
        self.contour_graph = cg
        c = HPlotContainer()
        c.add(g.plotcontainer)
        c.add(cg.plotcontainer)

        return c
コード例 #28
0
ファイル: csv_grapher.py プロジェクト: waffle-iron/pychron
    def _gc(self, p, det, kind):
        g = Graph(container_dict=dict(padding=5),
                  window_width=1000,
                  window_height=800,
                  window_x=40,
                  window_y=20)
        with open(p, 'r') as rfile:
            # gather data
            reader = csv.reader(rfile)
            header = reader.next()
            groups = self._parse_data(reader)
            '''
                groups= [data,]
                data shape = nrow,ncols
                
            '''
            data = groups[0]
            x = data[0]
            y = data[header.index(det)]

        sy = smooth(y, window_len=120)  # , window='flat')

        x = x[::50]
        y = y[::50]
        sy = sy[::50]

        # smooth

        # plot
        g.new_plot(zoom=True,
                   xtitle='Time (s)',
                   ytitle='{} Baseline Intensity (fA)'.format(det))
        g.new_series(x, y, type=kind, marker='dot', marker_size=2)
        g.new_series(x, sy, line_width=2)
        #        g.set_x_limits(500, 500 + 60 * 30)
        #        g.edit_traits()
        return g
コード例 #29
0
    def _rebuild_hole_vs_j(self, x, y, r, reg):
        g = Graph()
        self.graph = g

        p = g.new_plot(xtitle='Hole (Theta)',
                       ytitle='J',
                       padding=[90, 5, 5, 40])

        p.y_axis.tick_label_formatter = lambda x: floatfmt(x, n=2, s=3)

        xs = arctan2(x, y)
        ys = reg.ys
        yserr = reg.yserr

        scatter, _ = g.new_series(xs,
                                  ys,
                                  yerror=yserr,
                                  type='scatter',
                                  marker='circle')

        ebo = ErrorBarOverlay(component=scatter, orientation='y')
        scatter.overlays.append(ebo)
        self._add_inspector(scatter)

        a = max((abs(min(xs)), abs(max(xs))))

        fxs = linspace(-a, a)

        a = r * sin(fxs)
        b = r * cos(fxs)
        pts = vstack((a, b)).T

        fys = reg.predict(pts)

        g.new_series(fxs, fys)
        g.set_x_limits(-3.2, 3.2)
コード例 #30
0
ファイル: power_mapper.py プロジェクト: UManPychron/pychron
    def make_component(self, padding):
        cg = ContourGraph()

        cg.new_plot(title='Beam Space',
                    xtitle='X mm',
                    ytitle='Y mm',
                    aspect_ratio=1
                    )

        g = Graph()
        g.new_plot(title='Motor Space',
                     xtitle='X mm',
                     ytitle='Power',
                     )
        g.new_series(
                     )

        self.graph = g
        self.contour_graph = cg
        c = HPlotContainer()
        c.add(g.plotcontainer)
        c.add(cg.plotcontainer)

        return c
コード例 #31
0
    def _test(self):

        p = '/Users/ross/Pychrondata_demo/data/snapshots/scan6/007.jpg'
        g = Graph()
        g.new_plot()


        for scan_i, z, idxs in [
#                    1,
#                     2,
#                     3, 4, 5,
#                     (6, [20, 30, 40, 50, 60, 70, 80, 90, 100, ],
#                         [2, 3, 4, 5, 6, 7, 8, 9, 10]
#                      ),
                    (6, [10],
                        [1]
                     ),
#                     (6, [100, 90, 80, 70, 60, 50, 40, 30, 20],
#                         [11, 12, 13, 14, 15, 16, 17, 18, 19]
#                     )

                   ]:
            dxs = []
            zs = []
            root = '/Users/ross/Pychrondata_demo/data/snapshots/scan{}'.format(scan_i)
            for  zi, idx in zip(z, idxs):
                pn = os.path.join(root, '{:03n}.jpg'.format(idx))
                d = load_image(pn)

                dx = self._calculate_spacing(d)
                dxs.append(dx)

                zs.append(zi)

            g.new_series(zs, dxs, type='scatter')

            coeffs = polyfit(zs, dxs, 2)
            print 'parabolic intercept {}'.format(coeffs[-1])

            xs = linspace(0, max(zs))
            ys = polyval(coeffs, xs)
            g.new_series(xs, ys)

            fitfunc = lambda p, x: p[0] * exp(p[1] * x) + p[2]
            lr = LeastSquaresRegressor(fitfunc=fitfunc,
                                       initial_guess=[1, 0.1, 0],
                                       xs=zs,
                                       ys=dxs
                                       )
            xs = linspace(0, max(zs))
            ys = lr.predict(xs)
            print 'exponential intercept {}'.format(lr.predict(0))
            g.new_series(xs, ys)

        invoke_in_main_thread(g.edit_traits)
コード例 #32
0
ファイル: patterns.py プロジェクト: ael-noblegas/pychron
    def _amplitude_graph_factory(self):
        g = Graph()
        p = g.new_plot(show_legend='ul')
        p.index_range.tight_bounds = False
        p.value_range.tight_bounds = False

        x, y, spx, spy = self._calculate_power_series()
        g.new_series(x, y, type='line', color='red')
        g.set_series_label('Power')
        x, y, szx, szy = self._calculate_z_series()
        g.new_series(x, y, type='line', color='blue')
        g.set_series_label('Z')

        g.new_series(spx, spy, type='scatter', color='red')
        g.new_series(szx, szy, type='scatter', color='blue')

        # g.new_series(type='scatter', marker='circle')
        return g
コード例 #33
0
ファイル: patterns.py プロジェクト: NMGRL/pychron
    def _amplitude_graph_factory(self):
        g = Graph()
        p = g.new_plot(show_legend='ul')
        p.index_range.tight_bounds = False
        p.value_range.tight_bounds = False

        x, y, spx, spy = self._calculate_power_series()
        g.new_series(x, y, type='line', color='red')
        g.set_series_label('Power')
        x, y, szx, szy = self._calculate_z_series()
        g.new_series(x, y, type='line', color='blue')
        g.set_series_label('Z')

        g.new_series(spx, spy, type='scatter', color='red')
        g.new_series(szx, szy, type='scatter', color='blue')

        # g.new_series(type='scatter', marker='circle')
        return g
コード例 #34
0
ファイル: zoom_calibration.py プロジェクト: sgallet/pychron
    def _test(self):

        p = '/Users/ross/Pychrondata_demo/data/snapshots/scan6/007.jpg'
        g = Graph()
        g.new_plot()

        for scan_i, z, idxs in [
                #                    1,
                #                     2,
                #                     3, 4, 5,
                #                     (6, [20, 30, 40, 50, 60, 70, 80, 90, 100, ],
                #                         [2, 3, 4, 5, 6, 7, 8, 9, 10]
                #                      ),
            (6, [10], [1]),
                #                     (6, [100, 90, 80, 70, 60, 50, 40, 30, 20],
                #                         [11, 12, 13, 14, 15, 16, 17, 18, 19]
                #                     )
        ]:
            dxs = []
            zs = []
            root = '/Users/ross/Pychrondata_demo/data/snapshots/scan{}'.format(
                scan_i)
            for zi, idx in zip(z, idxs):
                pn = os.path.join(root, '{:03n}.jpg'.format(idx))
                d = load_image(pn)

                dx = self._calculate_spacing(d)
                dxs.append(dx)

                zs.append(zi)

            g.new_series(zs, dxs, type='scatter')

            coeffs = polyfit(zs, dxs, 2)
            print 'parabolic intercept {}'.format(coeffs[-1])

            xs = linspace(0, max(zs))
            ys = polyval(coeffs, xs)
            g.new_series(xs, ys)

            fitfunc = lambda p, x: p[0] * exp(p[1] * x) + p[2]
            lr = LeastSquaresRegressor(fitfunc=fitfunc,
                                       initial_guess=[1, 0.1, 0],
                                       xs=zs,
                                       ys=dxs)
            xs = linspace(0, max(zs))
            ys = lr.predict(xs)
            print 'exponential intercept {}'.format(lr.predict(0))
            g.new_series(xs, ys)

        invoke_in_main_thread(g.edit_traits)
コード例 #35
0
        def _graph_default(self):
            g = Graph()
            p = g.new_plot()
            txt = 'gooiooi \N{Plus-minus sign} \N{Greek Small Letter Sigma} \u03AE \u00ae \u00a3'
            txt2 = 'aaaaaa \xb1 \u00b1'

            pl = PlotLabel(txt,
                           overlay_position='inside bottom',
                           font='Helvetica 12')
            pl2 = PlotLabel(txt2,
                            x=100,
                            y=100,
                            overlay_position='inside bottom',
                            font='Helvetica 24')

            s, p = g.new_series([1, 2, 3, 4, 5, 6], [10, 21, 34, 15, 133, 1])
            s.overlays.append(pl)
            s.overlays.append(pl2)
            return g
コード例 #36
0
ファイル: peak_center.py プロジェクト: jirhiker/pychron
    def _graph_factory(self, graph=None):
        if graph is None:
            graph = Graph(
                container_dict=dict(padding=5,
                                    bgcolor='lightgray'))

        graph.new_plot(
            padding=[50, 5, 5, 50],
            #                       title='{}'.format(self.title),
            xtitle='DAC (V)',
            ytitle='Intensity (fA)',
            show_legend='ul',
            legend_kw=dict(
                font='modern 8',
                line_spacing=1))

        graph.new_series(line_width=2)

        graph.set_series_label('*{}'.format(self.reference_detector))
        self._markup_idx = 1
        spec = self.spectrometer
        for di in self.additional_detectors:
            det = spec.get_detector(di)
            c = det.color
            graph.new_series(line_color=c)
            graph.set_series_label(di)
            self._markup_idx += 1

        graph.new_series(type='scatter', marker='circle',
                         marker_size=4,
                         color='green')
        graph.new_series(type='scatter', marker='circle',
                         marker_size=4,
                         color='green')

        #graph.plots[0].value_range.tight_bounds = False
        return graph
コード例 #37
0
                  scale='log'):
        i = 1
        while 1:
            if data_low < data_high:
                break
            data_low = min(10**-i, data_low)
            i += 1

        oticks = super(SparseLogTicks,
                       self).get_ticks(data_low,
                                       data_high,
                                       bounds_low,
                                       bounds_high,
                                       interval,
                                       use_endpoints=use_endpoints,
                                       scale=scale)
        ticks = oticks[oticks > data_low]

        return ticks


if __name__ == '__main__':
    g = Graph()
    pp = g.new_plot()
    g.new_series([1, 2, 3, 4, 5, 6, 7], [-1, 1, 10, 20, 30, 80, 105])

    pp.value_scale = 'log'
    pp.value_axis.tick_generator = SparseLogTicks()
    g.configure_traits()
# ============= EOF =============================================
コード例 #38
0
from numpy import *

d = os.path.dirname(os.getcwd())
sys.path.append(d)

from pychron.core.ui import set_toolkit

set_toolkit('qt4')

from pychron.graph.graph import Graph
from pychron.graph.tools.limits_tool import LimitsTool, LimitOverlay

xs = linspace(0, pi * 2)
ys = cos(xs)

g = Graph()
p = g.new_plot()
g.new_series(xs, ys)

t = LimitsTool(component=p)
o = LimitOverlay(component=p, tool=t)
p.tools.append(t)
p.overlays.append(o)

t = LimitsTool(component=p, orientation='y')
o = LimitOverlay(component=p, tool=t)
p.tools.append(t)
p.overlays.append(o)

g.configure_traits()
コード例 #39
0
    def _execute_seek(self, controller, pattern):
        from pychron.core.ui.gui import invoke_in_main_thread
        from pychron.graph.graph import Graph

        duration = pattern.duration
        g = Graph()
        g.edit_traits()
        g.new_plot()
        s, p = g.new_series()

        g.new_plot()
        g.new_series(type='line')

        cp = CurrentPointOverlay(component=s)
        s.overlays.append(cp)
        w = 2
        g.set_x_limits(-w, w)
        g.set_y_limits(-w, w)
        om = 60
        g.set_x_limits(max_=om, plotid=1)

        lm = self.laser_manager
        sm = lm.stage_manager

        st = time.time()

        def update_graph(zs, zz, xx, yy):
            cp.point = (xx, yy)
            g.add_datum((xx, yy), plotid=0)
            t = time.time() - st
            g.add_datum((t, zz), update_y_limits=True, plotid=1)

            g.add_datum((t, ) * len(zs),
                        zs,
                        update_y_limits=True,
                        plotid=1,
                        series=1)
            g.set_x_limits(max_=max(om, t + 10), plotid=1)
            g.redraw()

        pp = os.path.join(paths.data_dir, 'seek_pattern.txt')
        with open(pp, 'w') as wfile:
            cx, cy = pattern.cx, pattern.cy
            wfile.write('{},{}\n'.format(cx, cy))
            wfile.write('#z,     x,     y,     n\n')
            gen = pattern.point_generator()
            for x, y in gen:
                if not self._alive:
                    break

                with PeriodCTX(1):
                    # x, y = gen.next()
                    # x, y = pattern.next_point
                    controller.linear_move(cx + x,
                                           cy + y,
                                           block=False,
                                           velocity=pattern.velocity)

                    mt = time.time()
                    zs = []
                    while sm.moving():
                        _, _, v = sm.get_brightness()
                        zs.append(v)

                    while 1:
                        if time.time() - mt > duration:
                            break
                        _, _, v = sm.get_brightness()
                        zs.append(v)

                    if zs:
                        n = len(zs)
                        z = sum(zs) / float(n)
                        self.debug('XY:({},{}) Z:{}, N:{}'.format(x, y, z, n))
                        pattern.set_point(z, x, y)

                        wfile.write('{:0.5f},{:0.3f},{:0.3f},{}\n'.format(
                            z, x, y, n))

                        invoke_in_main_thread(update_graph, zs, z, x, y)
        g.close_ui()
コード例 #40
0
ファイル: scan_line.py プロジェクト: waffle-iron/pychron
    if use_convex_hull:
        poly = convex_hull(poly)
        xs, ys = poly.T
        cx, cy = xs.mean(), ys.mean()
        P = poly.T
        xs = np.hstack((xs, xs[0]))
        ys = np.hstack((ys, ys[0]))
    else:
        xs, ys = poly.T
        xs = np.hstack((xs, xs[0]))
        ys = np.hstack((ys, ys[0]))

    cx, cy = xs.mean(), ys.mean()

    # plot original
    g.new_series(xs, ys)
    g.set_x_limits(min(xs), max(xs), pad='0.1')
    g.set_y_limits(min(ys), max(ys), pad='0.1')
    for ps in npoints:
        for i in range(0, len(ps), 2):
            p1, p2 = ps[i], ps[i + 1]
            g.new_series((p1[0], p2[0]),
                         (p1[1], p2[1]), color='black')

    # plot offset polygon

#    poly = sort_clockwise(poly, poly)
    opoly = polygon_offset(poly, -500)
    if use_convex_hull:
        opoly = convex_hull(opoly)
        xs, ys, _ = opoly.T
コード例 #41
0
    def _graph_grid(self, x, y, z, ze, r, reg, refresh):
        self.min_j = min(z)
        self.max_j = max(z)

        g = self.graph
        layout = FigureLayout(fixed='square')
        nrows, ncols = layout.calculate(len(x))

        if not isinstance(g, Graph):
            g = Graph(container_dict={'bgcolor': 'gray',
                                      'kind': 'g',
                                      'shape': (nrows, ncols)})
            self.graph = g

        def get_ip(xi, yi):
            return next(
                (ip for ip in self.monitor_positions if ((ip.x - xi) ** 2 + (ip.y - yi) ** 2) ** 0.5 < 0.01), None)

        opt = self.plotter_options
        monage = opt.monitor_age * 1e6
        lk = opt.lambda_k
        ans = self._analyses[0]
        scale = opt.flux_scalar
        for r in range(nrows):
            for c in range(ncols):
                idx = c + ncols * r

                if refresh:
                    try:
                        yy = z[idx] * scale
                        ye = ze[idx] * scale
                    except IndexError:
                        continue
                    if hasattr(g, 'rules'):
                        l1, l2, l3 = g.rules[idx]
                        l1.value = yy
                        l2.value = yy + ye
                        l3.value = yy - ye
                        g.refresh()

                else:
                    plot = g.new_plot(padding_left=65, padding_right=5, padding_top=30, padding_bottom=5)
                    try:
                        ip = get_ip(x[idx], y[idx])
                    except IndexError:
                        continue

                    add_axes_tools(g, plot)
                    yy = z[idx] * scale
                    ye = ze[idx] * scale
                    plot.title = 'Identifier={} Position={}'.format(ip.identifier, ip.hole_id)

                    plot.x_axis.visible = False
                    if c == 0 and r == nrows // 2:
                        plot.y_axis.title = 'J x{}'.format(scale)

                    if not ip.use:
                        continue

                    # get ip via x,y
                    ais = [a for a in ans if a.irradiation_position == ip.hole_id]
                    n = len(ais)

                    # plot mean value
                    l1 = g.add_horizontal_rule(yy, color='black', line_style='solid', plotid=idx)
                    l2 = g.add_horizontal_rule(yy + ye, plotid=idx)
                    l3 = g.add_horizontal_rule(yy - ye, plotid=idx)
                    if hasattr(g, 'rules'):
                        g.rules.append((l1, l2, l3))
                    else:
                        g.rules = [(l1, l2, l3)]

                    # plot individual analyses
                    fs = [a.model_j(monage, lk) * scale for a in ais]
                    fs = sorted(fs)
                    iys = array([nominal_value(fi) for fi in fs])
                    ies = array([std_dev(fi) for fi in fs])

                    s, _p = g.new_series(linspace(0, n - 1, n), iys, yerror=ies, type='scatter',
                                         marker='circle', marker_size=3)
                    g.set_x_limits(0, n - 1, pad='0.1', plotid=idx)
                    g.set_y_limits(min(iys - ies), max(iys + ies), pad='0.1', plotid=idx)

                    ebo = ErrorBarOverlay(component=s, orientation='y')
                    s.underlays.append(ebo)
                    s.error_bars = ebo

                    add_analysis_inspector(s, ais)
                    s.index.on_trait_change(self._grid_update_graph_metadata(ais), 'metadata_changed')
                    self.suppress_metadata_change = True
                    sel = [i for i, a in enumerate(ais) if a.is_omitted()]
                    s.index.metadata['selections'] = sel
                    self.suppress_metadata_change = False
コード例 #42
0
    def _graph_hole_vs_j(self, x, y, r, reg, refresh):

        sel = [i for i, a in enumerate(self.analyses) if a.is_omitted()]

        g = self.graph
        if not isinstance(g, Graph):
            g = Graph(container_dict={'bgcolor': self.plotter_options.bgcolor})
            self.graph = g

        po = self.plotter_options

        xs = arctan2(x, y)
        ys = reg.ys
        a = max((abs(min(xs)), abs(max(xs))))
        fxs = linspace(-a, a)

        a = r * sin(fxs)
        b = r * cos(fxs)
        pts = vstack((a, b)).T

        fys = reg.predict(pts)
        yserr = reg.yserr
        l, u = reg.calculate_error_envelope([[p] for p in pts], rmodel=fys)

        lyy = ys - yserr
        uyy = ys + yserr

        if not refresh:
            g.clear()
            p = g.new_plot(xtitle='Hole (Theta)',
                           ytitle='J',
                           # padding=[90, 5, 5, 40],
                           padding=po.paddings())
            p.bgcolor = po.plot_bgcolor

            p.y_axis.tick_label_formatter = lambda x: floatfmt(x, n=2, s=4, use_scientific=True)

            scatter, _ = g.new_series(xs, ys,
                                      yerror=yserr,
                                      type='scatter', marker='circle')

            ebo = ErrorBarOverlay(component=scatter,
                                  orientation='y')
            scatter.overlays.append(ebo)
            scatter.error_bars = ebo

            add_inspector(scatter, self._additional_info)
            line, _p = g.new_series(fxs, fys)

            ee = ErrorEnvelopeOverlay(component=line,
                                      xs=fxs, lower=l, upper=u)
            line.error_envelope = ee
            line.overlays.append(ee)

            # plot the individual analyses
            s, iys = self._graph_individual_analyses()
            s.index.metadata['selections'] = sel
            # s.index.metadata_changed = True

            ymi = min(lyy.min(), min(iys))
            yma = max(uyy.max(), max(iys))
            g.set_x_limits(-3.2, 3.2)

        else:
            plot = g.plots[0]

            s1 = plot.plots['plot0'][0]
            s1.yerror.set_data(yserr)
            s1.error_bars.invalidate()

            l1 = plot.plots['plot1'][0]
            l1.error_envelope.trait_set(xs=fxs, lower=l, upper=u)
            l1.error_envelope.invalidate()

            g.set_data(ys, plotid=0, series=0, axis=1)
            g.set_data(fys, plotid=0, series=1, axis=1)

            s2 = plot.plots['plot2'][0]
            iys = s2.value.get_data()
            ymi = min(fys.min(), lyy.min(), iys.min())
            yma = max(fys.max(), uyy.max(), iys.max())

            s2.index.metadata['selections'] = sel

        g.set_y_limits(ymi, yma, pad='0.1')
        self._model_sin_flux(fxs, fys)
コード例 #43
0

d = os.path.dirname(os.getcwd())
sys.path.append(d)

from pychron.core.ui import set_toolkit

set_toolkit('qt4')

from pychron.graph.graph import Graph
from pychron.graph.tools.limits_tool import LimitsTool, LimitOverlay


xs = linspace(0, pi * 2)
ys = cos(xs)

g = Graph()
p = g.new_plot()
g.new_series(xs, ys)

t = LimitsTool(component=p)
o = LimitOverlay(component=p, tool=t)
p.tools.append(t)
p.overlays.append(o)

t = LimitsTool(component=p, orientation='y')
o = LimitOverlay(component=p, tool=t)
p.tools.append(t)
p.overlays.append(o)

g.configure_traits()
コード例 #44
0
ファイル: dead_time.py プロジェクト: sgallet/pychron
        x = range(1, 6)
        ratios1 = []
        errs1 = []
        for i in KEYS:
            m1, e1 = d._calculate_mean_ratio(nshots[i + '40'], nshots[i + '36cor'])
            ratios1.append(m1)
            errs1.append(e1)

        ms1 = calculate_mswd(ratios1, errs1)

        mswds1.append(ms1)

        rratios1.append(ratios1)

        if tau % 5 == 0:
            g.new_series(x, ratios1, plotid=1, type='line')
            i = int((tau / 5) - 1)
        #            g.set_series_label('p', plotid=1, series=i)
        #            g.set_series_label('{} (ns)'.format(tau), plotid=1, series=i)


        #    g.plots[1].legend.plots = dict([(k, v[0]) for k, v in g.plots[1].plots.iteritems()])
        #    print g.plots[1].legend.plots
    g.new_series(taus, mswds1, plotid=0, type='line_scatter')
    g.set_y_limits(min(mswds1) - 5, max(mswds1) + 5, plotid=0)

    # fit parabola and find minimum.
    coeffs1 = polyfit(taus, mswds1, 2)
    # min at dy=0   (ax2+bx+c)dx=dy==2ax+b
    # 2ax+b=0 , x=-b/(2a)
    dt = -coeffs1[1] / (2 * coeffs1[0])
コード例 #45
0
    def _execute_seek(self, controller, pattern):
        from pychron.core.ui.gui import invoke_in_main_thread
        from pychron.graph.graph import Graph

        duration = pattern.duration
        g = Graph()
        g.edit_traits()
        g.new_plot()
        s, p = g.new_series()

        g.new_plot()
        g.new_series(type='line')

        cp = CurrentPointOverlay(component=s)
        s.overlays.append(cp)
        w = 2
        g.set_x_limits(-w, w)
        g.set_y_limits(-w, w)
        om = 60
        g.set_x_limits(max_=om, plotid=1)

        lm = self.laser_manager
        sm = lm.stage_manager

        st = time.time()

        def update_graph(zs, zz, xx, yy):
            cp.point = (xx, yy)
            g.add_datum((xx, yy), plotid=0)
            t = time.time() - st
            g.add_datum((t, zz),
                        update_y_limits=True,
                        plotid=1)

            g.add_datum((t,) * len(zs), zs,
                        update_y_limits=True,
                        plotid=1, series=1)
            g.set_x_limits(max_=max(om, t + 10), plotid=1)
            g.redraw()

        pp = os.path.join(paths.data_dir, 'seek_pattern.txt')
        with open(pp, 'w') as wfile:
            cx, cy = pattern.cx, pattern.cy
            wfile.write('{},{}\n'.format(cx, cy))
            wfile.write('#z,     x,     y,     n\n')
            gen = pattern.point_generator()
            for x, y in gen:
                if not self._alive:
                    break

                with PeriodCTX(1):
                    # x, y = gen.next()
                    # x, y = pattern.next_point
                    controller.linear_move(cx + x, cy + y, block=False, velocity=pattern.velocity)

                    mt = time.time()
                    zs = []
                    while sm.moving():
                        _, _, v = sm.get_brightness()
                        zs.append(v)

                    while 1:
                        if time.time() - mt > duration:
                            break
                        _, _, v = sm.get_brightness()
                        zs.append(v)

                    if zs:
                        n = len(zs)
                        z = sum(zs) / float(n)
                        self.debug('XY:({},{}) Z:{}, N:{}'.format(x, y, z, n))
                        pattern.set_point(z, x, y)

                        wfile.write('{:0.5f},{:0.3f},{:0.3f},{}\n'.format(z, x, y, n))

                        invoke_in_main_thread(update_graph, zs, z, x, y)
        g.close_ui()
コード例 #46
0
    def _graph_hole_vs_j(self, x, y, r, reg, refresh):

        if self._individual_analyses_enabled:
            sel = [
                i for i, (a, x, y, e) in enumerate(zip(*self._analyses))
                if a.is_omitted()
            ]

        g = self.graph
        if not isinstance(g, Graph):
            g = Graph(container_dict={'bgcolor': self.plotter_options.bgcolor})
            self.graph = g

        po = self.plotter_options

        ys = reg.ys
        xs = arctan2(x, y)

        yserr = reg.yserr
        lyy = ys - yserr
        uyy = ys + yserr
        a = max((abs(min(xs)), abs(max(xs))))
        fxs = linspace(-a, a, 200)

        a = r * sin(fxs)
        b = r * cos(fxs)
        pts = vstack((a, b)).T
        fys = reg.predict(pts)

        use_ee = False
        if po.model_kind not in (MATCHING, BRACKETING, NN):
            use_ee = True
            try:
                l, u = reg.calculate_error_envelope(fxs, rmodel=fys)
            except BaseException:
                l, u = reg.calculate_error_envelope(pts, rmodel=fys)

        if not refresh:
            g.clear()
            p = g.new_plot(
                xtitle='Hole (Theta)',
                ytitle='J',
                # padding=[90, 5, 5, 40],
                padding=po.get_paddings())
            p.bgcolor = po.plot_bgcolor

            add_axes_tools(g, p)

            def label_fmt(xx):
                return floatfmt(xx, n=2, s=4, use_scientific=True)

            p.y_axis.tick_label_formatter = label_fmt

            # plot fit line
            # plot0 == line

            if po.model_kind in (MATCHING, BRACKETING, NN):
                g.new_series(fxs, fys, render_style='connectedhold')
            else:
                line, _p = g.new_series(fxs, fys)
                if use_ee:
                    ee = ErrorEnvelopeOverlay(component=line,
                                              xs=fxs,
                                              lower=l,
                                              upper=u)
                    line.error_envelope = ee
                    line.underlays.append(ee)

            miy = 100
            may = -1

            if self._individual_analyses_enabled:
                # plot the individual analyses
                # plot1 == scatter
                iscatter, iys = self._graph_individual_analyses()
                miy = min(iys)
                may = max(iys)

            # plot means
            # plot2 == scatter
            scatter, _ = g.new_series(xs,
                                      ys,
                                      yerror=yserr,
                                      type='scatter',
                                      marker_size=4,
                                      marker='diamond')

            ebo = ErrorBarOverlay(component=scatter, orientation='y')
            scatter.underlays.append(ebo)
            scatter.error_bars = ebo

            add_inspector(scatter, self._additional_info)

            ymi = min(lyy.min(), miy)
            yma = max(uyy.max(), may)
            g.set_x_limits(-3.5, 3.5)
            g.set_y_limits(ymi, yma, pad='0.1')

            if self._individual_analyses_enabled:
                # set metadata last because it will trigger a refresh
                self.suppress_metadata_change = True
                iscatter.index.metadata['selections'] = sel
                self.suppress_metadata_change = False

            if self._individual_analyses_enabled:
                # add a legend
                labels = [
                    ('plot1', 'Individual'),
                    ('plot2', 'Mean'),
                    ('plot0', 'Fit'),
                ]
            else:
                labels = [('plot0', 'Mean')]

            legend = ExplicitLegend(plots=self.graph.plots[0].plots,
                                    labels=labels)
            p.overlays.append(legend)

        else:
            plot = g.plots[0]
            s1 = plot.plots['plot2'][0]
            s1.yerror.set_data(yserr)
            s1.error_bars.invalidate()

            g.set_data(ys, plotid=0, series=2, axis=1)

            l1 = plot.plots['plot0'][0]
            l1.index.metadata['selections'] = sel
            g.set_data(fys, plotid=0, series=0, axis=1)

            if use_ee:
                l1.error_envelope.trait_set(xs=fxs, lower=l, upper=u)
                l1.error_envelope.invalidate()

        self.max_j = fys.max()
        self.min_j = fys.min()
コード例 #47
0
    def _graph_hole_vs_j(self, x, y, r, reg, refresh):

        sel = [i for i, (a, x, y, e) in enumerate(zip(*self._analyses)) if a.is_omitted()]
        g = self.graph
        if not isinstance(g, Graph):
            g = Graph(container_dict={'bgcolor': self.plotter_options.bgcolor})
            self.graph = g

        po = self.plotter_options
        is_matching = po.model_kind == 'Matching'

        ys = reg.ys
        xs = arctan2(x, y)

        yserr = reg.yserr
        lyy = ys - yserr
        uyy = ys + yserr
        a = max((abs(min(xs)), abs(max(xs))))
        fxs = linspace(-a, a)

        a = r * sin(fxs)
        b = r * cos(fxs)
        pts = vstack((a, b)).T
        fys = reg.predict(pts)

        if not is_matching:
            try:
                l, u = reg.calculate_error_envelope(fxs, rmodel=fys)
            except BaseException:
                l, u = reg.calculate_error_envelope(pts, rmodel=fys)

        if not refresh:
            g.clear()
            p = g.new_plot(xtitle='Hole (Theta)',
                           ytitle='J',
                           # padding=[90, 5, 5, 40],
                           padding=po.paddings())
            p.bgcolor = po.plot_bgcolor

            add_axes_tools(g, p)

            def label_fmt(xx):
                return floatfmt(xx, n=2, s=4, use_scientific=True)

            p.y_axis.tick_label_formatter = label_fmt

            # plot fit line
            # plot0 == line
            if not is_matching:
                line, _p = g.new_series(fxs, fys)

                ee = ErrorEnvelopeOverlay(component=line,
                                          xs=fxs, lower=l, upper=u)
                line.error_envelope = ee
                line.underlays.append(ee)

            # plot the individual analyses
            # plot1 == scatter
            iscatter, iys = self._graph_individual_analyses()

            # plot means
            # plot2 == scatter
            scatter, _ = g.new_series(xs, ys,
                                      yerror=yserr,
                                      type='scatter',
                                      marker_size=4, marker='diamond')

            ebo = ErrorBarOverlay(component=scatter,
                                  orientation='y')
            scatter.underlays.append(ebo)
            scatter.error_bars = ebo

            add_inspector(scatter, self._additional_info)

            ymi = min(lyy.min(), min(iys))
            yma = max(uyy.max(), max(iys))
            g.set_x_limits(-3.5, 3.5)
            g.set_y_limits(ymi, yma, pad='0.1')

            # set metadata last because it will trigger a refresh
            self.suppress_metadata_change = True
            iscatter.index.metadata['selections'] = sel
            self.suppress_metadata_change = False

            # add a legend
            if not is_matching:
                labels = [('plot1', 'Individual'),
                          ('plot2', 'Mean'),
                          ('plot0', 'Fit'),
                          ]
            else:
                labels = [('plot0', 'Individual'),
                          ('plot1', 'Mean')]

            legend = ExplicitLegend(plots=self.graph.plots[0].plots,
                                    labels=labels)
            p.overlays.append(legend)

        else:
            plot = g.plots[0]

            s1 = plot.plots['plot1' if is_matching else 'plot2'][0]
            s1.yerror.set_data(yserr)
            s1.error_bars.invalidate()

            g.set_data(ys, plotid=0, series=1 if is_matching else 2, axis=1)

            if not is_matching:
                l1 = plot.plots['plot0'][0]
                l1.error_envelope.trait_set(xs=fxs, lower=l, upper=u)
                l1.error_envelope.invalidate()
                g.set_data(fys, plotid=0, series=0, axis=1)

            s2 = plot.plots['plot1' if is_matching else 'plot0'][0]
            s2.index.metadata['selections'] = sel

        self.max_j = fys.max()
        self.min_j = fys.min()
コード例 #48
0
ファイル: scan_line.py プロジェクト: jirhiker/pychron
    if use_convex_hull:
        poly = convex_hull(poly)
        xs, ys = poly.T
        cx, cy = xs.mean(), ys.mean()
        P = poly.T
        xs = np.hstack((xs, xs[0]))
        ys = np.hstack((ys, ys[0]))
    else:
        xs, ys = poly.T
        xs = np.hstack((xs, xs[0]))
        ys = np.hstack((ys, ys[0]))

    cx, cy = xs.mean(), ys.mean()

    # plot original
    g.new_series(xs, ys)
    g.set_x_limits(min(xs), max(xs), pad="0.1")
    g.set_y_limits(min(ys), max(ys), pad="0.1")
    for ps in npoints:
        for i in range(0, len(ps), 2):
            p1, p2 = ps[i], ps[i + 1]
            g.new_series((p1[0], p2[0]), (p1[1], p2[1]), color="black")

    # plot offset polygon

    #    poly = sort_clockwise(poly, poly)
    opoly = polygon_offset(poly, -500)
    if use_convex_hull:
        opoly = convex_hull(opoly)
        xs, ys, _ = opoly.T
        xs = np.hstack((xs, xs[0]))