Пример #1
0
    def render(self, context):
        qs = context[self.var_name]
        tmp = StringIO.StringIO()

        P = [c.p_bary for c in qs.all() if c.p_bary > 0]

        cv = SVGCanvas(940, 550, background_color='white')
        if P:
            binned = bin_data_log(P, 200)
            pc = PlotContainer(0, -20, 950, 550, color='black', x_log=True)
            pc.bottom.set_label('Period (ms)')
            pc.top.hide_label()
            pc.left.set_label('Count')
            pc.right.hide_label()
            hp = HistogramPlotter(binned, color='black')
            pc.add_plotter(hp)
            cv.add_plot_container(pc)
            # write number of candidates shown:
            tf = TextFragment(50,
                              520,
                              '(Showing %d candidates.)' % len(P),
                              color='black',
                              font_size=15)
            cv.add_plot_container(tf)
        else:
            tf = TextFragment(200,
                              200,
                              'No Candidates found.',
                              color='red',
                              font_size=50)
            cv.add_plot_container(tf)

        tmp = StringIO.StringIO()
        cv.draw(tmp)
        return tmp.getvalue()
Пример #2
0
    def render(self, context):
        qs = context[self.var_name]
        tmp = StringIO.StringIO()

        P = [c.p_bary for c in qs.all() if c.p_bary > 0]

        cv = SVGCanvas(940, 550, background_color='white')
        if P:
            binned = bin_data_log(P, 200)
            pc = PlotContainer(0, -20, 950, 550, color='black', x_log=True)
            pc.bottom.set_label('Period (ms)')
            pc.top.hide_label()
            pc.left.set_label('Count')
            pc.right.hide_label()
            hp = HistogramPlotter(binned, color='black')
            pc.add_plotter(hp)
            cv.add_plot_container(pc)
            # write number of candidates shown:
            tf = TextFragment(50, 520, '(Showing %d candidates.)' %
                              len(P), color='black', font_size=15)
            cv.add_plot_container(tf)
        else:
            tf = TextFragment(200, 200, 'No Candidates found.', color='red',
                              font_size=50)
            cv.add_plot_container(tf)

        tmp = StringIO.StringIO()
        cv.draw(tmp)
        return tmp.getvalue()
Пример #3
0
    def plot_profile(cv, x, y, width, height, bestprof_inst, *args, **kwargs):
        psr_name = kwargs.get('psr_name', '')
        data_set = kwargs.get('data_set', '')
        beam_ra = kwargs.get('beam_ra', None)
        beam_dec = kwargs.get('beam_dec', None)

        if beam_ra != None and beam_dec != None:
            if isintance(beam_ra, BaseString):
                pass
            elif isinstance(beam_ra, RightAscension):
                pass

        # Some futzing with the position and size because the axes are not
        # drawn, normally they get 50 px.
        pc = PlotContainer(x - 50,
                           y - 50,
                           width + 100,
                           height + 100,
                           data_padding=0)
        pc.hide_axes()

        bpf = bestprof_inst

        pp = LinePlotter(bpf.profile, use_markers=False)
        pc.add_plotter(pp)
        TEXTSIZE = 10
        cv.add_plot_container(pc)
        if psr_name:
            cv.add_plot_container(
                TextFragment(x + 0,
                             y + height + TEXTSIZE,
                             'PSR ' + psr_name,
                             font_size=TEXTSIZE))
        elif bpf.psr_name:
            cv.add_plot_container(
                TextFragment(x + 0,
                             y + height + TEXTSIZE,
                             bpf.psr_name,
                             font_size=TEXTSIZE))
        else:
            cv.add_plot_container(
                TextFragment(x + 0,
                             y + height + TEXTSIZE,
                             'PSR UNKNOWN',
                             font_size=TEXTSIZE))
        cv.add_plot_container(
            TextFragment(x + 0,
                         y + height + 2 * TEXTSIZE,
                         '%.2f ms' % bpf.header.p_bary[0],
                         alignment='start',
                         font_size=TEXTSIZE))
        cv.add_plot_container(
            TextFragment(x + width,
                         y + height + 2 * TEXTSIZE,
                         '%.3f pc cm^-3' % bpf.header.best_dm,
                         alignment='end',
                         font_size=TEXTSIZE))
