Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
        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])
    print 'dead time1= ', dt

    g.set_x_title('# Airshots', plotid=1)
    g.set_x_title('Dead Time (ns)', plotid=0)

    g.set_y_title('40Ar/36Ar', plotid=1)
    g.set_y_title('MSWD', plotid=0)

    g.add_vertical_rule(dt)
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
        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]))
        ys = np.hstack((ys, ys[0]))
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
        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]))
        ys = np.hstack((ys, ys[0]))
    else:
Ejemplo n.º 10
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()
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
        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]))
        ys = np.hstack((ys, ys[0]))
Ejemplo n.º 13
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
Ejemplo n.º 14
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()