Exemple #1
0
def write_recovery(page, injList):
    """
        Write injection recovery plots to markup.page object page
    """

    th = [''] + injList
    td = []

    plots = ['sky_error_time', 'sky_error_mchirp', 'sky_error_distance']
    text = { 'sky_error_time':'Sky error vs time',\
                      'sky_error_mchirp':'Sky error vs mchirp',\
                      'sky_error_distance':'Sky error vs distance' }

    for row in plots:
        pTag = text[row]
        d = [pTag]
        for inj in injList:
            plot = markup.page()
            plot = markup.page()
            p = "%s/efficiency_OFFTRIAL_1/found_%s.png" % (inj, row)
            plot.a(href=p, title=pTag)
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    page = write_table(page, th, td)

    return page
Exemple #2
0
def write_recovery(page, injList):

    """
        Write injection recovery plots to markup.page object page
    """

    th = ['']+injList
    td = []

    plots = ['sky_error_time','sky_error_mchirp','sky_error_distance']
    text = { 'sky_error_time':'Sky error vs time',\
                      'sky_error_mchirp':'Sky error vs mchirp',\
                      'sky_error_distance':'Sky error vs distance' }

    for row in plots:
        pTag = text[row]
        d = [pTag]
        for inj in injList:
            plot = markup.page()
            plot = markup.page()
            p = "%s/efficiency_OFFTRIAL_1/found_%s.png" % (inj, row)
            plot.a(href=p, title=pTag)
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    page = write_table(page, th, td)

    return page
Exemple #3
0
def write_loudest_events(page, bins, onsource=False):

    """
        Write injection chisq plots to markup.page object page
    """

    th = ['']+['Mchirp %s - %s' % tuple(bin) for bin in bins]
    td = []

    plots = ['BestNR','SNR']

    if onsource:
        trial = 'ONSOURCE'
    else:
        trial = 'OFFTRIAL_1'

    for pTag in plots:
        row = pTag.lower()
        d = [pTag]
        for bin in bins:
            b = '%s_%s' % tuple(bin)
            plot = markup.page()
            p = "%s/efficiency/%s_vs_fap_%s.png" % (trial, row, b)
            plot.a(href=p, title="FAP versus %s" % pTag)
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    row = 'snruncut'
    d = ['SNR after cuts <br> have been applied']
    for bin in bins:
        b = '%s_%s' % tuple(bin)
        plot = markup.page()
        p = "%s/efficiency/%s_vs_fap_%s.png" % (trial, row, b)
        plot.a(href=p, title="FAP versus %s" % pTag)
        plot.img(src=p)
        plot.a.close()
        d.append(plot())
    td.append(d)

    page = write_table(page, th, td)

    page.add('For more details on the loudest offsource events see')
    page.a(href='%s/efficiency/loudest_offsource_trigs.html' % (trial))
    page.add('here.')
    page.a.close()


    return page
Exemple #4
0
def write_loudest_events(page, bins, onsource=False):

    """
        Write injection chisq plots to markup.page object page
    """

    th = ['']+['Mchirp %s - %s' % tuple(bin) for bin in bins]
    td = []

    plots = ['BestNR','SNR']

    if onsource:
        trial = 'ONSOURCE'
    else:
        trial = 'OFFTRIAL_1'

    for pTag in plots:
        row = pTag.lower()
        d = [pTag]
        for bin in bins:
            b = '%s_%s' % tuple(bin)
            plot = markup.page()
            p = "%s/efficiency/%s_vs_fap_%s.png" % (trial, row, b)
            plot.a(href=p, title="FAP versus %s" % pTag)
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    row = 'snruncut'
    d = ['SNR after cuts <br> have been applied']
    for bin in bins:
        b = '%s_%s' % tuple(bin)
        plot = markup.page()
        p = "%s/efficiency/%s_vs_fap_%s.png" % (trial, row, b)
        plot.a(href=p, title="FAP versus %s" % pTag)
        plot.img(src=p)
        plot.a.close()
        d.append(plot())
    td.append(d)

    page = write_table(page, th, td)

    page.add('For more details on the loudest offsource events see')
    page.a(href='%s/efficiency/loudest_offsource_trigs.html' % (trial))
    page.add('here.')
    page.a.close()


    return page
