Esempio n. 1
0
def plotnorm(data, circleinds=[], crossinds=[], edgeinds=[], url_path=None, fileroot=None,
             tools="hover,tap,pan,box_select,wheel_zoom,reset", plot_width=450, plot_height=400):
    """ Make a light-weight norm figure """

    fields = ['zs', 'sizes', 'colors', 'abssnr', 'key', 'snrs']

    if not circleinds: circleinds = range(len(data['snrs']))

    source = ColumnDataSource(data = dict({(key, tuple([value[i] for i in circleinds if i not in edgeinds])) 
                                           for (key, value) in data.iteritems() if key in fields}))
    norm = Figure(plot_width=plot_width, plot_height=plot_height, toolbar_location="left", x_axis_label='SNR observed',
                  y_axis_label='SNR expected', tools=tools, webgl=True)
    norm.circle('abssnr', 'zs', size='sizes', line_color=None, fill_color='colors', fill_alpha=0.2, source=source)

    if crossinds:
        sourceneg = ColumnDataSource(data = dict({(key, tuple([value[i] for i in crossinds]))
                                                  for (key, value) in data.iteritems() if key in fields}))
        norm.cross('abssnr', 'zs', size='sizes', line_color='colors', line_alpha=0.3, source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(data = dict({(key, tuple([value[i] for i in edgeinds]))
                                                   for (key, value) in data.iteritems() if key in fields}))
        norm.circle('abssnr', 'zs', size='sizes', line_color='colors', fill_color='colors', source=sourceedge, line_alpha=0.5, fill_alpha=0.2)

    hover = norm.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = norm.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return norm
Esempio n. 2
0
def plotnoisedist(noisepkl, plot_width=450, plot_height=400):
    """ """

    # plot noise and flag distributions
    scans, segments, noiseperbl, flagfrac, imstd = read_noise(noisepkl)
    pl = Figure(plot_width=plot_width,
                plot_height=plot_height,
                toolbar_location="above",
                x_axis_label='Flag fraction',
                y_axis_label='Image noise (sys)',
                tools='pan, wheel_zoom, reset')
    pl.cross(flagfrac, imstd, line_alpha=0.2, color='blue')

    # find medians
    flagfrac_med = np.median(flagfrac)
    imstd_med = np.median(imstd)
    logger.info('Median image noise (sys) = {0}'.format(imstd_med))
    logger.info('Median flag fraction = {0}'.format(flagfrac_med))
    pl.cross(flagfrac_med, imstd_med, line_alpha=1, size=40, color='red')

    # estimate number of zero noise images
    zeronoisefrac = float(len(np.where(imstd == 0.)[0])) / len(imstd)
    logger.info('{0:.0%} of noise images are zeros'.format(zeronoisefrac))

    return pl, imstd_med, flagfrac_med
Esempio n. 3
0
def plotstat(data, circleinds=None, crossinds=None, edgeinds=None, url_path=None, fileroot=None, 
             tools="hover,tap,pan,box_select,wheel_zoom,reset", plot_width=450, plot_height=400):
    """ Make a light-weight stat figure """

    fields = ['imkur', 'specstd', 'sizes', 'colors', 'snrs', 'key']

    if not circleinds: circleinds = range(len(data['snrs']))

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    specstd = [data['specstd'][i] for i in inds]
    specstd_min = min(specstd)
    specstd_max = max(specstd)
    imkur = [data['imkur'][i] for i in inds]
    imkur_min = min(imkur)
    imkur_max = max(imkur)

    source = ColumnDataSource(data = dict({(key, tuple([value[i] for i in circleinds if i not in edgeinds])) 
                                           for (key, value) in data.iteritems() if key in fields}))
    stat = Figure(plot_width=plot_width, plot_height=plot_height, toolbar_location="left", x_axis_label='Spectral std',
                  y_axis_label='Image kurtosis', x_range=(specstd_min, specstd_max), 
                  y_range=(imkur_min, imkur_max), tools=tools, webgl=True)
    stat.circle('specstd', 'imkur', size='sizes', line_color=None, fill_color='colors', fill_alpha=0.2, source=source)

    if crossinds:
        sourceneg = ColumnDataSource(data = dict({(key, tuple([value[i] for i in crossinds]))
                                                  for (key, value) in data.iteritems() if key in fields}))
        stat.cross('specstd', 'imkur', size='sizes', line_color='colors', line_alpha=0.3, source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(data = dict({(key, tuple([value[i] for i in edgeinds]))
                                                   for (key, value) in data.iteritems() if key in fields}))
        stat.circle('specstd', 'imkur', size='sizes', line_color='colors', fill_color='colors', source=sourceedge, line_alpha=0.5, fill_alpha=0.2)

    hover = stat.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = stat.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return stat
Esempio n. 4
0
def plotdmt(data, circleinds=[], crossinds=[], edgeinds=[], url_path=None, fileroot=None,
            tools="hover,tap,pan,box_select,wheel_zoom,reset", plot_width=950, plot_height=500):
    """ Make a light-weight dm-time figure """

    fields = ['dm', 'time', 'sizes', 'colors', 'snrs', 'key']

    if not circleinds: circleinds = range(len(data['snrs']))

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    dm = [data['dm'][i] for i in inds]
    dm_min = min(min(dm), max(dm)/1.2)
    dm_max = max(max(dm), min(dm)*1.2)
    time = [data['time'][i] for i in inds]
    time_min = min(time)
    time_max = max(time)

    source = ColumnDataSource(data = dict({(key, tuple([value[i] for i in circleinds if i not in edgeinds])) 
                                           for (key, value) in data.iteritems() if key in fields}))
    dmt = Figure(plot_width=plot_width, plot_height=plot_height, toolbar_location="left", x_axis_label='Time (s; relative)',
                 y_axis_label='DM (pc/cm3)', x_range=(time_min, time_max), y_range=(dm_min, dm_max), 
                 webgl=True, tools=tools)
    dmt.circle('time', 'dm', size='sizes', fill_color='colors', line_color=None, fill_alpha=0.2, source=source)

    if crossinds:
        sourceneg = ColumnDataSource(data = dict({(key, tuple([value[i] for i in crossinds]))
                                                  for (key, value) in data.iteritems() if key in fields}))
        dmt.cross('time', 'dm', size='sizes', fill_color='colors', line_alpha=0.3, source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(data = dict({(key, tuple([value[i] for i in edgeinds]))
                                                   for (key, value) in data.iteritems() if key in fields}))
        dmt.circle('time', 'dm', size='sizes', line_color='colors', fill_color='colors', line_alpha=0.5, fill_alpha=0.2, source=sourceedge)
    hover = dmt.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
#        url = '{}/cands_{}_sc@scan-seg@seg-i@candint-dm@[email protected]'.format(url_path, fileroot)
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = dmt.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return dmt
Esempio n. 5
0
def plotloc(data, circleinds=[], crossinds=[], edgeinds=[], url_path=None, fileroot=None,
            tools="hover,tap,pan,box_select,wheel_zoom,reset", plot_width=450, plot_height=400):
    """ Make a light-weight loc figure """

    fields = ['l1', 'm1', 'sizes', 'colors', 'snrs', 'key']

    if not circleinds: circleinds = range(len(data['snrs']))

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    l1 = [data['l1'][i] for i in inds]
    l1_min = min(l1)
    l1_max = max(l1)
    m1 = [data['m1'][i] for i in inds]
    m1_min = min(m1)
    m1_max = max(m1)

    source = ColumnDataSource(data = dict({(key, tuple([value[i] for i in circleinds if i not in edgeinds])) 
                                           for (key, value) in data.iteritems() if key in fields}))
    loc = Figure(plot_width=plot_width, plot_height=plot_height, toolbar_location="left", x_axis_label='l1 (rad)', y_axis_label='m1 (rad)',
                 x_range=(l1_min, l1_max), y_range=(m1_min,m1_max), tools=tools, webgl=True)
    loc.circle('l1', 'm1', size='sizes', line_color=None, fill_color='colors', fill_alpha=0.2, source=source)

    if crossinds:
        sourceneg = ColumnDataSource(data = dict({(key, tuple([value[i] for i in crossinds]))
                                                  for (key, value) in data.iteritems() if key in fields}))
        loc.cross('l1', 'm1', size='sizes', line_color='colors', line_alpha=0.3, source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(data = dict({(key, tuple([value[i] for i in edgeinds]))
                                                   for (key, value) in data.iteritems() if key in fields}))
        loc.circle('l1', 'm1', size='sizes', line_color='colors', fill_color='colors', source=sourceedge, line_alpha=0.5, fill_alpha=0.2)

    hover = loc.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = loc.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return loc
Esempio n. 6
0
def plotnoisedist(noisepkl, plot_width=450, plot_height=400):
    """ """

    # plot noise and flag distributions
    scans, segments, noiseperbl, flagfrac, imstd = read_noise(noisepkl)
    pl = Figure(plot_width=plot_width, plot_height=plot_height, toolbar_location="above",
                x_axis_label='Flag fraction', y_axis_label='Image noise (sys)', tools='pan, wheel_zoom, reset')
    pl.cross(flagfrac, imstd, line_alpha=0.2, color='blue')

    # find medians
    flagfrac_med = np.median(flagfrac)
    imstd_med = np.median(imstd)
    logger.info('Median image noise (sys) = {0}'.format(imstd_med))
    logger.info('Median flag fraction = {0}'.format(flagfrac_med))
    pl.cross(flagfrac_med, imstd_med, line_alpha=1, size=40, color='red')

    # estimate number of zero noise images
    zeronoisefrac = float(len(np.where(imstd == 0.)[0]))/len(imstd)
    logger.info('{0:.0%} of noise images are zeros'.format(zeronoisefrac))
    
    return pl, imstd_med, flagfrac_med
Esempio n. 7
0
class pf_graph:
    def end_date(self):
        now = date.today() + timedelta(hours=4)
        return now.strftime("%Y%m%d")

    def get_quotes(self):
        self.data_slice = slice(-self.data_length, None)
        self.pf.asset_ticker = self.ticker
        quote = fn.get_quotes_finam(self.ticker,
                                    start_date=self.from_date,
                                    end_date=self.end_date(),
                                    period=self.quote_period,
                                    verbose=False,
                                    timeout=30)
        self.quote = quote[self.data_slice]
        #print(self.quote.tail())
        #self.quote.to_csv('/home/jupyter/bokeh/pf/quotes_{}'.format(self.quote_period))

    def update_quotes(self):
        quote = self.quote
        last_day = quote.ix[-1].name
        last_day_begin = datetime(last_day.year, last_day.month, last_day.day)
        quote_base = quote.ix[:last_day_begin + timedelta(seconds=-1)]
        last_day_str = last_day_begin.strftime('%Y%m%d')
        #while True:
        #print('get quotes')
        try:
            quote = fn.get_quotes_finam(self.ticker,
                                        start_date=last_day_str,
                                        end_date=self.end_date(),
                                        period=self.quote_period,
                                        verbose=False,
                                        timeout=5)
        except timeout as e:
            print('get quotes: timeout, period={}!'.format(self.quote_period))
            self.text.value = 'timeout!'
            return
        except:
            self.text.value = 'get quote error!'
            return
        #print('obtain quotes')
        self.quote = quote_base.append(quote)[self.data_slice]
        time_str = quote.ix[-1].name.strftime('%Y-%m-%d %H:%M')
        if self.text_marker == len(markers) - 1:
            self.text_marker = 0
        else:
            self.text_marker += 1
        self.text.value = '{} [{}] {}'.format(
            markers[self.text_marker], time_str,
            quote.ix[-1][self.ticker + '_Close'])
        #time.sleep(1)

    def __init__(self, quote_period, box_size, graph_name, candles=30):
        # Set up data
        self.graph_counter = 0
        self.data_length = candles
        self.data_slice = slice(-self.data_length, None)
        self.quote_period = quote_period
        self.ticker = 'SPFB.RTS'
        self.box_size_divider = 1.

        self.pf = point_and_figure.Point_and_Figure()

        #print(quote_period)
        if (quote_period == 'daily' or quote_period == 'hour'):
            self.from_date = (date.today() - timedelta(
                days=days_look_back_min_candles * 5)).strftime('%Y%m%d')
        else:
            self.from_date = (
                date.today() -
                timedelta(days=days_look_back_min_candles)).strftime('%Y%m%d')

        self.get_quotes()
        self.last_quote_date = None

        self.pf.box_size = box_size
        self.pf.process_df(self.quote)
        self.pf.prepare_datasource()

        self.plot = Figure(
            plot_height=400,
            plot_width=600,
            title=graph_name,
            tools="crosshair,pan,reset,resize,wheel_zoom,save",
        )
        self.yticker = bokeh.models.FixedTicker()
        #print pf.yticks
        self.yticker.ticks = list(self.pf.yticks)
        self.xticker = bokeh.models.FixedTicker()
        self.xticker.ticks = list(self.pf.xticks)
        # ticker.interval = 1
        #p.xaxis.ticker = ticker
        self.plot.ygrid.ticker = self.yticker
        self.plot.xgrid.ticker = self.xticker
        self.plot.yaxis.formatter = bokeh.models.NumeralTickFormatter(
            format=self.pf.bokeh_ticks_format)
        self.plot.yaxis.ticker = self.yticker
        #self.plot.ygrid.band_fill_alpha = 0.05
        #self.plot.ygrid.band_fill_color = "navy"
        #self.glyphs_size = 100.
        #self.glyphs_size = self.pf.box_size / 1. / len(self.pf.yticks) * self.pf.scale_factor

        self.scale = Slider(title="scale",
                            value=300,
                            start=300,
                            end=3000,
                            step=1)
        self.scale.on_change('value', self.scale_change)

        self.recalc_glyphs_size = True
        self.calc_glyphs()
        self.source_x = ColumnDataSource(
            data=dict(x=self.pf.x_x, y=self.pf.x_y, size=self.glyphs_size_x))
        self.source_o = ColumnDataSource(
            data=dict(x=self.pf.o_x, y=self.pf.o_y, size=self.glyphs_size_o))
        self.source_digits = ColumnDataSource(
            data=dict(x=self.pf.digits_x,
                      y=self.pf.digits_y,
                      text=self.pf.digits_text,
                      size=self.font_size))
        self.graph_o = self.plot.circle('x',
                                        'y',
                                        source=self.source_o,
                                        alpha=0.5,
                                        size='size',
                                        color="navy")
        self.graph_x = self.plot.cross('x',
                                       'y',
                                       source=self.source_x,
                                       alpha=0.5,
                                       size='size',
                                       color="navy",
                                       angle=np.pi / 4)
        self.graph_digits = self.plot.text(
            'x',
            'y',
            source=self.source_digits,
            alpha=0.5,
            text='text',
            color="navy",
            text_font_size='size')  #text_font_size

        self.box = Slider(title="box",
                          value=self.pf.box_size,
                          start=10,
                          end=500,
                          step=1)
        self.box.on_change('value', self.box_change)

        self.text = TextInput()
        self.text_marker = 0

    def calc_glyphs(self):
        #self.glyphs_size = self.pf.box_size / 4. / len(self.pf.yticks) * self.pf.scale_factor
        #print self.glyphs_size
        if self.recalc_glyphs_size:
            self.glyphs_size = min(
                self.plot.plot_height / 1.2 / (len(self.pf.yticks) + 3),
                self.plot.plot_width / 1.2 / (len(self.pf.xticks) + 3))
            self.scale.value = int(self.glyphs_size * 100)
        self.recalc_glyphs_size = False
        if self.glyphs_size < 3:
            self.glyphs_size = 3
        self.glyphs_size_x = [self.glyphs_size for _ in self.pf.x_x]
        self.glyphs_size_o = [self.glyphs_size for _ in self.pf.o_x]
        self.font_size = [
            '{}px'.format(self.glyphs_size) for _ in self.pf.digits_x
        ]
        #print(self.glyphs_size_x)

    def scale_change(self, attrname, old, new):
        self.glyphs_size = self.scale.value / 100.
        #print(self.glyphs_size)

    def box_change(self, attrname, old, new):
        self.pf.box_size = self.box.value / self.box_size_divider
        self.recalc_glyphs_size = True

    def update_data(self, attrname, old, new):
        #print('box')
        # Get the current slider values

        # Generate the new curve
        self.pf.process_df(self.quote)
        self.pf.prepare_datasource()
        self.yticker.ticks = list(self.pf.yticks)
        self.xticker.ticks = list(self.pf.xticks)
        self.calc_glyphs()
        #self.graph_o.glyph.size = self.glyphs_size
        #self.graph_x.glyph.size = self.glyphs_size
        #self.shuffle(x=self.pf.x_x, y=self.pf.x_y)
        data = dict(x=self.pf.x_x, y=self.pf.x_y, size=self.glyphs_size_x)
        self.source_x.data = data
        #self.shuffle(x=self.pf.o_x, y=self.pf.o_y)
        data = dict(x=self.pf.o_x, y=self.pf.o_y, size=self.glyphs_size_o)
        self.source_o.data = data
        data = dict(x=self.pf.digits_x,
                    y=self.pf.digits_y,
                    text=self.pf.digits_text,
                    size=self.font_size)
        self.source_digits.data = data
Esempio n. 8
0
              title="Optimization with side condition",
              x_range=[lagrange_settings.x_min, lagrange_settings.x_max],
              y_range=[lagrange_settings.y_min, lagrange_settings.y_max])

# Plot contour of f(x,y)
contour_f = my_bokeh_utils.Contour(plot, line_color='grey', line_width=1)
# Plot active isolevel f(x,y)=v
contour_f0 = my_bokeh_utils.Contour(plot, add_label=True, line_color='black', line_width=2, legend='f(x,y) = v')
# Plot constraint function contour g(x,y)=0
contour_g = my_bokeh_utils.Contour(plot, line_color='red', line_width=2, legend='g(x,y) = 0')
# Plot corresponding tangent vector
quiver_isolevel = my_bokeh_utils.Quiver(plot, fix_at_middle=False, line_width=2, color='black')
# Plot corresponding tangent vector
quiver_constraint = my_bokeh_utils.Quiver(plot, fix_at_middle=False, line_width=2, color='red')
# Plot mark at position on constraint function
plot.cross(x='x', y='y', color='red', size=10, line_width=2, source=source_mark)

# object that detects, if a position in the plot is clicked on
interactor = my_bokeh_utils.Interactor(plot)
# adds callback function to interactor, if position in plot is clicked, call on_selection_change
interactor.on_click(on_selection_change)

# text input window for objective function f(x,y) to be optimized
f_input = TextInput(value=lagrange_settings.f_init, title="f(x,y):")
f_input.on_change('value', f_changed)

# dropdown menu for selecting one of the sample functions
sample_fun_input_f = Dropdown(label="choose a sample function f(x,y) or enter one below",
                              menu=lagrange_settings.sample_f_names)
sample_fun_input_f.on_click(sample_fun_input_f_changed)
Esempio n. 9
0
def plotall(data, circleinds=[], crossinds=[], edgeinds=[], htmlname=None, noiseplot=None, url_path='plots', fileroot=None):
    """ Create interactive plot (preserving links between panels) from data dictionary

    data has keys of snr, time, dm, sizes, key and more.
    Optional index arguments are used to filter full data set.
    This can be used to remove bad segments or apply different symbols to subsets.
    url_path is path difference to png files for taptool. ('../plots' for jupyter notebook, 'plots' for public page)
    fileroot is the sdm file name used as root for all png files.
    """

    # set up data dictionary
    if not circleinds: circleinds = calcinds(data, np.abs(data['snrs']).min())
    if not crossinds: crossinds = calcinds(data, -1*np.abs(data['snrs']).min())

    TOOLS = "hover,tap,pan,box_select,wheel_zoom,reset"

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    dm = [data['dm'][i] for i in inds]
    dm_min = min(min(dm), max(dm)/1.2)
    dm_max = max(max(dm), min(dm)*1.2)
    time = [data['time'][i] for i in inds]
    time_min = min(time)
    time_max = max(time)
    l1 = [data['l1'][i] for i in inds]
    l1_min = min(l1)
    l1_max = max(l1)
    m1 = [data['m1'][i] for i in inds]
    m1_min = min(m1)
    m1_max = max(m1)
    specstd = [data['specstd'][i] for i in inds]
    specstd_min = min(specstd)
    specstd_max = max(specstd)
    imkur = [data['imkur'][i] for i in inds]
    imkur_min = min(imkur)
    imkur_max = max(imkur)

    # create figures
    dmt = Figure(plot_width=950, plot_height=500, toolbar_location="left", x_axis_label='Time (s; relative)',
                 y_axis_label='DM (pc/cm3)', x_range=(time_min, time_max), y_range=(dm_min, dm_max), 
                 webgl=True, tools=TOOLS)
    loc = Figure(plot_width=450, plot_height=400, toolbar_location="left", x_axis_label='l1 (rad)', y_axis_label='m1 (rad)',
                 x_range=(l1_min, l1_max), y_range=(m1_min,m1_max), tools=TOOLS, webgl=True)
    stat = Figure(plot_width=450, plot_height=400, toolbar_location="left", x_axis_label='Spectral std',
                  y_axis_label='Image kurtosis', x_range=(specstd_min, specstd_max), 
                  y_range=(imkur_min, imkur_max), tools=TOOLS, webgl=True)
    norm = Figure(plot_width=450, plot_height=400, toolbar_location="left", x_axis_label='SNR observed',
                  y_axis_label='SNR expected', tools=TOOLS, webgl=True)

    # create positive symbol source and add glyphs
    source = ColumnDataSource(data = dict({(key, tuple([value[i] for i in circleinds if i not in edgeinds])) 
                                           for (key, value) in data.iteritems()}))
    dmt.circle('time', 'dm', size='sizes', fill_color='colors', line_color=None, fill_alpha=0.2, source=source)
    loc.circle('l1', 'm1', size='sizes', line_color=None, fill_color='colors', fill_alpha=0.2, source=source)
    stat.circle('specstd', 'imkur', size='sizes', line_color=None, fill_color='colors', fill_alpha=0.2, source=source)
    norm.circle('abssnr', 'zs', size='sizes', line_color=None, fill_color='colors', fill_alpha=0.2, source=source)

    # create negative symbol source and add glyphs
    if crossinds:
        sourceneg = ColumnDataSource(data = dict({(key, tuple([value[i] for i in crossinds]))
                                                  for (key, value) in data.iteritems()}))
        dmt.cross('time', 'dm', size='sizes', fill_color='colors', line_alpha=0.3, source=sourceneg)
        loc.cross('l1', 'm1', size='sizes', line_color='colors', line_alpha=0.3, source=sourceneg)
        stat.cross('specstd', 'imkur', size='sizes', line_color='colors', line_alpha=0.3, source=sourceneg)
        norm.cross('abssnr', 'zs', size='sizes', line_color='colors', line_alpha=0.3, source=sourceneg)

    # create linked symbol source and add glyphs
    if edgeinds:
        sourceedge = ColumnDataSource(data = dict({(key, tuple([value[i] for i in edgeinds]))
                                                   for (key, value) in data.iteritems()}))
        dmt.circle('time', 'dm', size='sizes', line_color='colors', fill_color='colors', line_alpha=0.5, fill_alpha=0.2, source=sourceedge)
        loc.circle('l1', 'm1', size='sizes', line_color='colors', fill_color='colors', source=sourceedge, line_alpha=0.5, fill_alpha=0.2)
        stat.circle('specstd', 'imkur', size='sizes', line_color='colors', fill_color='colors', source=sourceedge, line_alpha=0.5, fill_alpha=0.2)
        norm.circle('abssnr', 'zs', size='sizes', line_color='colors', fill_color='colors', source=sourceedge, line_alpha=0.5, fill_alpha=0.2)

    hover = dmt.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])
    hover = loc.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])
    hover = stat.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])
    hover = norm.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = dmt.select(type=TapTool)
        taptool.callback = OpenURL(url=url)
        taptool = loc.select(type=TapTool)
        taptool.callback = OpenURL(url=url)
        taptool = stat.select(type=TapTool)
        taptool.callback = OpenURL(url=url)
        taptool = norm.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

