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()
    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()
    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()
    output_files = check_directories(options, args, p)

    for plot_i, searchoutdir, fn in output_files:
        print plot_i, searchoutdir, fn
        # Do some setting up and calculations:
        cv = SVGCanvas(1250, 760)
        try:
            print 'Scanning for .singlepulse and .inf files ...'
            spr = SinglePulseReaderCondensed(searchoutdir, options.s, options.e,
                                        delays_file, options.lo, options.hi)
            print '... done'
        except:
            raise
            datapath = os.path.abspath(searchoutdir)
            msg = 'Problem with data in %s, nothing present?' % datapath
            cv.add_plot_container(TextFragment(100, 100, msg, font_size=15))
        else:
            print 'Number of DM-trials: %d' % len(spr.dms)
            tf = TextFragment(870, 600, spr.sp_map[spr.dms[0]][:-12])
            cv.add_plot_container(tf)
            min_dmi, max_dmi = get_dmi_range(spr, options.dmspercell)

            # for main, count detections (or do SNR calculation per cell):
            ar = count_detections(spr, options.dmspercell, max_dmi, options.s,
                                  options.e, options.secondspercell,
                                  options.type)
            # set up the gradient:
            if options.type == 'N':
                m, M = 1, 30
            elif options.type == 'M':
                m, M = 5, 30
Exemple #5
0
    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'))

    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')
    c.bottom.label_link('http://slashdot.org')
    c.top.set_label('OH JOY!')
    cv.add_plot_container(c)

    # Histogram testing:
    c = PlotContainer(100,
                      500,
                      600,
                      400,
                      background_color="white",
                      x_log=False,
                      y_log=False,
                      data_background_color='yellow')

    cp = LegendPlotter(position=UNDER_PLOT)
    colors = ['green', 'blue', 'red', 'gray', 'yellow', 'orange', 'lime']
    lps = ['6 2', '2 2', '4 4', '2 2 8 2', '']
    for ii in range(2):
Exemple #6
0
    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")
    c.bottom.label_link("http://slashdot.org")
    c.top.set_label("OH JOY!")
    cv.add_plot_container(c)

    # Histogram testing:
    c = PlotContainer(
        100, 500, 600, 400, background_color="white", x_log=False, y_log=False, data_background_color="yellow"
    )

    cp = LegendPlotter(position=UNDER_PLOT)
    colors = ["green", "blue", "red", "gray", "yellow", "orange", "lime"]
    lps = ["6 2", "2 2", "4 4", "2 2 8 2", ""]
    for ii in range(2):
        data = []
        for i in range(10000):
            data.append(random.randrange(100))
        bd = bin_data(data, 100)
        c.add_plotter(HistogramPlotter(bd, color="black", linepattern=lps[ii % len(lps)]))
    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()