Пример #4
0
    def render(self, context):
        qs = context[self.var_name]

        P = [c.p_bary for c in qs.all() if c.best_dm > 0]
        DM = [c.best_dm for c in qs.all() if c.best_dm > 0]
        REDCHISQ = [c.reduced_chi_sq for c in qs.all() if c.best_dm > 0]
        LINKS = [reverse('bestprof_detail', args=[c.pk])
                 for c in qs.all() if c.best_dm > 0]
        RA = [c.ra_deg for c in qs.all() if c.best_dm > 0]
        DEC = [c.dec_deg for c in qs.all() if c.best_dm > 0]

        cv = SVGCanvas(940, 550, background_color='white')
        if P:
            lo_dm = min(DM)
            max_dm = max(DM)
            pc = PlotContainer(0, -20, 880, 550, color='black', x_log=True,
                               y_log=True, data_background_color='gray')
            gr = RGBGradient((lo_dm, max_dm), (0, 0, 1), (1, 0, 0))
            scp = ScatterPlotter(P, REDCHISQ, RA, DEC, DM, gradient=gr,
                                 gradient_i=4, links=LINKS,
                                 symbol=RADECSymbol)
            pc.add_plotter(scp)
#            pc.top.hide_tickmarklabels()
            pc.top.hide_label()
#            pc.right.hide_tickmarklabels()
            pc.right.hide_label()
            pc.left.set_label('Reduced Chi Square')
            pc.bottom.set_label('Period (ms)')
            cv.add_plot_container(pc)
            # Gradient:
            pc = PlotContainer(820, -20, 120, 550, color='black', data_padding=0)
            pc.top.hide_label()
            pc.top.hide_tickmarks()
            pc.left.hide_tickmarks()
            pc.bottom.hide_label()
            pc.bottom.hide_tickmarks()
            pc.left.hide_label()
            pc.right.set_label('Dispersion Measure cm^-3 pc')
            pc.add_plotter(GradientPlotter(gr))
            cv.add_plot_container(pc)
            # write number of candidates shown:
            tf = TextFragment(50, 520,
                              '(Showing %d candidates.)' % len(P),
                              color='black', font_size=15)
            cv.add_plot_container(tf)
        else:
            tf = TextFragment(200, 200, 'No Candidates found.', color='red',
                              font_size=50)
            cv.add_plot_container(tf)

        tmp = StringIO.StringIO()
        cv.draw(tmp)
        return tmp.getvalue()
Пример #5
0
    def plot_profile(cv, x, y, width, height, bestprof_inst, *args, **kwargs):
        psr_name = kwargs.get('psr_name', '')
        data_set = kwargs.get('data_set', '')
        beam_ra = kwargs.get('beam_ra', None)
        beam_dec = kwargs.get('beam_dec', None)

        if beam_ra != None and beam_dec != None:
            if isintance(beam_ra, BaseString):
                pass
            elif isinstance(beam_ra, RightAscension):
                pass

        # Some futzing with the position and size because the axes are not
        # drawn, normally they get 50 px.
        pc = PlotContainer(x - 50, y - 50, width + 100, height + 100, data_padding=0)
        pc.hide_axes()

        bpf = bestprof_inst

        pp = LinePlotter(bpf.profile, use_markers=False)
        pc.add_plotter(pp)
        TEXTSIZE = 10
        cv.add_plot_container(pc)
        if psr_name:
            cv.add_plot_container(TextFragment(x + 0, y + height + TEXTSIZE,
                'PSR ' + psr_name, font_size=TEXTSIZE))
        elif bpf.psr_name:
            cv.add_plot_container(TextFragment(x + 0, y + height + TEXTSIZE,
                bpf.psr_name, font_size=TEXTSIZE))
        else:
            cv.add_plot_container(TextFragment(x + 0, y + height + TEXTSIZE,
                'PSR UNKNOWN', font_size=TEXTSIZE))
        cv.add_plot_container(TextFragment(x + 0, y + height + 2 * TEXTSIZE, 
            '%.2f ms' % bpf.header.p_bary[0], alignment='start', 
            font_size=TEXTSIZE))
        cv.add_plot_container(TextFragment(x + width, 
            y + height + 2 * TEXTSIZE, '%.3f pc cm^-3' % bpf.header.best_dm,
            alignment='end', font_size=TEXTSIZE))