# this approach does not preserve links between panels
#    dmt = plotdmt(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS) # maybe add size?
#    loc = plotloc(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS)
#    stat = plotstat(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS)
#    norm = plotnorm(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS)

    # arrange figures
    top = HBox(dmt, width=950)
    middle = HBox(loc, stat, width=950)
    if noiseplot:
        bottom = HBox(norm, noiseplot, width=950)
    else:
        bottom = HBox(norm, width=950)
    combined = VBox(top, middle, bottom, width=950)

    if htmlname:
        output_file(htmlname)
        save(combined)
    else:
        return combined
Esempio n. 10
0
def plotall(data,
            circleinds=[],
            crossinds=[],
            edgeinds=[],
            htmlname=None,
            noiseplot=None,
            url_path='plots',
            fileroot=None):
    """ Create interactive plot (preserving links between panels) from data dictionary

    data has keys of snr, time, dm, sizes, key and more.
    Optional index arguments are used to filter full data set.
    This can be used to remove bad segments or apply different symbols to subsets.
    url_path is path difference to png files for taptool. ('../plots' for jupyter notebook, 'plots' for public page)
    fileroot is the sdm file name used as root for all png files.
    """

    # set up data dictionary
    if not circleinds: circleinds = calcinds(data, np.abs(data['snrs']).min())
    if not crossinds:
        crossinds = calcinds(data, -1 * np.abs(data['snrs']).min())

    TOOLS = "hover,tap,pan,box_select,wheel_zoom,reset"

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    dm = [data['dm'][i] for i in inds]
    dm_min = min(min(dm), max(dm) / 1.2)
    dm_max = max(max(dm), min(dm) * 1.2)
    time = [data['time'][i] for i in inds]
    time_min = min(time)
    time_max = max(time)
    l1 = [data['l1'][i] for i in inds]
    l1_min = min(l1)
    l1_max = max(l1)
    m1 = [data['m1'][i] for i in inds]
    m1_min = min(m1)
    m1_max = max(m1)
    specstd = [data['specstd'][i] for i in inds]
    specstd_min = min(specstd)
    specstd_max = max(specstd)
    imkur = [data['imkur'][i] for i in inds]
    imkur_min = min(imkur)
    imkur_max = max(imkur)

    # create figures
    dmt = Figure(plot_width=950,
                 plot_height=500,
                 toolbar_location="left",
                 x_axis_label='Time (s; relative)',
                 y_axis_label='DM (pc/cm3)',
                 x_range=(time_min, time_max),
                 y_range=(dm_min, dm_max),
                 output_backend='webgl',
                 tools=TOOLS)
    loc = Figure(plot_width=450,
                 plot_height=400,
                 toolbar_location="left",
                 x_axis_label='l1 (rad)',
                 y_axis_label='m1 (rad)',
                 x_range=(l1_min, l1_max),
                 y_range=(m1_min, m1_max),
                 tools=TOOLS,
                 output_backend='webgl')
    stat = Figure(plot_width=450,
                  plot_height=400,
                  toolbar_location="left",
                  x_axis_label='Spectral std',
                  y_axis_label='Image kurtosis',
                  x_range=(specstd_min, specstd_max),
                  y_range=(imkur_min, imkur_max),
                  tools=TOOLS,
                  output_backend='webgl')
    norm = Figure(plot_width=450,
                  plot_height=400,
                  toolbar_location="left",
                  x_axis_label='SNR observed',
                  y_axis_label='SNR expected',
                  tools=TOOLS,
                  output_backend='webgl')

    # create positive symbol source and add glyphs
    source = ColumnDataSource(
        data=dict({(key,
                    tuple([value[i] for i in circleinds if i not in edgeinds]))
                   for (key, value) in data.iteritems()}))
    dmt.circle('time',
               'dm',
               size='sizes',
               fill_color='colors',
               line_color=None,
               fill_alpha=0.2,
               source=source)
    loc.circle('l1',
               'm1',
               size='sizes',
               line_color=None,
               fill_color='colors',
               fill_alpha=0.2,
               source=source)
    stat.circle('specstd',
                'imkur',
                size='sizes',
                line_color=None,
                fill_color='colors',
                fill_alpha=0.2,
                source=source)
    norm.circle('abssnr',
                'zs',
                size='sizes',
                line_color=None,
                fill_color='colors',
                fill_alpha=0.2,
                source=source)

    # create negative symbol source and add glyphs
    if crossinds:
        sourceneg = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in crossinds]))
                       for (key, value) in data.iteritems()}))
        dmt.cross('time',
                  'dm',
                  size='sizes',
                  fill_color='colors',
                  line_alpha=0.3,
                  source=sourceneg)
        loc.cross('l1',
                  'm1',
                  size='sizes',
                  line_color='colors',
                  line_alpha=0.3,
                  source=sourceneg)
        stat.cross('specstd',
                   'imkur',
                   size='sizes',
                   line_color='colors',
                   line_alpha=0.3,
                   source=sourceneg)
        norm.cross('abssnr',
                   'zs',
                   size='sizes',
                   line_color='colors',
                   line_alpha=0.3,
                   source=sourceneg)

    # create linked symbol source and add glyphs
    if edgeinds:
        sourceedge = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in edgeinds]))
                       for (key, value) in data.iteritems()}))
        dmt.circle('time',
                   'dm',
                   size='sizes',
                   line_color='colors',
                   fill_color='colors',
                   line_alpha=0.5,
                   fill_alpha=0.2,
                   source=sourceedge)
        loc.circle('l1',
                   'm1',
                   size='sizes',
                   line_color='colors',
                   fill_color='colors',
                   source=sourceedge,
                   line_alpha=0.5,
                   fill_alpha=0.2)
        stat.circle('specstd',
                    'imkur',
                    size='sizes',
                    line_color='colors',
                    fill_color='colors',
                    source=sourceedge,
                    line_alpha=0.5,
                    fill_alpha=0.2)
        norm.circle('abssnr',
                    'zs',
                    size='sizes',
                    line_color='colors',
                    fill_color='colors',
                    source=sourceedge,
                    line_alpha=0.5,
                    fill_alpha=0.2)

    hover = dmt.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])
    hover = loc.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])
    hover = stat.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])
    hover = norm.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = dmt.select(type=TapTool)
        taptool.callback = OpenURL(url=url)
        taptool = loc.select(type=TapTool)
        taptool.callback = OpenURL(url=url)
        taptool = stat.select(type=TapTool)
        taptool.callback = OpenURL(url=url)
        taptool = norm.select(type=TapTool)
        taptool.callback = OpenURL(url=url)


