Esempio n. 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()
Esempio n. 2
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))
Esempio n. 3
0
from brp.svg.plotters.gradient import RGBGradient, GradientPlotter
from brp.svg.plotters.crosshair import CrossHairPlotter
from brp.svg.plotters.limit import XLimitPlotter, YLimitPlotter
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'))
Esempio n. 4
0
if __name__ == '__main__':

    cv = SVGCanvas(1200, 1800)

# ------------------------------------------------------
# -- For debugging RADECSymbol raster fallback ---------

    NPULSARS = 100
    P = [random.uniform(0.001, 10) for i in range(NPULSARS)]
    DM = [random.uniform(1, 100) for i in range(NPULSARS)]
    RA = [random.uniform(0, 24) for i in range(NPULSARS)]
    DEC = [random.uniform(-90, 90) for i in range(NPULSARS)]
    SIGMA = [random.uniform(2, 15) for i in range(NPULSARS)]

    # plot
    pc = PlotContainer(0, 0, 600, 400)
    pc.add(ScatterPlotter(P, DM, RA, DEC, SIGMA, symbol=RADECSymbol))
    cv.add(pc)

    pc = PlotContainer(600, 0, 600, 400)
    pc.add(ScatterPlotter(P, DM, RA, DEC, SIGMA, symbols=[RADECSymbol]),
           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)
Esempio n. 5
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()
Esempio n. 6
0
import sys
from random import random as r

from brp.svg.base import SVGCanvas, PlotContainer
from brp.svg.plotters import newhist2d
from brp.svg.plotters.gradient import GradientPlotter
from brp.svg.plotters.line import LinePlotter

if __name__ == '__main__':

    x_data = [r() for i in range(1000)]
    y_data = [r() for i in range(1000)]

    cv = SVGCanvas(1200, 800)

    p = PlotContainer(0, 0, 600, 400)
    h = newhist2d.Histogram2dPlotter(x_data, y_data, x_bins=100)
    gr = h.get_gradient()
    collapsed_x, yvalues = h.collapse_x()
    xvalues, collapsed_y = h.collapse_y()
    p.add(h)
    cv.add(p)

    p = PlotContainer(800, 0, 160, 400)
    p.add(GradientPlotter(gr, 'vertical'))
    cv.add(p)

    p = PlotContainer(600, 0, 200, 400)
    p.add(LinePlotter(collapsed_x, yvalues))
    cv.add(p)
Esempio n. 7
0
import sys
#sys.path.append('../')

from brp.svg.base import SVGCanvas, PlotContainer, TextFragment
from brp.svg.plotters.histogram import HistogramPlotter, merge_bins

if __name__ == '__main__':
    bins = [(0, 1, 10), (1, 2, 10), (2, 3, 11), (3, 4, 10), (4, 5, 10),
            (5, 6, 7)]

    cv = SVGCanvas(1200, 1200)

    # Histogram testing:
    c = PlotContainer(0, 0, 600, 400)
    c.add(HistogramPlotter(bins))
    cv.add(c)
    cv.add(TextFragment(100, 100, 'Unmerged bins', color='red'))

    merged = merge_bins(bins)

    c2 = PlotContainer(600, 0, 600, 400)
    c2.add(HistogramPlotter(merged))
    cv.add(c2)
    cv.add(TextFragment(700, 100, 'Merged bins', color='red'))

    cv.draw(sys.stdout)