Пример #6
0
            # Do the plots:
            PLOT_HEIGHT = 600

            TYPE2TITLE = {'N': 'Count', 'M': 'Max(SNR)', 'S': 'Sum(SNR)'}

            # Main panel, color-coded number of detections on DM-trial-time plane:
            pc_main = PlotContainer(0, -30, 900, PLOT_HEIGHT)
            pc_main.bottom.hide_label()
            pc_main.bottom.hide_tickmarklabels()
            pc_main.top.hide_label()
            pc_main.top.hide_tickmarklabels()
            pc_main.right.hide_tickmarklabels()
            pc_main.right.hide_label()
            pc_main.left.set_label('DM Index')
            pc_main.add_plotter(SinglePulsePlotter(png_str, (options.s, min_dmi,
                                options.e, max_dmi)))
            pc_main.set_minimum_data_bbox((options.s, min_dmi, options.e, max_dmi))
            cv.add_plot_container(pc_main)

            # First right-side panel, histogram of number of detections versus DM:
            pc_right1 = PlotContainer(820, -30, 270, PLOT_HEIGHT)
            pc_right1.add_plotter(HistogramPlotter(bins_dmi, False,
                                  orientation='vertical'))
            pc_right1.bottom.set_label(TYPE2TITLE[options.type])
            pc_right1.top.hide_label()
            pc_right1.top.hide_tickmarklabels()
            pc_right1.left.hide_tickmarklabels()
            pc_right1.left.hide_label()
            pc_right1.right.hide_tickmarklabels()
            pc_right1.right.hide_label()
            cv.add_plot_container(pc_right1)
Пример #7
0
    c = PlotContainer(100,
                      100,
                      600,
                      400,
                      background_color="white",
                      x_log=True,
                      y_log=True)
    TMP = [10 * x + 10 for x in range(99)]
    TMP2 = [10 * x + 10 for x in range(99)]
    TMP2.reverse()

    gr = RGBGradient((200, 800), (1, 0, 0), (0, 0, 1))
    c.add_plotter(
        LinePlotter(TMP,
                    TMP,
                    gradient=gr,
                    gradient_i=1,
                    symbol=BaseSymbol,
                    linepattern='2 2 8 2'))
    c.add_plotter(
        ScatterPlotter(TMP, TMP2, symbol=BaseSymbol, gradient=gr,
                       gradient_i=0))
    c.add_plotter(CrossHairPlotter(500, 500))
    c.add_plotter(CrossHairPlotter(200, 700, color='red'))
    c.add_plotter(XLimitPlotter(300))
    c.add_plotter(YLimitPlotter(300))
    c.add_plotter(CrossHairPlotter(1e+6, 1e+6))
    c.add_plotter(
        ScatterPlotter([1000], [1000], symbol=CrossHairSymbol, color='lime'))
    c.add_plotter(LinkBox((100, 100, 10000, 10000), 'http://www.slashdot.org'))
Пример #8
0
from brp.svg.plotters.legend import LegendPlotter, UNDER_PLOT, BOTTOMLEFT
from brp.core.interval import stretch_interval
from brp.svg.plotters.histogram import HistogramPlotter, bin_data
from brp.svg.plotters.error import ErrorPlotter
from brp.svg.plotters.linkbox import LinkBox

if __name__ == "__main__":
    # Draw a simple scatter + line plot to SVG (dumped to standard out).
    cv = SVGCanvas(1000, 2500)
    c = PlotContainer(100, 100, 600, 400, background_color="white", x_log=True, y_log=True)
    TMP = [10 * x + 10 for x in range(99)]
    TMP2 = [10 * x + 10 for x in range(99)]
    TMP2.reverse()

    gr = RGBGradient((200, 800), (1, 0, 0), (0, 0, 1))
    c.add_plotter(LinePlotter(TMP, TMP, gradient=gr, gradient_i=1, symbol=BaseSymbol, linepattern="2 2 8 2"))
    c.add_plotter(ScatterPlotter(TMP, TMP2, symbol=BaseSymbol, gradient=gr, gradient_i=0))
    c.add_plotter(CrossHairPlotter(500, 500))
    c.add_plotter(CrossHairPlotter(200, 700, color="red"))
    c.add_plotter(XLimitPlotter(300))
    c.add_plotter(YLimitPlotter(300))
    c.add_plotter(CrossHairPlotter(1e6, 1e6))
    c.add_plotter(ScatterPlotter([1000], [1000], symbol=CrossHairSymbol, color="lime"))
    c.add_plotter(LinkBox((100, 100, 10000, 10000), "http://www.slashdot.org"))

    c.left.set_interval(stretch_interval((10, 1000), 1.2, True), log=False)
    c.right.set_interval(stretch_interval((1000, 10), 1.2, True), log=False)
    c.bottom.set_interval((-100, 100), False)
    c.left.label_link("http://slashdot.org")
    c.right.label_link("http://slashdot.org")
    c.top.label_link("http://slashdot.org")