# this approach does not preserve links between panels
#    dmt = plotdmt(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS) # maybe add size?
#    loc = plotloc(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS)
#    stat = plotstat(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS)
#    norm = plotnorm(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds, url_path=url_path, fileroot=fileroot, tools=TOOLS)

# arrange figures
    top = Row(dmt, width=950)
    middle = Row(loc, stat, width=950)
    if noiseplot:
        bottom = Row(norm, noiseplot, width=950)
    else:
        bottom = Row(norm, width=950)
    combined = Column(top, middle, bottom, width=950)

    if htmlname:
        output_file(htmlname)
        save(combined)
    else:
        return combined
Esempio n. 11
0
def plotnorm(data,
             circleinds=[],
             crossinds=[],
             edgeinds=[],
             url_path=None,
             fileroot=None,
             tools="hover,tap,pan,box_select,wheel_zoom,reset",
             plot_width=450,
             plot_height=400):
    """ Make a light-weight norm figure """

    fields = ['zs', 'sizes', 'colors', 'abssnr', 'key', 'snrs']

    if not circleinds: circleinds = range(len(data['snrs']))

    source = ColumnDataSource(
        data=dict({(key,
                    tuple([value[i] for i in circleinds if i not in edgeinds]))
                   for (key, value) in data.iteritems() if key in fields}))
    norm = Figure(plot_width=plot_width,
                  plot_height=plot_height,
                  toolbar_location="left",
                  x_axis_label='SNR observed',
                  y_axis_label='SNR expected',
                  tools=tools,
                  output_backend='webgl')
    norm.circle('abssnr',
                'zs',
                size='sizes',
                line_color=None,
                fill_color='colors',
                fill_alpha=0.2,
                source=source)

    if crossinds:
        sourceneg = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in crossinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        norm.cross('abssnr',
                   'zs',
                   size='sizes',
                   line_color='colors',
                   line_alpha=0.3,
                   source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in edgeinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        norm.circle('abssnr',
                    'zs',
                    size='sizes',
                    line_color='colors',
                    fill_color='colors',
                    source=sourceedge,
                    line_alpha=0.5,
                    fill_alpha=0.2)

    hover = norm.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = norm.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return norm
Esempio n. 12
0
def plotstat(data,
             circleinds=None,
             crossinds=None,
             edgeinds=None,
             url_path=None,
             fileroot=None,
             tools="hover,tap,pan,box_select,wheel_zoom,reset",
             plot_width=450,
             plot_height=400):
    """ Make a light-weight stat figure """

    fields = ['imkur', 'specstd', 'sizes', 'colors', 'snrs', 'key']

    if not circleinds: circleinds = range(len(data['snrs']))

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    specstd = [data['specstd'][i] for i in inds]
    specstd_min = min(specstd)
    specstd_max = max(specstd)
    imkur = [data['imkur'][i] for i in inds]
    imkur_min = min(imkur)
    imkur_max = max(imkur)

    source = ColumnDataSource(
        data=dict({(key,
                    tuple([value[i] for i in circleinds if i not in edgeinds]))
                   for (key, value) in data.iteritems() if key in fields}))
    stat = Figure(plot_width=plot_width,
                  plot_height=plot_height,
                  toolbar_location="left",
                  x_axis_label='Spectral std',
                  y_axis_label='Image kurtosis',
                  x_range=(specstd_min, specstd_max),
                  y_range=(imkur_min, imkur_max),
                  tools=tools,
                  output_backend='webgl')
    stat.circle('specstd',
                'imkur',
                size='sizes',
                line_color=None,
                fill_color='colors',
                fill_alpha=0.2,
                source=source)

    if crossinds:
        sourceneg = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in crossinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        stat.cross('specstd',
                   'imkur',
                   size='sizes',
                   line_color='colors',
                   line_alpha=0.3,
                   source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in edgeinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        stat.circle('specstd',
                    'imkur',
                    size='sizes',
                    line_color='colors',
                    fill_color='colors',
                    source=sourceedge,
                    line_alpha=0.5,
                    fill_alpha=0.2)

    hover = stat.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = stat.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return stat
Esempio n. 13
0
def plotloc(data,
            circleinds=[],
            crossinds=[],
            edgeinds=[],
            url_path=None,
            fileroot=None,
            tools="hover,tap,pan,box_select,wheel_zoom,reset",
            plot_width=450,
            plot_height=400):
    """ Make a light-weight loc figure """

    fields = ['l1', 'm1', 'sizes', 'colors', 'snrs', 'key']

    if not circleinds: circleinds = range(len(data['snrs']))

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    l1 = [data['l1'][i] for i in inds]
    l1_min = min(l1)
    l1_max = max(l1)
    m1 = [data['m1'][i] for i in inds]
    m1_min = min(m1)
    m1_max = max(m1)

    source = ColumnDataSource(
        data=dict({(key,
                    tuple([value[i] for i in circleinds if i not in edgeinds]))
                   for (key, value) in data.iteritems() if key in fields}))
    loc = Figure(plot_width=plot_width,
                 plot_height=plot_height,
                 toolbar_location="left",
                 x_axis_label='l1 (rad)',
                 y_axis_label='m1 (rad)',
                 x_range=(l1_min, l1_max),
                 y_range=(m1_min, m1_max),
                 tools=tools,
                 output_backend='webgl')
    loc.circle('l1',
               'm1',
               size='sizes',
               line_color=None,
               fill_color='colors',
               fill_alpha=0.2,
               source=source)

    if crossinds:
        sourceneg = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in crossinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        loc.cross('l1',
                  'm1',
                  size='sizes',
                  line_color='colors',
                  line_alpha=0.3,
                  source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in edgeinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        loc.circle('l1',
                   'm1',
                   size='sizes',
                   line_color='colors',
                   fill_color='colors',
                   source=sourceedge,
                   line_alpha=0.5,
                   fill_alpha=0.2)

    hover = loc.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = loc.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return loc
Esempio n. 14
0
def plotdmt(data,
            circleinds=[],
            crossinds=[],
            edgeinds=[],
            url_path=None,
            fileroot=None,
            tools="hover,tap,pan,box_select,wheel_zoom,reset",
            plot_width=950,
            plot_height=500):
    """ Make a light-weight dm-time figure """

    fields = ['dm', 'time', 'sizes', 'colors', 'snrs', 'key']

    if not circleinds: circleinds = range(len(data['snrs']))

    # set ranges
    datalen = len(data['dm'])
    inds = circleinds + crossinds + edgeinds
    dm = [data['dm'][i] for i in inds]
    dm_min = min(min(dm), max(dm) / 1.2)
    dm_max = max(max(dm), min(dm) * 1.2)
    time = [data['time'][i] for i in inds]
    time_min = min(time)
    time_max = max(time)

    source = ColumnDataSource(
        data=dict({(key,
                    tuple([value[i] for i in circleinds if i not in edgeinds]))
                   for (key, value) in data.iteritems() if key in fields}))
    dmt = Figure(plot_width=plot_width,
                 plot_height=plot_height,
                 toolbar_location="left",
                 x_axis_label='Time (s; relative)',
                 y_axis_label='DM (pc/cm3)',
                 x_range=(time_min, time_max),
                 y_range=(dm_min, dm_max),
                 output_backend='webgl',
                 tools=tools)
    dmt.circle('time',
               'dm',
               size='sizes',
               fill_color='colors',
               line_color=None,
               fill_alpha=0.2,
               source=source)

    if crossinds:
        sourceneg = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in crossinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        dmt.cross('time',
                  'dm',
                  size='sizes',
                  fill_color='colors',
                  line_alpha=0.3,
                  source=sourceneg)

    if edgeinds:
        sourceedge = ColumnDataSource(
            data=dict({(key, tuple([value[i] for i in edgeinds]))
                       for (key, value) in data.iteritems() if key in fields}))
        dmt.circle('time',
                   'dm',
                   size='sizes',
                   line_color='colors',
                   fill_color='colors',
                   line_alpha=0.5,
                   fill_alpha=0.2,
                   source=sourceedge)
    hover = dmt.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([('SNR', '@snrs'), ('key', '@key')])

    if url_path and fileroot:
        #        url = '{}/cands_{}_sc@scan-seg@seg-i@candint-dm@[email protected]'.format(url_path, fileroot)
        url = '{}/cands_{}[email protected]'.format(url_path, fileroot)
        taptool = dmt.select(type=TapTool)
        taptool.callback = OpenURL(url=url)

    return dmt