def test_register_tab(): class TestTab(object): type = 'test' pass tabs.register_tab(TestTab) with pytest.raises(ValueError): tabs.register_tab(TestTab) tabs.register_tab(TestTab, force=True) assert tabs.get_tab('test') is TestTab tabs.register_tab(TestTab, name='test-with-name') assert tabs.get_tab('test-with-name') is TestTab
def test_registry(self): # test get tab = tabs.get_tab('basic') self.assertIs(tab, tabs.Tab) tab = tabs.get_tab('\'plots\'') self.assertIs(tab, tabs.PlotTab) self.assertRaises(ValueError, tabs.get_tab, 'dfskaewf') # test register class TestTab(object): type = 'test' pass tabs.register_tab(TestTab) self.assertRaises(ValueError, tabs.register_tab, TestTab) tabs.register_tab(TestTab, force=True) self.assertIs(tabs.get_tab('test'), TestTab) tabs.register_tab(TestTab, name='test-with-name') self.assertIs(tabs.get_tab('test-with-name'), TestTab)
def write_state_html(self, state): # write results table performance = [(str(m), '%.2f %s' % (r.value, r.unit), m.description.split('\n')[0]) for (m, r) in self.results[state].iteritems()] pre = markup.page() pre.div(class_='scaffold well') pre.strong('Flag performance summary') pre.add( str(data_table(['Metric', 'Result', 'Description'], performance))) pre.div.close() pre.h2('Figures of Merit') # write configuration table post = markup.page() def add_config_entry(title, entry): post.tr() post.th(title) post.td(entry) post.tr.close() post.h2('Analysis configuration') post.div() post.table(class_='table table-condensed table-hover') add_config_entry('Flags', '<br>'.join(map(str, self.flags))) if len(self.flags) > 1 and self.intersection: add_config_entry('Flag combination', 'Intersection (logical AND)') elif len(self.flags) > 1: add_config_entry('Flag combination', 'Union (logical OR)') add_config_entry( 'Analysis start time', '%s (%s)' % (str(Time(float(self.start), format='gps', scale='utc').iso), self.start)) add_config_entry( 'Analysis end time', '%s (%s)' % (str(Time(float(self.end), format='gps', scale='utc').iso), self.end)) add_config_entry('Event trigger channel', str(self.channel)) add_config_entry('Event trigger generator', str(self.etg)) post.table.close() post.div.close() post.h2('Segment information') post.div(class_='panel-group', id="accordion") for i, flag in enumerate([self.metaflag] + self.flags): flag = get_segments(flag, state.active, query=False, padding=self.padding).copy() post.div(class_='panel well panel-primary') post.div(class_='panel-heading') post.a(href='#flag%d' % i, **{ 'data-toggle': 'collapse', 'data-parent': '#accordion' }) if i == 0: post.h4(self.intersection and 'Intersection' or 'Union', class_='panel-title') elif self.labels[i - 1] != str(flag): post.h4('%s (%s)' % (flag.name, self.labels[i - 1]), class_='panel-title') else: post.h4(flag.name, class_='panel-title') post.a.close() post.div.close() post.div(id_='flag%d' % i, class_='panel-collapse collapse') post.div(class_='panel-body') # write segment summary post.p('This flag was defined and had a known state during ' 'the following segments:') post.add(self.print_segments(flag.known)) # write segment table post.p('This flag was active during the following segments:') post.add(self.print_segments(flag.active)) post.div.close() post.div.close() post.div.close() post.div.close() # then write standard data tab return super(get_tab('default'), self).write_state_html(state, plots=True, pre=pre, post=post)
from gwsumm.segments import (get_segments, format_padding) from gwsumm.triggers import (get_triggers, get_etg_table) from gwsumm.tabs import get_tab, register_tab from gwsumm.html import (data_table, markup) from gwsumm.plot import (get_plot, get_column_label) from gwsumm.utils import vprint from gwsumm.state import ALLSTATE from . import etg from .core import evaluate_flag from .triggers import (re_meta, veto_tag) from .metric import get_metric __author__ = 'Duncan Macleod <*****@*****.**>' ParentTab = get_tab('default') class FlagTab(ParentTab): """Tab for analysing veto performance Parameters ---------- name : `str` the name of this analysis, either the name of the flag tested, of a descriptive name for the groups of flags start : `float`, `~gwpy.time.LIGOTimeGPS` the GPS start time of the analysis end : `float`, `~gwpy.time.LIGOTimeGPS` the GPS end time of the analysis flags : `list`, optional
def write_state_html(self, state): # write results table performance = [(str(m), '%.2f %s' % (r.value, r.unit), m.description.split('\n')[0]) for (m, r) in self.results[state].iteritems()] pre = html.markup.page() pre.div(class_='scaffold well') pre.strong('Flag performance summary') pre.add(str(html.table(['Metric', 'Result', 'Description'], performance))) pre.div.close() pre.h2('Figures of Merit') # write configuration table post = html.markup.page() def add_config_entry(title, entry): post.tr() post.th(title) post.td(entry) post.tr.close() post.h2('Analysis configuration') post.div() post.table(class_='table table-condensed table-hover') add_config_entry('Flags', '<br>'.join(map(str, self.flags))) if len(self.flags) > 1 and self.intersection: add_config_entry('Flag combination', 'Intersection (logical AND)') elif len(self.flags) > 1: add_config_entry('Flag combination', 'Union (logical OR)') add_config_entry('Analysis start time', '%s (%s)' % ( str(Time(float(self.start), format='gps', scale='utc').iso), self.start)) add_config_entry('Analysis end time', '%s (%s)' % ( str(Time(float(self.end), format='gps', scale='utc').iso), self.end)) add_config_entry('Event trigger channel', str(self.channel)) add_config_entry('Event trigger generator', str(self.etg)) post.table.close() post.div.close() post.h2('Segment information') post.div(class_='panel-group', id="accordion") for i, flag in enumerate([self.metaflag] + self.flags): flag = get_segments(flag, state.active, query=False, padding=self.padding).copy() post.div(class_='panel well panel-primary') post.div(class_='panel-heading') post.a(href='#flag%d' % i, **{'data-toggle': 'collapse', 'data-parent': '#accordion'}) if i == 0: post.h4(self.intersection and 'Intersection' or 'Union', class_='panel-title') elif self.labels[i-1] != str(flag): post.h4('%s (%s)' % (flag.name, self.labels[i-1]), class_='panel-title') else: post.h4(flag.name, class_='panel-title') post.a.close() post.div.close() post.div(id_='flag%d' % i, class_='panel-collapse collapse') post.div(class_='panel-body') # write segment summary post.p('This flag was defined and had a known state during ' 'the following segments:') post.add(self.print_segments(flag.known)) # write segment table post.p('This flag was active during the following segments:') post.add(self.print_segments(flag.active)) post.div.close() post.div.close() post.div.close() post.div.close() # then write standard data tab return super(get_tab('default'), self).write_state_html( state, plots=True, pre=pre, post=post)
from gwsumm.data import get_channel from gwsumm.segments import (get_segments, format_padding) from gwsumm.triggers import get_triggers from gwsumm.tabs import get_tab, register_tab from gwsumm.plot import (get_plot, get_column_label) from gwsumm.utils import vprint from gwsumm.state import ALLSTATE from . import etg from .core import evaluate_flag from .triggers import (re_meta, veto_tag) from .metric import get_metric __author__ = 'Duncan Macleod <*****@*****.**>' ParentTab = get_tab('default') class FlagTab(ParentTab): """Tab for analysing veto performance Parameters ---------- name : `str` the name of this analysis, either the name of the flag tested, of a descriptive name for the groups of flags start : `float`, `~gwpy.time.LIGOTimeGPS` the GPS start time of the analysis end : `float`, `~gwpy.time.LIGOTimeGPS` the GPS end time of the analysis flags : `list`, optional
def write_state_html(self, state): """Write the content of inner HTML for the given state """ def format_result(res): fmt = '%d' if ( res.value < 0.01 or (res.unit == Unit('%') and res.value > 99.99)) else '%.2f' return ''.join([fmt % res.value, str(res.unit)]) def add_config_entry(page, title, entry): page.tr() page.th(title) page.td(entry) page.tr.close() # write results table performance = [( str(m), format_result(r), m.description.split('\n')[0], ) for (m, r) in self.results[state].items()] pre = markup.page() pre.p(self.foreword) pre.h4('Flag performance summary', class_='mt-4') pre.add( str( gwhtml.table(['Metric', 'Result', 'Description'], performance, id=self.title))) pre.h2('Figures of Merit', class_='mt-4 mb-2') # write configuration table post = markup.page() post.h2('Analysis configuration', class_='mt-4') post.div() post.table(class_='table table-sm table-hover') add_config_entry(post, 'Flags', '<br>'.join(list(map(str, self.flags)))) if len(self.flags) > 1 and self.intersection: add_config_entry(post, 'Flag combination', 'Intersection (logical AND)') elif len(self.flags) > 1: add_config_entry(post, 'Flag combination', 'Union (logical OR)') add_config_entry( post, 'Analysis start time', '%s (%s)' % (str(Time(float(self.start), format='gps', scale='utc').iso), self.start)) add_config_entry( post, 'Analysis end time', '%s (%s)' % (str(Time(float(self.end), format='gps', scale='utc').iso), self.end)) add_config_entry(post, 'Event trigger channel', str(self.channel)) add_config_entry(post, 'Event trigger generator', str(self.etg)) post.table.close() post.div.close() post.h2('Segment information', class_='mt-4') post.div(class_='mt-2', id="accordion") for i, flag in enumerate([self.metaflag] + self.flags): flag = get_segments(flag, state.active, query=False, padding=self.padding).copy() post.div(class_='card border-info mb-1 shadow-sm') post.div(class_='card-header text-white bg-info') if i == 0: title = self.intersection and 'Intersection' or 'Union' elif self.labels[i - 1] != str(flag): title = '%s (%s)' % (flag.name, self.labels[i - 1]) else: title = flag.name post.a(title, class_='card-link cis-link collapsed', href='#flag%d' % i, **{ 'data-toggle': 'collapse', 'aria-expanded': 'false' }) post.div.close() # card-header post.div(id_='flag%d' % i, class_='collapse', **{'data-parent': '#accordion'}) post.div(class_='card-body') # write segment summary post.p('This flag was defined and had a known state during ' 'the following segments:') post.add(self.print_segments(flag.known)) # write segment table post.p('This flag was active during the following segments:') post.add(self.print_segments(flag.active)) post.div.close() # card-body post.div.close() # collapse post.div.close() # card post.div.close() # then write standard data tab return super(get_tab('default'), self).write_state_html(state, plots=True, pre=pre, post=post)
def setup_class(cls): cls.TAB = tabs.get_tab(cls.TYPE)
def test_get_tab(name, tab): assert tabs.get_tab(name) is tab with pytest.raises(ValueError): tabs.get_tab('fasmklwea')
def setUpClass(cls): cls.TAB = tabs.get_tab(cls.TYPE)