Пример #9
0
           raster=True)
    cv.add(pc)

# ------------------------------------------------------
# -- For debugging error bar raster fallback -----------

# LINEAR TRANSFORM CASE:

#    c = PlotContainer(0, 400, 600, 400, x_log=True, y_log=True)
    c = PlotContainer(600, 400, 600, 400)
    data_y = [10, 10, 20, 30, 40, 50, 40, 30, 20, 10, 10]
    data_x = [110, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    err_y = [(5, 5) for i in range(len(data_y))]
    ep = ErrorPlotter(data_x, data_y, symbols=[SquareSymbol],
                      err_y=err_y, err_x=err_y)
    c.add_plotter(ep)
    data_x1 = [2, 6, 43, 67]
    data_y1 = [45, 12, 85, 34]
    error_y = [(7, 4), (8, 8), (5, 5), (3, 9)]
    ep1 = ErrorPlotter(data_x1, data_y1, err_y=error_y, color='green')
    c.add(ep1, raster=True)
    ep2 = ErrorPlotter(data_y1, data_x1, err_x=error_y, color='red')
    c.add_plotter(ep2, raster=True)

    cv.add(c)

#    c = PlotContainer(600, 400, 600, 400, x_log=True, y_log=True)
    c = PlotContainer(0, 400, 600, 400)
    data_y = [10, 10, 20, 30, 40, 50, 40, 30, 20, 10, 10]
    data_x = [110, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    ep = ErrorPlotter(data_x, data_y, symbols=[SquareSymbol],
Пример #10
0
    def render(self, context):

        qs = context[self.var_name]
        tmp = StringIO.StringIO()

        cv = SVGCanvas(940, 550, background_color='white')

        P = [c.p_bary for c in qs.all() if c.best_dm > 0]
        DM = [c.best_dm for c in qs.all() if c.best_dm > 0]
        REDCHISQ = [c.reduced_chi_sq for c in qs.all() if c.best_dm > 0]
        LINKS = [
            reverse('bestprof_detail', args=[c.pk]) for c in qs.all()
            if c.best_dm > 0
        ]
        RA = [c.ra_deg for c in qs.all() if c.best_dm > 0]
        DEC = [c.dec_deg for c in qs.all() if c.best_dm > 0]

        if P:
            max_redchisq = max(REDCHISQ)
            min_redchisq = min(REDCHISQ)
            # Main panel showing candidate period-DM scatter plot:
            pc = PlotContainer(0,
                               -20,
                               880,
                               550,
                               color='black',
                               x_log=True,
                               y_log=True,
                               data_background_color='gray')
            pc.bottom.set_label('Period (ms)')
            pc.top.hide_label()
            pc.left.set_label('Dispersion Measure (cm^-3 pc)')
            pc.right.hide_label()
            gr = RGBGradient((min_redchisq, max_redchisq), (0, 0, 1),
                             (1, 0, 0))
            scp = ScatterPlotter(P,
                                 DM,
                                 RA,
                                 DEC,
                                 REDCHISQ,
                                 gradient=gr,
                                 gradient_i=4,
                                 links=LINKS,
                                 symbol=RADECSymbol)
            pc.add_plotter(scp)
            cv.add_plot_container(pc)
            # Gradient:
            pc = PlotContainer(820,
                               -20,
                               120,
                               550,
                               color='black',
                               data_padding=0)
            pc.top.hide_label()
            pc.top.hide_tickmarks()
            pc.left.hide_tickmarks()
            pc.bottom.hide_label()
            pc.bottom.hide_tickmarks()
            pc.left.hide_label()
            pc.right.set_label('Candidate Reduced Chi-Square')
            pc.add_plotter(GradientPlotter(copy.deepcopy(scp.gradient)))
            cv.add_plot_container(pc)
            # write number of candidates shown:
            tf = TextFragment(50,
                              520,
                              '(Showing %d candidates.)' % len(P),
                              color='black',
                              font_size=15)
            cv.add_plot_container(tf)
        else:
            tf = TextFragment(200,
                              200,
                              'No Candidates found.',
                              color='red',
                              font_size=50)
            cv.add_plot_container(tf)

        cv.draw(tmp)
        return tmp.getvalue()