def init_page(head, banner, menu, **kwargs):
    """
    Initialise html into markup page, including <head> tag, banner and menu.
    Pass further html elements to the body tag using the kwargs.
  """

    # write html
    page = markup.page()
    page._escape = False

    # initialise page
    page.add("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "+\
             "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
    page.html(xmlns="http://www.w3.org/1999/xhtml", lang="en",\
              **{"xml:lang":"en"})
    page.add(head())

    # open body
    page.body(**kwargs)

    # open container for page (needed to position footer)
    page.div(id="container")
    # add banner
    page.add(banner())
    # open content (tab below banner and above footer)
    page.div(id="content")
    page.div()
    # print menu
    page.add(menu())
    # initialise maintab
    page.div(id="maintab")

    return page
def write_menu(sections, pages, current=None):
    """
    Returns glue.markup.page object for <div id="menubar">, constructing menu
    in HTML.

    Arguments:

      sections : list
        ordered list of menu entry names
      pages : dict
        dict of section:href pairs holding link paths for each element of
        sections list
  """

    page = markup.page(mode="strict_html")
    page._escape = False

    page.div(id="menubar")

    for i, sec in enumerate(sections):
        if sec == current: cl = "menulink selected"
        else: cl = "menulink"
        page.a(sec, id="link_%d" % i, class_=cl, href=pages[sec])

    page.script("", type="text/javascript")

    page.div.close()

    return page
def init_page(head, banner, menu, **kwargs):

  """
    Initialise html into markup page, including <head> tag, banner and menu.
    Pass further html elements to the body tag using the kwargs.
  """

  # write html
  page = markup.page()
  page._escape = False

  # initialise page
  page.add("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "+\
           "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
  page.html(xmlns="http://www.w3.org/1999/xhtml", lang="en",\
            **{"xml:lang":"en"})
  page.add(head())

  # open body
  page.body(**kwargs)

  # open container for page (needed to position footer)
  page.div(id="container")
  # add banner
  page.add(banner())
  # open content (tab below banner and above footer)
  page.div(id="content")
  page.div()
  # print menu
  page.add(menu())
  # initialise maintab
  page.div(id="maintab")

  return page
Exemple #8
0
def write_inj_snrs(page, ifos, injList, grbtag):

    """
        Write injection chisq plots to markup.page object page
    """

    if injList:
        th = ['']+injList + ['OFFSOURCE']
    else:
        th= ['','OFFSOURCE']
        injList = ['OFFSOURCE']
    td = []

    ifos = [ifos[i:i+2] for i in range(0, len(ifos), 2)]
    plots = ['null_stat2']+['%s_snr' % ifo for ifo in ifos]

    for row in plots:
        pTag = row.replace('_',' ').title()
        d = [pTag]
        for inj in injList + ['OFFSOURCE']:
            plot = markup.page()
            p = "%s/plots_clustered/GRB%s_%s_vs_snr_zoom.png" % (inj, grbtag,
                                                                 row)
            plot.a(href=p, title="%s %s versus SNR" % (inj, pTag))
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    page = write_table(page, th, td)

    return page
Exemple #9
0
def write_about_page(configfiles):
    """Write a page explaining how a Qscan analysis was completed

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    gpstime  : `float`
        the central GPS time of the analysis
    configfiles : `list` of `str`
        list of paths of the configuration files to embed
    outdir : `str`, optional
        the output directory for the HTML

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    page.h2('On the command line')
    page.p('This page was generated with the command line call shown below.')
    page.pre(' '.join(sys.argv))
    page.h2('Configuration file')
    page.p('Omega scans are configured through INI-format files. The files '
           'used for this analysis are reproduced below in full.')
    for configfile in configfiles:
        page.pre(write_config_html(configfile))
    return page
Exemple #10
0
def write_null_page(reason, context='info'):
    """Write the Hveto results to HTML

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    start  : `int`
        the GPS start time of the analysis
    end : `int`
        the GPS end time of the analysis
    reason : `str`
        the explanation for this null result
    context : `str`, optional
        the bootstrap context class for this result, see the bootstrap
        docs for more details
    outdir : `str`, optional
        the output directory for the HTML

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    # write alert
    page.div(class_='alert alert-%s' % context)
    page.p(reason)
    page.div.close()  # alert
    return page
Exemple #11
0
def write_about_page(configfile):
    """Write a page explaining how an hveto analysis was completed

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    start  : `int`
        the GPS start time of the analysis
    end : `int`
        the GPS end time of the analysis
    configfile : `str`
        the path of the configuration file to embed
    outdir : `str`, optional
        the output directory for the HTML

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    page.h2('Command-line')
    page.pre(' '.join(sys.argv))
    page.h2('Configuration')
    page.pre(write_config_html(configfile))
    return page
Exemple #12
0
def write_hveto_page(rounds, plots):
    """Write the Hveto results to HTML

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    start  : `int`
        the GPS start time of the analysis
    end : `int`
        the GPS end time of the analysis
    rounds : `list` of `HvetoRound`
        the rounds produced by this analysis
    plots : `list` of `str`
        the `list` of summary plots
    outdir : `str`, optional
        the output directory for the HTML

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    page.add(write_summary(rounds, plots))
    page.h2('Round details')
    for r in rounds:
        page.add(write_round(r))
    return page
Exemple #13
0
def write_footer(about=None, date=None):
    """Write a <footer> for an Hveto page

    Parameters
    ----------
    about : `str`, optional
        path of about page to link
    date : `datetime.datetime`, optional
        the datetime representing when this analysis was generated, defaults
        to `~datetime.datetime.now`

    Returns
    -------
    page : `~glue.markup.page`
        the markup object containing the footer HTML
    """
    page = markup.page()
    page.twotags.append('footer')
    markup.element('footer', parent=page)(class_='footer')
    page.div(class_='container')
    # write user/time for analysis
    if date is None:
        date = datetime.datetime.now().replace(second=0, microsecond=0)
    version = get_versions()['version']
    commit = get_versions()['full-revisionid']
    url = 'https://github.com/hveto/hveto/tree/%s' % commit
    hlink = markup.oneliner.a('Hveto version %s' % version,
                              href=url,
                              target='_blank')
    page.p('Page generated using %s by %s at %s' % (hlink, getuser(), date))
    # link to 'about'
    if about is not None:
        page.a('How was this page generated?', href=about)
    markup.element('footer', parent=page).close()
    return page
Exemple #14
0
def write_null_page(reason, context='default'):
    """Write the Qscan results to HTML

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    gpstime  : `float`
        the central GPS time of the analysis
    reason : `str`
        the explanation for this null result
    context : `str`, optional
        the bootstrap context class for this result, see the bootstrap
        docs for more details

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    # write alert
    page.div(class_='alert alert-%s' % context)
    page.p(reason)
    page.div.close()  # alert
    return page
Exemple #15
0
def write_qscan_page(blocks, context):
    """Write the Qscan results to HTML

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    gpstime  : `float`
        the central GPS time of the analysis
    blocks : `dict` of `OmegaChannel`
        the channel blocks scanned in the analysis
    context : `str`, optional
        the type of Bootstrap ``<panel>`` object to use, color-coded by
        GWO standard

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    page.div(class_='banner')
    page.h2('Channel details')
    page.div.close()  # banner
    for key, block in blocks.items():
        page.add(write_block(key, block, context))
    write_summary_table(blocks)
    return page
Exemple #16
0
def write_chisq(page, injList, grbtag):

    """
        Write injection chisq plots to markup.page object page
    """

    if injList:
        th = ['']+injList + ['OFFSOURCE']
    else:
        th= ['','OFFSOURCE']
        injList = ['OFFSOURCE']
    td = []

    plots = ['bank_veto','auto_veto','chi_square', 'mchirp']

    for test in plots:
        pTag = test.replace('_',' ').title()
        d = [pTag]
        for inj in injList + ['OFFSOURCE']:
            plot = markup.page()
            p = "%s/plots_clustered/GRB%s_%s_vs_snr_zoom.png" % (inj, grbtag,
                                                                 test)
            plot.a(href=p, title="%s %s versus SNR" % (inj, pTag))
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
  
        td.append(d)

    page = write_table(page, th, td)

    return page
def write_menu(sections, pages, current=None):

  """
    Returns glue.markup.page object for <div id="menubar">, constructing menu
    in HTML.

    Arguments:

      sections : list
        ordered list of menu entry names
      pages : dict
        dict of section:href pairs holding link paths for each element of
        sections list
  """

  page = markup.page(mode="strict_html")
  page._escape = False

  page.div(id="menubar")

  for i,sec in enumerate(sections):
    if sec==current: cl = "menulink selected"
    else:            cl = "menulink"
    page.a(sec, id="link_%d" % i, class_=cl, href=pages[sec])

  page.script("",type="text/javascript")

  page.div.close()

  return page
Exemple #18
0
def scaffold_plots(plots, nperrow=3):
    """Embed a `list` of images in a bootstrap scaffold

    Parameters
    ----------
    plot : `list` of `FancyPlot`
        the list of image paths to embed
    nperrow : `int`
        the number of images to place in a row (on a desktop screen)

    Returns
    -------
    page : `~glue.markup.page`
        the markup object containing the scaffolded HTML
    """
    page = markup.page()
    x = int(12//nperrow)
    # scaffold plots
    for i, p in enumerate(plots):
        if i % nperrow == 0:
            page.div(class_='row')
        page.div(class_='col-sm-%d' % x)
        page.add(fancybox_img(p))
        page.div.close()  # col
        if i % nperrow == nperrow - 1:
            page.div.close()  # row
    if i % nperrow < nperrow-1:
        page.div.close()  # row
    return page()
Exemple #19
0
def write_flag_html(flag, span, id=0, parent='accordion', context='warning',
                    title=None, plotdir=None, plot_func=None):
    page = markup.page()
    page.div(class_='panel panel-%s' % context)
    page.div(class_='panel-heading')
    if title is None:
        title = flag.name
    page.a(title, class_="panel-title", href='#flag%s' % id,
           **{'data-toggle': 'collapse', 'data-parent': '#%s' % parent})
    page.div.close()
    page.div(id_='flag%s' % id, class_='panel-collapse collapse')
    page.div(class_='panel-body')
    segs = StringIO()
    try:
        flag.active.write(segs, format='segwizard',
                          coltype=type(flag.active[0][0]))
    except IndexError:
        page.p("No segments were found.")
    else:
        page.pre(segs.getvalue())
    page.div.close()
    if plotdir is not None and plot_func is not None:
        flagr = flag.name.replace('-', '_').replace(':', '-', 1)
        png = os.path.join(
            plotdir, '%s-%d-%d.png' % (flagr, span[0], abs(span)))
        plot = plot_func(flag, span)
        plot.save(png)
        page.a(href=png, target='_blank')
        page.img(style="width: 100%;", src=png)
        page.a.close()
    page.div.close()
    page.div.close()
    return page
Exemple #20
0
def write_qscan_page(blocks, context):
    """Write the Qscan results to HTML

    Parameters
    ----------
    ifo : `str`
        the prefix of the interferometer used in this analysis
    gpstime  : `float`
        the central GPS time of the analysis
    blocks : `list` of `OmegaChannelList`
        the channel blocks scanned in the analysis
    context : `str`, optional
        the type of Bootstrap ``<panel>`` object to use, color-coded by
        GWO standard

    Returns
    -------
    index : `str`
        the path of the HTML written for this analysis
    """
    page = markup.page()
    page.add(write_toc(blocks))
    page.h2('Results')
    page.p('The following blocks of channels were scanned for interesting '
           'time-frequency morphology:')
    for block in blocks:
        page.add(write_block(block, context))
    return page
Exemple #21
0
def write_chisq(page, injList, grbtag):
    """
        Write injection chisq plots to markup.page object page
    """

    if injList:
        th = [''] + injList + ['OFFSOURCE']
    else:
        th = ['', 'OFFSOURCE']
        injList = ['OFFSOURCE']
    td = []

    plots = ['bank_veto', 'auto_veto', 'chi_square', 'mchirp']

    for test in plots:
        pTag = test.replace('_', ' ').title()
        d = [pTag]
        for inj in injList + ['OFFSOURCE']:
            plot = markup.page()
            p = "%s/plots_clustered/GRB%s_%s_vs_snr_zoom.png" % (inj, grbtag,
                                                                 test)
            plot.a(href=p, title="%s %s versus SNR" % (inj, pTag))
            plot.img(src=p)
            plot.a.close()
            d.append(plot())

        td.append(d)

    page = write_table(page, th, td)

    return page
Exemple #22
0
def write_inj_snrs(page, ifos, injList, grbtag):
    """
        Write injection chisq plots to markup.page object page
    """

    if injList:
        th = [''] + injList + ['OFFSOURCE']
    else:
        th = ['', 'OFFSOURCE']
        injList = ['OFFSOURCE']
    td = []

    ifos = [ifos[i:i + 2] for i in range(0, len(ifos), 2)]
    plots = ['null_stat2'] + ['%s_snr' % ifo for ifo in ifos]

    for row in plots:
        pTag = row.replace('_', ' ').title()
        d = [pTag]
        for inj in injList + ['OFFSOURCE']:
            plot = markup.page()
            p = "%s/plots_clustered/GRB%s_%s_vs_snr_zoom.png" % (inj, grbtag,
                                                                 row)
            plot.a(href=p, title="%s %s versus SNR" % (inj, pTag))
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    page = write_table(page, th, td)

    return page
Exemple #23
0
def write_offsource(page, args, grbtag, onsource=False):

    """
        Write offsource SNR versus time plots to markup.page object page
    """

    th = ['Re-weighted SNR', 'Coherent SNR']

    if args.time_slides:
        if onsource:
            out_dir = 'ZEROLAG_ALL'
        else:
            out_dir = 'ZEROLAG_OFF'
    else:
        if onsource:
            out_dir = 'ALL_TIMES'
        else:
            out_dir = 'OFFSOURCE'

    plot = markup.page()
    p = "%s/plots_clustered/GRB%s_bestnr_vs_time_noinj.png" % (out_dir, grbtag)
    plot.a(href=p, title="Detection statistic versus time")
    plot.img(src=p)
    plot.a.close()
    td = [ plot() ]

    plot = markup.page()
    p = "%s/plots_clustered/GRB%s_triggers_vs_time_noinj.png" % (out_dir, grbtag)
    plot.a(href=p, title="Coherent SNR versus time")
    plot.img(src=p)
    plot.a.close()
    td.append(plot())

    ifos = [args.ifo_tag[i:i+2] for i in range(0, len(args.ifo_tag), 2)]
    for ifo in ifos:
        th.append('%s SNR' % ifo)
        plot = markup.page()
        p = "%s/plots_clustered/GRB%s_%s_triggers_vs_time_noinj.png"\
            % (out_dir, grbtag, ifo)
        plot.a(href=p, title="%s SNR versus time" % ifo)
        plot.img(src=p)
        plot.a.close()
        td.append(plot())

    page = write_table(page, th, td)

    return page
Exemple #24
0
def write_offsource(page, args, grbtag, onsource=False):
    """
        Write offsource SNR versus time plots to markup.page object page
    """

    th = ['Re-weighted SNR', 'Coherent SNR']

    if args.time_slides:
        if onsource:
            out_dir = 'ZEROLAG_ALL'
        else:
            out_dir = 'ZEROLAG_OFF'
    else:
        if onsource:
            out_dir = 'ALL_TIMES'
        else:
            out_dir = 'OFFSOURCE'

    plot = markup.page()
    p = "%s/plots_clustered/GRB%s_bestnr_vs_time_noinj.png" % (out_dir, grbtag)
    plot.a(href=p, title="Detection statistic versus time")
    plot.img(src=p)
    plot.a.close()
    td = [plot()]

    plot = markup.page()
    p = "%s/plots_clustered/GRB%s_triggers_vs_time_noinj.png" % (out_dir,
                                                                 grbtag)
    plot.a(href=p, title="Coherent SNR versus time")
    plot.img(src=p)
    plot.a.close()
    td.append(plot())

    ifos = [args.ifo_tag[i:i + 2] for i in range(0, len(args.ifo_tag), 2)]
    for ifo in ifos:
        th.append('%s SNR' % ifo)
        plot = markup.page()
        p = "%s/plots_clustered/GRB%s_%s_triggers_vs_time_noinj.png"\
            % (out_dir, grbtag, ifo)
        plot.a(href=p, title="%s SNR versus time" % ifo)
        plot.img(src=p)
        plot.a.close()
        td.append(plot())

    page = write_table(page, th, td)

    return page
Exemple #25
0
def about_page(executable, cmdargs, version=False, filedict={},\
               classdict={"h2":"open", "p":"line", "div":"about"}, init=False):
    """
    Returns a glue.markup.page object formatting the given executable,\
    commandline arguments, and any included files.

    Arguments:

        executable : string
            path of executable file (sys.argv[0])
        cmdargs : iterable
            set of command line arguments (sys.argv[1:])
 
    Keyword arguments:

        filedict : [ dict | iterable ]
            iterable of ("name", filepath) pairs to insert in full into the page
        classdict : dict
            dict containing HTML class strings for each tag used
        init : [ True | False ]
            initialise the markup.page object, adds HTML and BODY tags
    """
    page = markup.page()

    # initialise
    if init: page.init()

    page.h1("About", class_=classdict.get("h1",None))
    page.p("This page was generated with %s using the following tools."\
           % (executable), class_=classdict.get("p",None))

    def pre(h2, content, id_=0):
        page.h2(h2, id_="h2_%s" % id_, onclick="toggleVisible();",\
                class_=classdict.get("h2",None))
        page.div(id_="div_%s" % id_, style="display: block;",\
                 class_=classdict.get("div",None))
        page.pre(content, class_=classdict.get("pre",None))
        page.div.close()

    i = 0

    # write command line
    pre("Command line arguments", " ".join([executable]+cmdargs), id_=i)
    i += 1

    # write version
    if version:
        pre("Version", version, id_=i)
        i += 1
  
    if isinstance(filedict, dict):
        filedict = filedict.iteritems()

    for name,path in filedict:
        pre(name, open(path, "r").read(), id_=i)
        i += 1

    return page
Exemple #26
0
def about_page(executable, cmdargs, version=False, filedict={},\
               classdict={"h2":"open", "p":"line", "div":"about"}, init=False):
    """
    Returns a glue.markup.page object formatting the given executable,\
    commandline arguments, and any included files.

    Arguments:

        executable : string
            path of executable file (sys.argv[0])
        cmdargs : iterable
            set of command line arguments (sys.argv[1:])
 
    Keyword arguments:

        filedict : [ dict | iterable ]
            iterable of ("name", filepath) pairs to insert in full into the page
        classdict : dict
            dict containing HTML class strings for each tag used
        init : [ True | False ]
            initialise the markup.page object, adds HTML and BODY tags
    """
    page = markup.page()

    # initialise
    if init: page.init()

    page.h1("About", class_=classdict.get("h1", None))
    page.p("This page was generated with %s using the following tools."\
           % (executable), class_=classdict.get("p",None))

    def pre(h2, content, id_=0):
        page.h2(h2, id_="h2_%s" % id_, onclick="toggleVisible();",\
                class_=classdict.get("h2",None))
        page.div(id_="div_%s" % id_, style="display: block;",\
                 class_=classdict.get("div",None))
        page.pre(content, class_=classdict.get("pre", None))
        page.div.close()

    i = 0

    # write command line
    pre("Command line arguments", " ".join([executable] + cmdargs), id_=i)
    i += 1

    # write version
    if version:
        pre("Version", version, id_=i)
        i += 1

    if isinstance(filedict, dict):
        filedict = filedict.iteritems()

    for name, path in filedict:
        pre(name, open(path, "r").read(), id_=i)
        i += 1

    return page
Exemple #27
0
def initialize_page(title, style, script, header=None):
    """
    A function that returns a markup.py page object with the required html
    header.
    """

    page = markup.page(mode="strict_html")
    page._escape = False
    page.init(title=title, css=style, script=script, header=header)

    return page
Exemple #28
0
def initialize_page(title, style, script, header=None):
    """
    A function that returns a markup.py page object with the required html
    header.
    """

    page = markup.page(mode="strict_html")
    page._escape = False
    page.init(title=title, css=style, script=script, header=header)

    return page
Exemple #29
0
def write_found_missed(page, args, injList):

    """
        Write injection found/missed plots to markup.page object page
    """

    th = ['']+injList
    td = []

    #FIXME: Work out a way to make externals calls safely
    #d = ['Number of injections']
    #for inj in injList:
    #    cmmnd = 'lwtprint ../*' + inj + '*MISSED*xml -t sim_inspiral | wc -l'
    #    output,status = make_external_call(cmmnd, shell=True)
    #    numInjs = int(output)
    #    cmmnd = 'lwtprint ../*' + inj + '*FOUND*xml -t sim_inspiral | wc -l'
    #    output,status = make_external_call(cmmnd, shell=True)
    #    numInjs += int(output)
    #    d.append(str(numInjs))
    #td.append(d)

    plots = []
    text  = {}
    ifos = [args.ifo_tag[i:i+2] for i in range(0, len(args.ifo_tag), 2)]
    plots.extend(['dist', 'dist_time'])
    text['dist'] = 'Dist vs Mchirp'
    text['dist_time'] = 'Dist vs Time'
    for ifo in ifos:
        plots.extend(['effdist_%s' % ifo[0].lower(),\
                      'effdist_time_%s' % ifo[0].lower()])
        text['effdist_%s' % ifo[0].lower()] = 'Eff. dist. %s vs Mchirp' % ifo
        text['effdist_time_%s' % ifo[0].lower()] = 'Eff. dist %s vs Time' % ifo

    for row in plots:
        pTag = text[row]
        d = [pTag]
        for inj in injList:
            plot = markup.page()
            p = "%s/efficiency_OFFTRIAL_1/found_missed_injections_%s.png"\
                % (inj, row)
            plot.a(href=p, title=pTag)
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    td.append(['Close injections without FAP = 0']+\
              ['<a href="%s/efficiency_OFFTRIAL_1/quiet_found_triggers.html"> '
               'here</a>' % inj for inj in injList])

    page = write_table(page, th, td)

    return page
Exemple #30
0
def write_found_missed(page, args, injList):

    """
        Write injection found/missed plots to markup.page object page
    """

    th = ['']+injList
    td = []

    #FIXME: Work out a way to make externals calls safely
    #d = ['Number of injections']
    #for inj in injList:
    #    cmmnd = 'lwtprint ../*' + inj + '*MISSED*xml -t sim_inspiral | wc -l'
    #    output,status = make_external_call(cmmnd, shell=True)
    #    numInjs = int(output)
    #    cmmnd = 'lwtprint ../*' + inj + '*FOUND*xml -t sim_inspiral | wc -l'
    #    output,status = make_external_call(cmmnd, shell=True)
    #    numInjs += int(output)
    #    d.append(str(numInjs))
    #td.append(d)

    plots = []
    text  = {}
    ifos = [args.ifo_tag[i:i+2] for i in range(0, len(args.ifo_tag), 2)]
    plots.extend(['dist', 'dist_time'])
    text['dist'] = 'Dist vs Mchirp'
    text['dist_time'] = 'Dist vs Time'
    for ifo in ifos:
        plots.extend(['effdist_%s' % ifo[0].lower(),\
                      'effdist_time_%s' % ifo[0].lower()])
        text['effdist_%s' % ifo[0].lower()] = 'Eff. dist. %s vs Mchirp' % ifo
        text['effdist_time_%s' % ifo[0].lower()] = 'Eff. dist %s vs Time' % ifo

    for row in plots:
        pTag = text[row]
        d = [pTag]
        for inj in injList:
            plot = markup.page()
            p = "%s/efficiency_OFFTRIAL_1/found_missed_injections_%s.png"\
                % (inj, row)
            plot.a(href=p, title=pTag)
            plot.img(src=p)
            plot.a.close()
            d.append(plot())
        td.append(d)

    td.append(['Close injections without FAP = 0']+\
              ['<a href="%s/efficiency_OFFTRIAL_1/quiet_found_triggers.html"> '
               'here</a>' % inj for inj in injList])

    page = write_table(page, th, td)

    return page
def write_head(title, css, js, base=None, refresh=None, jquery=True):

  """
    Returns glue.markup.page object with <head> tag filled.

    Arguments:

      title : string
        text for <title> tag
      css : string
        relative path to style sheet
      js : string
        relative path to javascript

    Keyword arguments:

      base : string
        absolute http(s) path of url base
      refresh : int
        number of seconds after which to refresh page automatically
      jquery : [ True | False ]
        import jquery AJAX script in header, default: True
  """

  # generate object
  page = markup.page(mode="strict_html")
  page._escape = False

  # open head
  page.head()
  # add base
  if base:
    page.base(href=base)
  # add html auto-refresh
  if refresh:
    page.meta(http_equiv="refresh", content="%s" % refresh)
  # link stylesheet
  if isinstance(css, str): css = [css]
  for c in css:
    page.link(media="all", href=c, type="text/css", rel="stylesheet")
  # add title
  page.title(title)

  if jquery:
    page.script("", src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0"\
                    "/jquery.min.js", type="text/javascript")
  if isinstance(js, str): js = [js]
  for j in js:
    page.script("", src=j, type="text/javascript")
  page.head.close()

  return page
def write_head(title, css, js, base=None, refresh=None, jquery=True):
    """
    Returns glue.markup.page object with <head> tag filled.

    Arguments:

      title : string
        text for <title> tag
      css : string
        relative path to style sheet
      js : string
        relative path to javascript

    Keyword arguments:

      base : string
        absolute http(s) path of url base
      refresh : int
        number of seconds after which to refresh page automatically
      jquery : [ True | False ]
        import jquery AJAX script in header, default: True
  """

    # generate object
    page = markup.page(mode="strict_html")
    page._escape = False

    # open head
    page.head()
    # add base
    if base:
        page.base(href=base)
    # add html auto-refresh
    if refresh:
        page.meta(http_equiv="refresh", content="%s" % refresh)
    # link stylesheet
    if isinstance(css, str): css = [css]
    for c in css:
        page.link(media="all", href=c, type="text/css", rel="stylesheet")
    # add title
    page.title(title)

    if jquery:
        page.script("", src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0"\
                        "/jquery.min.js", type="text/javascript")
    if isinstance(js, str): js = [js]
    for j in js:
        page.script("", src=j, type="text/javascript")
    page.head.close()

    return page
Exemple #33
0
def write_summary(
        ifo,
        gpstime,
        header='Analysis Summary',
        tableclass='table table-condensed table-hover table-responsive'):
    """Write the Qscan analysis summary HTML

    Parameters
    ----------
    ifo : `str`
        the interferometer prefix
    gpstime : `float`
        the central GPS time of the analysis
    header : `str`, optional
        the text for the section header (``<h2``>)
    tableclass : `str`, optional
        the ``class`` for the summary ``<table>``

    Returns
    -------
    page : `~glue.markup.page`
        the formatted markup object containing the analysis summary table
    """
    utc = tconvert(gpstime)
    page = markup.page()
    page.h2(header)
    page.p('This page shows time-frequency maps of a user-configured list of '
           'channels for a given interferometer and GPS time. Time-frequency '
           'maps are computed using the <a '
           'href="https://gwpy.github.io/docs/stable/examples/timeseries/'
           'qscan.html" target="_blank">Q-transform</a>.')
    page.p("This analysis is based on the following run arguments.")
    page.table(class_=tableclass)
    # make table body
    page.tbody()
    page.tr()
    page.td("<b>Interferometer</b>")
    page.td("%s (%s)" % (OBSERVATORY_MAP[ifo]['name'], ifo))
    page.tr.close()
    page.tr()
    page.td("<b>UTC Time</b>")
    page.td("%s" % utc)
    page.tr.close()
    page.tbody.close()
    # close table
    page.table.close()
    return page()
def write_banner(title, text=""):
    """
    Returns glue.markup.page object for <div id="header">
  """

    page = markup.page(mode="strict_html")
    page._escape = False

    page.div(class_="content", id="header")
    page.div()
    page.h1(title)
    page.h3(text)
    page.div.close()

    page.div.close()

    return page
Exemple #35
0
def write_menu(sections, pages, current=None, classdict={"a":"menulink"}):

    """
    Returns glue.markup.page object for <div id_="menubar">, constructing menu
    in HTML.

    Arguments:

        sections : list
            ordered list of menu entry names
        pages : dict
            dict of section:href pairs holding link paths for each element of
            sections list

    Keyword arguments:

        current : str
            element of sections list to identify with class="open"
        classdict : dict
            dict of tag:class pairs for setting HTML tags

    """

    page = markup.page()
    page.div(id_="menubar", class_=classdict.get("div", ""))

    for i,sec in enumerate(sections):
        # set current class
        if sec == current and not re.search("open", classdict.get("a", "")):
           cl = classdict["a"] + " open"
        else:
           cl = classdict["a"]

        # remove index.html to make url look nicer
        if pages[sec].endswith("/index.html"):
            href = pages[sec][:-11]
        else:
            href = pages[sec]

        # make link
        page.a(sec, id_="a_%d" % i, class_=cl, href=href)

    page.div.close()

    return page
Exemple #36
0
def new_bootstrap_page(*args, **kwargs):
    """Create a new `~markup.page` with twitter bootstrap CSS and JS headers
    """
    # add bootstrap CSS if needed
    css = kwargs.pop('css', [])
    if BOOTSTRAP_CSS not in css:
        css.insert(0, BOOTSTRAP_CSS)
    # add jquery and bootstrap JS if needed
    script = kwargs.pop('script', [])
    for js in [BOOTSTRAP_JS, JQUERY_JS]:
        if js not in script:
            script.insert(0, js)
    # create page and init
    kwargs['css'] = css
    kwargs['script'] = script
    page = markup.page()
    page.init(*args, **kwargs)
    return page
def write_banner(title, text=""):

  """
    Returns glue.markup.page object for <div id="header">
  """

  page = markup.page(mode="strict_html")
  page._escape = False

  page.div(class_="content", id="header")
  page.div()
  page.h1(title)
  page.h3(text)
  page.div.close()

  page.div.close()

  return page
Exemple #38
0
def new_bootstrap_page(*args, **kwargs):
    """Create a new `~markup.page` with twitter bootstrap CSS and JS headers
    """
    # add bootstrap CSS if needed
    css = kwargs.pop('css', [])
    if BOOTSTRAP_CSS not in css:
        css.insert(0, BOOTSTRAP_CSS)
    # add jquery and bootstrap JS if needed
    script = kwargs.pop('script', [])
    for js in [BOOTSTRAP_JS, JQUERY_JS]:
        if js not in script:
            script.insert(0, js)
    # create page and init
    kwargs['css'] = css
    kwargs['script'] = script
    page = markup.page()
    page.init(*args, **kwargs)
    return page
Exemple #39
0
def write_menu(sections, pages, current=None, classdict={"a": "menulink"}):
    """
    Returns glue.markup.page object for <div id_="menubar">, constructing menu
    in HTML.

    Arguments:

        sections : list
            ordered list of menu entry names
        pages : dict
            dict of section:href pairs holding link paths for each element of
            sections list

    Keyword arguments:

        current : str
            element of sections list to identify with class="open"
        classdict : dict
            dict of tag:class pairs for setting HTML tags

    """

    page = markup.page()
    page.div(id_="menubar", class_=classdict.get("div", ""))

    for i, sec in enumerate(sections):
        # set current class
        if sec == current and not re.search("open", classdict.get("a", "")):
            cl = classdict["a"] + " open"
        else:
            cl = classdict["a"]

        # remove index.html to make url look nicer
        if pages[sec].endswith("/index.html"):
            href = pages[sec][:-11]
        else:
            href = pages[sec]

        # make link
        page.a(sec, id_="a_%d" % i, class_=cl, href=href)

    page.div.close()

    return page
Exemple #40
0
def write_glossary(entries, htag="h1",\
                   classdict={"p":"line", "h4":"glossary closed"}):
    """
    Write a glossary of DQ terms into the glue.markup.page object page using the
    list of (term,definition) tuples terms.

    Arguments:

        entries : dict
            dict of term:definition pairs for inclusion in glossary

    Keyword arguments:

        htag : str
            HTML tag to use for header, default <h1>
        classdict : dict
            dict of tag:class pairs for HTML class assignment
    """

    page = markup.page()

    # write heading and description
    getattr(page, htag)("Glossary", id_="%s_glossary" % htag)
    page.div(id_="div_glossary", style="display: block;",\
             class_=classdict.get("div", ""),  onclick="toggleVisible();")
    page.p("This section gives a glossary of terms relevant to this page.",\
           class_=classdict.get("p", ""))
    lvwiki = "https://www.lsc-group.phys.uwm.edu/ligovirgo/cbcnote/Acronyms"
    page.p("The LIGO-Virgo acronym wiki can be found on %s."\
           % markup.oneliner.a("this page", href=lvwiki),\
           class_=classdict.get("p", ""))

    # write glossary table
    terms = sorted(entries.keys())
    for i,term in enumerate(terms):
        page.h4(term, id_="glossaryh4_%d" % i, class_=classdict.get("h4", ""))
        page.div(entries[term], id_="div_%d" % i, style="display: none;",\
                 class_="glossary")

    page.div.close()

    return page
Exemple #41
0
def fancybox_img(img, linkparams=dict(), **params):
    """Return the markup to embed an <img> in HTML

    Parameters
    ----------
    img : `FancyPlot`
        a `FancyPlot` object containing the path of the image to embed
        and its caption to be displayed
    linkparams : `dict`
        the HTML attributes for the ``<a>`` tag
    **params
        the HTML attributes for the ``<img>`` tag

    Returns
    -------
    html : `str`
    Notes
    -----
    See `~gwdetchar.omega.plot.FancyPlot` for more about the `FancyPlot` class.
    """
    page = markup.page()
    aparams = {
        'title': img.caption,
        'class_': 'fancybox',
        'target': '_blank',
        'data-fancybox-group': 'qscan-image',
    }
    aparams.update(linkparams)
    img = str(img)
    substrings = os.path.basename(img).split('-')
    channel = '%s-%s' % tuple(substrings[:2])
    duration = substrings[-1].split('.')[0]
    page.a(href=img, id_='a_%s_%s' % (channel, duration), **aparams)
    imgparams = {
        'alt': os.path.basename(img),
        'class_': 'img-responsive',
    }
    imgparams['src'] = img
    imgparams.update(params)
    page.img(id_='img_%s_%s' % (channel, duration), **imgparams)
    page.a.close()
    return str(page)
Exemple #42
0
def write_glossary(entries, htag="h1",\
                   classdict={"p":"line", "h4":"glossary closed"}):
    """
    Write a glossary of DQ terms into the glue.markup.page object page using the
    list of (term,definition) tuples terms.

    Arguments:

        entries : dict
            dict of term:definition pairs for inclusion in glossary

    Keyword arguments:

        htag : str
            HTML tag to use for header, default <h1>
        classdict : dict
            dict of tag:class pairs for HTML class assignment
    """

    page = markup.page()

    # write heading and description
    getattr(page, htag)("Glossary", id_="%s_glossary" % htag)
    page.div(id_="div_glossary", style="display: block;",\
             class_=classdict.get("div", ""),  onclick="toggleVisible();")
    page.p("This section gives a glossary of terms relevant to this page.",\
           class_=classdict.get("p", ""))
    lvwiki = "https://www.lsc-group.phys.uwm.edu/ligovirgo/cbcnote/Acronyms"
    page.p("The LIGO-Virgo acronym wiki can be found on %s."\
           % markup.oneliner.a("this page", href=lvwiki),\
           class_=classdict.get("p", ""))

    # write glossary table
    terms = sorted(entries.keys())
    for i, term in enumerate(terms):
        page.h4(term, id_="glossaryh4_%d" % i, class_=classdict.get("h4", ""))
        page.div(entries[term], id_="div_%d" % i, style="display: none;",\
                 class_="glossary")

    page.div.close()

    return page
Exemple #43
0
def write_footer(about=None, date=None):
    """Write a <footer> for a Qscan page

    Parameters
    ----------
    about : `str`, optional
        path of about page to link
    date : `datetime.datetime`, optional
        the datetime representing when this analysis was generated, defaults
        to `~datetime.datetime.now`

    Returns
    -------
    page : `~glue.markup.page`
        the markup object containing the footer HTML
    """
    page = markup.page()
    page.twotags.append('footer')
    markup.element('footer', case=page.case, parent=page)(class_='footer')
    page.div(class_='container')
    # write user/time for analysis
    if date is None:
        date = datetime.datetime.now().replace(second=0, microsecond=0)
    version = __version__
    url = 'https://github.com/ligovirgo/gwdetchar'
    hlink = markup.oneliner.a('GW-DetChar version %s' % version, href=url,
                              target='_blank', style='color:#eee;')
    page.div(class_='row')
    page.div(class_='col-md-12')
    page.p('Page generated using %s by %s at %s'
           % (hlink, getuser(), date))
    # link to 'about'
    if about is not None:
        page.a('How was this page generated?', href=about, style='color:#eee;')
    page.div.close()  # col-md-12
    page.div.close()  # row
    page.div.close()  # container
    markup.element('footer', case=page.case, parent=page).close()
    return page
Exemple #44
0
def fancybox_img(img, linkparams=dict(), **params):
    """Return the markup to embed an <img> in HTML

    Parameters
    ----------
    img : `str`
        the path of the image to embed
    linkparams : `dict`
        the HTML attributes for the ``<a>`` tag
    **params
        the HTML attributes for the ``<img>`` tag

    Returns
    -------
    html : `str`
    """
    page = markup.page()
    aparams = {
        'title': os.path.basename(img),
        'class_': 'fancybox',
        'rel': 'hveto-image',
        'target': '_blank',
    }
    aparams.update(linkparams)
    page.a(href=img, **aparams)
    imgparams = {
        'alt': os.path.basename(img),
        'class_': 'img-responsive',
    }
    if img.endswith('.svg') and os.path.isfile(img.replace('.svg', '.png')):
        imgparams['src'] = img.replace('.svg', '.png')
    else:
        imgparams['src'] = img
    imgparams.update(params)
    page.img(**imgparams)
    page.a.close()
    return str(page)
Exemple #45
0
def init_markup_page( opts):
  """
  Load the markup module, and initialise the HTML document if the opts 
  argument contains enable_ouput option.

  @param  opts : the user arguments 
  @return page 
  @return extra 
  """
  # Initialise the html output file
  if opts.enable_output:
    try:
      from glue import markup
      from glue.markup import oneliner as extra_oneliner
    except:
      raise ImportError("Require markup.py to generate the html page")

    page = markup.page()
    try:
      page.init(title=__title__)
    except:
      page.init()

  return page, extra_oneliner
Exemple #46
0
def write_banner(title, text='&nbsp;'):
    """
    Write html <title> tag into markup.page object
    """

    page = markup.page(mode="strict_html")
    page._escape = False

    page.div(id="header")
    page.h1()
    page.add(title)
    page.h1.close()
    page.h3()
    page.add(text)
    page.h3.close()

    page.hr(class_="short")
    page.hr(class_="long")

    page.div.close()

    page.div(id="container")

    return page
Exemple #47
0
def write_banner(title, text='&nbsp;'):
    """
    Write html <title> tag into markup.page object
    """

    page = markup.page(mode="strict_html")
    page._escape = False

    page.div(id="header")
    page.h1()
    page.add(title)
    page.h1.close()
    page.h3()
    page.add(text)
    page.h3.close()

    page.hr(class_="short")
    page.hr(class_="long")

    page.div.close()

    page.div(id="container")

    return page
Exemple #48
0
def simple_page(header, htag="h1", desc=None, plotlist=None,
                args=None, version=None, classdict={}, init=False):
    """
    Returns a glue.markup.page object with an h1 heading, descriptive text,\
    some plots, and the arguments used to generate it.

    Designed for embedding/including as a frame in a larger page.

    Arguments:

        header : str
            text to write as header  (<h1>)
        htag : str
            HTML tag to use for header, default <h1>
        desc : str
            descriptive text to print below header(s) (<p>)
        plotlist : list
            list of filepath strings or (path, title) tuples to include
            (<a>,<img>)
        args : [ str | list ]
            string with arguments used to generate plots, or list of arguments
            to be space-separated
        version : str
            code version str/number to include
        classdict : dict
            dict containing HTML class strings for each tag used
        init : [ True | False ]
            initialise the markup.page object, adds HTML and BODY tags
    """

    # generate object
    page = markup.page()

    # initialise
    if init: page.init()

    # print header
    if header is not None:
        getattr(page, htag)(header, class_=classdict.get(htag,""),\
                            id_="%s_simple-page" % htag,
                            onclick="toggleVisible();")

    # set div
    hclass = classdict.get(htag, "open")
    if hclass == "closed":   display="none"
    else:                    display="block"
    page.div(class_=classdict.get("div",""), id_="div_simple-page",\
             style="display: %s;" % display)

    if desc is not None:
        page.p(desc, class_=classdict.get("p",""))

    # add plots
    if plotlist is not None:
        for p in plotlist:
            if isinstance(p, str):
                alt = None
            else:
                p,alt = p
            page.a(href=p, title=alt, class_=classdict.get("a",""))
            page.img(src=p, alt=alt, class_=classdict.get("img",""))
            page.a.close()

    if args is not None:
        page.p("Generated by running:", class_=classdict.get("p",""))
        if not isinstance(args, str):  args = " ".join(args)
        page.pre(args, class_=classdict.get("pre",""))
    if version is not None:
        page.p("Code version: %s" % version, class_=classdict.get("p",""))

    page.div.close()

    return page
Exemple #49
0
def build_page(icon=None, banner=None, homebutton=None, tabs=None,\
               menu=None, frame=None, **initargs):
    """
    Build a complete HTML page from 6 components: icon banner homebutton tabs
    menu frame. All other args passed to glue.markup.page.init function.
    See docstring of that function for help.

    Body is built to the following format:

    <div id_="container">
        <div class="content" id_="header">
            <div>
                <div class="nav">
                    ICON
                </div>
                <div class="frame">
                    BANNER
                </div>
            </div>
        </div>
        <div class="content" id_="tabs">
            <div>
                <div class="nav">
                    HOMEBUTTON
                </div>
                <div class="frame">
                    TABS
                </div>
            </div>
        </div>
        <div class="content" id_="main">
            <div>
                <div class="nav">
                    MENUBAR
                </div>
                <div class="frame">
                    FRAME
                </div>
            </div>
        </div>
    </div>
   
    """

    # setup page object
    page = markup.page()
    initargs.setdefault("doctype", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
    page.init(**initargs)

    page.div(id_="container")

    # build top bar from icon and banner
    if icon is not None or banner is not None:
        page.div(class_="content", id_="header")
        page.div()
        page.div(str(icon), class_="nav", id_="headernav")
        page.div(str(banner), class_="frame", id_="headerframe")
        page.div.close()
        page.div.close()

    # build tab bar from home button and tab buttons
    if homebutton is not None or tabs is not None:
        page.div(class_="content", id_="tabs")
        page.div()
        if not homebutton: homebutton = ""
        page.div(str(homebutton), class_="nav", id_="tabsnav")
        page.div(str(tabs), class_="frame", id_="tabsframe")
        page.div.close()
        page.div.close()

    # build main page from menu and frame
    if menu is not None or frame is not None:
        page.div(class_="content", id_="main")
        page.div()
        page.div(str(menu), class_="nav", id_="mainnav")
        page.div(str(frame), class_="frame", id_="mainframe")
        page.div.close()
        page.div.close()

    page.div.close()

    return page
Exemple #50
0
def write_antenna(page, args, seg_plot=None, grid=False, ipn=False):

    """
    Write antenna factors to merkup.page object page and generate John's
    detector response plot.
    """

    page.h3()
    page.add('Antenna factors and sky locations')
    page.h3.close()

    th = []
    td = []
    th2 = []
    td2 = []

    ifos = [args.ifo_tag[i:i+2] for i in range(0, len(args.ifo_tag), 2)]

    if ipn:
        antenna_ifo = {}
        ra = []
        dec = []
        # FIXME: Remove hardcoding here and show this in all cases
        search_file = open('../../../S5IPN_GRB%s_search_180deg.txt'
                           % args.grb_name)
        for line in search_file:
            ra.append(line.split()[0])
            dec.append(line.split()[1])
        for ifo in ifos:
            antenna_ifo[ifo] = []
            for k, l in zip(ra, dec):
                _, _, _, f_q = antenna.response(args.start_time, float(k),
                                                float(l), 0.0, 0.0, 'degree',
                                                ifo)
                antenna_ifo[ifo].append(round(f_q,3))
        dectKeys = antenna_ifo.keys()
        newList=[]

        for elements in range(len(antenna_ifo.values()[0])):
            newDict={}
            for detectors in range(len(antenna_ifo.keys())):
                newDict[dectKeys[detectors]] = antenna_ifo[\
                                               dectKeys[detectors]][elements]
            for key in newDict.keys():
                th.append(key)
            td.append(newDict.values())        
        page = write_table(page, list(set(th)), td)
    for ifo in ifos:
        _, _, _, f_q = antenna.response(args.start_time, args.ra, args.dec,
                                        0.0, 0.0, 'degree',ifo)
        th.append(ifo)
        td.append(round(f_q, 3))

    #FIXME: Work out a way to make these external calls safely
    #cmmnd = 'projectedDetectorTensor --gps-sec %d --ra-deg %f --dec-deg %f' \
    #         % (args.start_time,args.ra, args.dec)
    #for ifo in ifos:
    #    if ifo == 'H1':
    #        cmmnd += ' --display-lho'
    #    elif ifo == 'L1':
    #        cmmnd += ' --display-llo'
    #    elif ifo == 'V1':
    #        cmmnd += ' --display-virgo'
    #status = make_external_call(cmmnd)

    page = write_table(page, th, td)

#    plot = markup.page()
#    p = "projtens.png"
#    plot.a(href=p, title="Detector response and polarization")
#    plot.img(src=p)
#    plot.a.close()
#    th2 = ['Response Diagram']
#    td2 = [plot() ]

        # FIXME: Add these in!!
#    plot = markup.page()
#    p = "ALL_TIMES/plots_clustered/GRB%s_search.png"\
#        % args.grb_name
#    plot.a(href=p, title="Error Box Search")
#    plot.img(src=p)
#    plot.a.close()
#    th2.append('Error Box Search')
#    td2.append(plot())

#    plot = markup.page()
#    p = "ALL_TIMES/plots_clustered/GRB%s_simulations.png"\
#        % args.grb_name
#    plot.a(href=p, title="Error Box Simulations")
#    plot.img(src=p)
#    plot.a.close()
#    th2.append('Error Box Simulations')
#    td2.append(plot())

    if seg_plot is not None:
        plot = markup.page()
        p = os.path.basename(seg_plot)
        plot.a(href=p, title="Science Segments")
        plot.img(src=p)
        plot.a.close()
        th2.append('Science Segments')
        td2.append(plot())

    plot = markup.page()
    p = "ALL_TIMES/plots_clustered/GRB%s_sky_grid.png"\
            % args.grb_name
    plot.a(href=p, title="Sky Grid")
    plot.img(src=p)
    plot.a.close()
    th2.append('Sky Grid')
    td2.append(plot())

#    plot = markup.page()
#    p = "GRB%s_inspiral_horizon_distance.png"\
#            % args.grb_name
#    plot.a(href=p, title="Inspiral Horizon Distance")
#    plot.img(src=p)
#    plot.a.close()
#    th2.append('Inspiral Horizon Distance')
#    td2.append(plot())

    page = write_table(page, th2, td2)

    return page
Exemple #51
0
def write_table(headers, data, classdict={}):

    """
    Write table into glue.markup.page object. headers are written with <th>,
    multiple columns of data are written with <td>.

    Arguments:

        page : glue.markup.page
            page object into which to write table
        headers : list
            list of table header elements
        data : list
            list (or nested list) of table data elements, list of lists used for
            multiple rows

    Keyword arguments:

        classdict : dict
            dict containing tag:class pairs for table, td, th, and td HTML tags
            "table":"list" prints table with headers and data side-by-side,
            all others print all headers in one row, then all data in one row
            (use list of lists for multiple rows).
    """

    # extract classes
    tclass = classdict.get("table","")
    rclass = classdict.get("tr","")
    hclass = classdict.get("th","")
    dclass = classdict.get("td","")

    page = markup.page()

    # open table
    page.table(class_=tclass)

    # list: print two vertical columns of header:data pairs
    if tclass == "list":
         for i in range(len(headers)):
            page.tr(class_=rclass)
            page.th(str(headers[i]), class_=hclass)
            page.td(str(data[i]), class_=classdict.get(str(data[i]),dclass))
            page.tr.close()

    # otherwise print "standard" table with single header row and multiple data
    # rows
    else:
        page.tr(class_=rclass)
        if len(headers)==1:
            page.th(str(headers[0]), colspan="100%", class_=hclass)
        else:
            for n in headers:
                page.th(str(n), class_=hclass)
        page.tr.close()

        if data and not re.search("list",str(type(data[0]))):
            data = [data]

        for row in data:
            page.tr(class_=rclass)
            for item in map(str, row):
                page.td(item, class_=classdict.get(item,dclass))

    page.table.close()

    return page
  def followup(self, inj, selectIFO, description = None):
    """
    Do the followup procedure for the missed injection 'inj'
    and create the several time-series for INSPIRAL and THINCA.
    The return value is the name of the created html file.
    @param inj: sim_inspiral table of the injection that needs to be
                followed up
    @param selectIFO: the IFO that is investigated
    @param description: Can be used to sieve further this pattern
                        from the description field.
    """
    
    def fill_table(page, contents ):
      """
      Making life easier...
      """
      page.add('<tr>')
      for content in contents:
        page.add('<td>')
        page.add( str(content) )
        page.add('</td>')
      page.add('</tr>')

   
    # get the ID corresponding to this injection
    injection_id = self.findInjection( inj )

    # increase internal number:
    self.number+=1

    ## create the web-page and add a table
    page = markup.page()
    page.h1("Followup missed injection #"+str(self.number)+" in "+selectIFO )
    page.hr()
    page.add('<table border="3" ><tr><td>')
    page.add('<table border="2" >')          
    fill_table( page, ['<b>parameter','<b>value'] )
    fill_table( page, ['Number', self.number] )
    fill_table( page, ['inj ID', injection_id] )
    fill_table( page, ['mass1', '%.2f'% inj.mass1] )
    fill_table( page, ['mass2', '%.2f'%inj.mass2] )
    fill_table( page, ['mtotal', '%.2f' % (inj.mass1+inj.mass2)] )
    fill_table( page, ['mchirp', '%.2f' % (inj.mchirp)] )
    fill_table( page, ['end_time', inj.geocent_end_time] )
    fill_table( page, ['end_time_ns', inj.geocent_end_time_ns] )    
    fill_table( page, ['distance', '%.1f' % inj.distance] )
    fill_table( page, ['eff_dist_h','%.1f' %  inj.eff_dist_h] )
    fill_table( page, ['eff_dist_l','%.1f' %  inj.eff_dist_l] )
    fill_table( page, ['eff_dist_v','%.1f' %  inj.eff_dist_v] )
    fill_table( page, ['eff_dist_g','%.1f' %  inj.eff_dist_g] )  
    fill_table( page, ['playground','%s' %  pipeline.s2play(inj.geocent_end_time)] )    
    page.add('</table></td>')
    
    # print infos to screen if required
    if self.opts.verbose:
      self.print_inj( inj,  injection_id)

    # sieve the cache for the required INSPIRAL and THINCA files
    invest_dict = {}
    for stage, cache in self.triggerCache.iteritems():

      trig_cache = lal.Cache()
      for c in cache:

        # check the time and the injection ID
        if inj.geocent_end_time in c.segment:
          if self.get_injection_id(url = c.url) == injection_id:
            trig_cache.append( c )

      # create a filelist
      file_list = trig_cache.sieve(description = description).pfnlist()
        
      # check if the pfnlist is empty. `
      if len(file_list)==0:
        print >>sys.stderr, "Error: No files found for stage %s in the "\
              "cache for ID %s and time %d; probably mismatch of a "\
              "pattern in the options. " % \
              ( stage, injection_id, inj.geocent_end_time)        
        continue

      # if the stage if THINCA_SECOND...
      if 'THINCA_SECOND' in stage:

        # ... need to loop over the four categories
        for cat in [1,2,3,4]:
          
          select_list=self.select_category( file_list, cat)
          if len(select_list)==0:
            print "WARNING: No THINCA_SECOND files found for category ", cat
            continue
          
          modstage = stage+'_CAT_' + str(cat)
          invest_dict[modstage] = self.investigateTimeseries( select_list, inj, selectIFO, modstage, self.number )

        #sys.exit(0)
      else:
        invest_dict[stage]=self.investigateTimeseries( file_list, inj, selectIFO, stage, self.number)

      
      
    ## print out the result for this particular injection
    page.add('<td><table border="2" >')
    fill_table( page, ['<b>step','<b>F/M', '<b>Rec. SNR', '<b>Rec. mchirp', \
                      '<b>Rec. eff_dist', '<b>Rec. chisq', '<b>Veto ON/OFF'] )

    # loop over the stages and create the table with
    # the various data in it (when available)
    for stage in self.orderLabels:
      if stage in invest_dict:
        result = invest_dict[stage]

        # Fill in the details of the loudest found coinc.
        #found_ifo=''
        #if "INSPIRAL" in stage or "THINCA" in stage:
        found_ifo=''
        loudest_snr=''
        loudest_mchirp=''
        loudest_eff_dist=''
        loudest_chisq=''
        veto_onoff=''

        # add all the IFO's for this coincident
        for ifo in result['foundset']:
          found_ifo += ifo+' '
          
          # Parameters of the loudest trigger, taken from the
          # 'loudest-details' dictionary, created in 'investigateTimeseries'
          loudest_snr += ifo + ': ' + str(result['loudest_details'][ifo]['snr'])+'<br>'
          loudest_mchirp += ifo + ': ' + str(result['loudest_details'][ifo]['mchirp'])+'<br>'
          loudest_eff_dist += ifo + ': ' + str(result['loudest_details'][ifo]['eff_dist'])+'<br>'
          loudest_chisq += ifo + ': ' + str(result['loudest_details'][ifo]['chisq'])+'<br>'
          
          # Check whether some of the ifo times is vetoed
          timeTrigger = float(result['loudest_details'][ifo]['timeTrigger'])
          if (self.vetodict[ifo]):
            veto = self.isThereVeto (timeTrigger, ifo)
            veto_txt = 'OFF'
            if veto:
              veto_txt = 'ON'              
            veto_onoff+=ifo+': '+veto_txt+'<br>'
          else: 
            veto_onoff+=ifo+': No info<br>'

        # Fill the table whether something is found or not
        if len(result['foundset'])>0:
          fill_table( page, [ stage,  'FOUND in '+found_ifo, 'loudest<br>'+loudest_snr, \
                              'loudest<br>'+loudest_mchirp, 'loudest<br>'+loudest_eff_dist,\
                              'loudest<br>'+loudest_chisq, veto_onoff])
        else:
          fill_table( page, [ stage,  '<font color="red">MISSED'])
          
    page.add('</table>')
    page.add('</td></tr></table><br><br>')


    ## add the pictures to the webpage
    for stage in self.orderLabels:
      if stage in invest_dict:
        result = invest_dict[stage]
      
        ##if stage!="TMPLTBANK":
        if True:
          fname = result['filename']
          page.a(extra.img(src=[fname], width=400, \
                           alt=fname, border="2"), title=fname, href=[ fname ])
          
    # add version information
    page.add('<hr>Page created with %s Version %s' % \
        (__prog__, git_version.verbose_msg))
    
    # and write the html file
    htmlfilename = self.opts.prefix + "_"+selectIFO+"_followup_"+str(self.number) +\
                         self.opts.suffix+'.html'
    file = open(self.opts.output_path+htmlfilename,'w')      
    file.write(page(False))
    file.close()

    # store html file in fnameList
    self.fnameList.append(htmlfilename)

    # supply the output
    return htmlfilename
    "that contains the url of the remote qscan result page. For instance: " \
    "--remote-seismic-qscan-web V1,http://virgo.in2p3.fr/followups/romain/" \
    "tests/lv/local_followup_043009/871147814-873567014/CAT3/seismic-qscan/V1/")

command_line = sys.argv[1:]
(opts,args) = parser.parse_args()

##############################################################################
# main program

# List of ifos (used to check for Nelson KW vetoes)
#ifoList = ['H1','H2','L1']

opts = InspiralUtils.initialise(opts, __prog__, git_version.verbose_msg)

page = markup.page(mode="strict_html")
page._escape = False
doctype="""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">"""
doctype+="""\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">"""

title = "Detection Checklist for candidate " + str(opts.trigger_gps.split(",")[0].strip())
page.init(title=title, doctype=doctype)
#page.init(title=title)
page.h1()
page.add("Detection Checklist for Candidate " + str(opts.trigger_gps.split(",")[0].strip()) + " " + opts.ifolist_in_coinc + " in " + opts.ifo_times)
page.h1.close()

page.h2()
page.add("Inspiral triggers found by CBC search:")
page.h2.close()
Exemple #54
0
def summary_page(header=None, htag="h1", desc=None, plotlist=None,
                 text=None, subplots=None, info=None, classdict={},\
                 init=False):
    """
    Returns a glue.markup.page object with an heading, descriptive text,\
    summary section with one plot and text, section with other plots,
    section with subplots, then section with info.

    Designed for embedding/including as a frame in a larger page.

    Keyword arguments:

        header : str
            text to write as header  (<h1>)
        htag : str
            HTML tag to use for header, default <h1>
        desc : str
            descriptive text to print below header(s) (<p>)
        plotlist : list
            list of filepath strings or (path, title) tuples to include
            (<a>,<img>)
        text : [ str | glue.markup.page ]
            text to print below summary plot (<p>), or glue.markup.page to
            drop in with no enclosing tags.
        subplotlist : list
            list of filepath strings or (path, title) tuples to include
            (<a>,<img>)
        info : str
            information to print below summary plot (<p>), or
            glue.markup.page to drop in with no enclosing tags.
        classdict : dict
            dict containing HTML class strings for each tag used
        init : [ True | False ]
            initialise the markup.page object, adds HTML and BODY tags
    """

    # generate object
    page = markup.page()

    # initialise
    if init: page.init()

    # print header
    if header is not None:
        getattr(page, htag)(header, class_=classdict.get(htag,""),\
                            id_="%s_simple-page" % htag,
                            onclick="toggleVisible();")

    # set div
    hclass = classdict.get(htag, "open")
    if hclass == "closed":   display="none"
    else:                    display="block"
    page.div(class_=classdict.get("div"), id_="div_simple-page",\
             style="display: %s;" % display)

    # print description
    if desc is not None:
        page.p(desc, class_=classdict.get("p",""))

    # print first plot
    if plotlist is not None:
        Np = len(plotlist)
        if Np:
            p = plotlist[0]
            if isinstance(p, str):
                alt = None
            else:
                p,alt = p
            page.a(href=p, title=alt, class_=classdict.get("a",""))
            page.img(src=p, alt=alt, class_=classdict.get("img",""))
            page.a.close()

    # print text
    if text is not None:
        if isinstance(markup.page):
            page.add(text())
        else:
            page.p(str(text), class_=classdict.get("p",""))

    # add rest of plots
    if plotlist is not None and Np > 1:
        for p in plotlist[1:]:
            if isinstance(p, str):
                alt = None
            else:
                p,alt = p
            page.a(href=p, title=alt, class_=classdict.get("a",""))
            page.img(src=p, alt=alt, class_=classdict.get("img",""))
            page.a.close()

    if info is not None:
        if isinstance(markup.page):
            page.add(info())
        else:
            page.p(str(info), class_=classdict.get("p",""))

    page.div.close()
Exemple #55
0
def write_exclusion_distances(page , trial, injList, massbins, reduced=False,
                              onsource=False):
    file = open('%s/efficiency/loud_numbers.txt' % (trial), 'r')
    FAPS = []
    for line in file:
        line = line.replace('\n','')
        if float(line) == -2:
            FAPS.append('No event')
        else:
            FAPS.append(float(line))

    file.close()

    th = ['']+['Mchirp %s - %s' % tuple(bin) for bin in massbins]
    td = ['FAP']+FAPS
    page = write_table(page, th, td)
    page.add('For more details on the loudest onsource events see')
    page.a(href='%s/efficiency/loudest_events.html' % (trial))
    page.add('here.')
    page.a.close()

    if reduced or not injList:
        return page  

    page.h3()
    page.add('Detection efficiency plots - injections louder than loudest '
             'background trigger')
    page.h3.close()

    th = injList
    td = []
    d = []
    for inj in injList:
        plot = markup.page()
        p = "%s/efficiency_%s/BestNR_max_efficiency.png" % (inj, trial)
        plot.a(href=p, title="Detection efficiency")
        plot.img(src=p)
        plot.a.close()
        d.append(plot())
    td.append(d)

    page = write_table(page, th, td)

    page.h3()
    page.add('Exclusion distance plots - injections louder than loudest '
             'foreground trigger')
    page.h3.close()

    th = injList
    td = []
    d = []
    for inj in injList:
        plot = markup.page()
        p = "%s/efficiency_%s/BestNR_on_efficiency.png" % (inj, trial)
        plot.a(href=p, title="Exclusion efficiency")
        plot.img(src=p)
        plot.a.close()
        d.append(plot())
    td.append(d)

    page = write_table(page, th, td)

    page.h3()
    page.add('90% confidence exclusion distances (Mpc)')
    th = injList
    td = []
    d = []
    for inj in injList:
        file = open('%s/efficiency_%s/exclusion_distance.txt' % (inj, trial),
                    'r')
        for line in file:
            line = line.replace('\n','')
            excl_dist = float(line)
        d.append(excl_dist)
        file.close()
    td.append(d)

    page = write_table(page, th, td)

    page.h3.close()

    return page
Exemple #56
0
  def write_html_output(self, html_filename, doThumb=True, map_list=[],
                        comment=None, coinc_summ_table=None ):
    """
    @param doThumb: Uses the thumbnail file as the sourcs for the images
    @param map_list: A list of dictionaries to create the image maps
    @param comment: A comment that can be added to the page
    @param coinc_summ_table: A CoincSummTable that can be added to the page
    """

    # Initialise the html output file
    page = markup.page()
    try:
      page.init(title=__title__)
    except:
      page.init()

    page.h1(self.name + " results")

    page.p(self.prefix + self.suffix)
    page.hr()

    # open the output file
    html_file = file(html_filename, "w")

    # loop over the contents
    for tag,filename in zip(self.tag_list, self.fname_list):

      # set the correct name for linking (two '//' does not bother)
      fname = "Images/" + os.path.basename(filename)

      # set the thumbnail pictures if required
      if doThumb:
        fname_thumb = fname[:-4] + "_thumb.png"
      else:
        fname_thumb = fname

      # add the image to the page
      page.a(extra_oneliner.img(src=[fname_thumb], width=400,
          alt=tag, border="2"), title=tag, href=[ fname])

    page.add("<hr/>")

    # add maps to this page
    m=0
    for map_dict in map_list:
      m+=1
      page.add( map_dict['text']+'<br>' )
      page.add( '<IMG src="%s" width=800px '
                'usemap="#map%d">' % ( map_dict['object'], m) )
      page.add( '<MAP name="map%d"> <P>' % m )
      n=0
      for px, py, link in zip( map_dict['xCoords'],
                               map_dict['yCoords'],
                               map_dict['links'] ):
        n+=1
        page.add( '<area href="%s" shape="circle" '
                  'coords="%d, %d, 5"> Point%d</a>' %
                  ( link, px, py, n) )
      page.add('</P></MAP></OBJECT><br>')
      page.add("<hr/>")

    # add some extra stuff if needed
    if comment:
      page.add("<div> "+comment+"</div>")
      page.hr()

    if coinc_summ_table:
      page.add(coinc_summ_table)
      page.hr()

    text = self.write_process_params()
    page.add(text)
    html_file.write(page(False))
    html_file.close()