Esempio n. 1
0
def test_registry_plot():
    class TestPlot(object):
        type = 'test'
        pass

    gwsumm_plot.register_plot(TestPlot)
    with pytest.raises(ValueError):
        gwsumm_plot.register_plot(TestPlot)
    gwsumm_plot.register_plot(TestPlot, force=True)

    assert gwsumm_plot.get_plot('test') is TestPlot

    gwsumm_plot.register_plot(TestPlot, name='test-with-name')
    assert gwsumm_plot.get_plot('test-with-name') is TestPlot
Esempio n. 2
0
def test_registry_plot():
    class TestPlot(object):
        type = 'test'
        pass

    gwsumm_plot.register_plot(TestPlot)
    with pytest.raises(ValueError):
        gwsumm_plot.register_plot(TestPlot)
    gwsumm_plot.register_plot(TestPlot, force=True)

    assert gwsumm_plot.get_plot('test') is TestPlot

    gwsumm_plot.register_plot(TestPlot, name='test-with-name')
    assert gwsumm_plot.get_plot('test-with-name') is TestPlot
Esempio n. 3
0
 def test_registry(self):
     # test get
     p = plot.get_plot(None)
     self.assertIs(p, plot.SummaryPlot)
     p = plot.get_plot('\'data\'')
     self.assertIs(p, plot.DataPlot)
     self.assertRaises(ValueError, plot.get_plot, 'dfskaewf')
     # test register
     class TestPlot(object):
         type = 'test'
         pass
     plot.register_plot(TestPlot)
     self.assertRaises(ValueError, plot.register_plot, TestPlot)
     plot.register_plot(TestPlot, force=True)
     self.assertIs(plot.get_plot('test'), TestPlot)
     plot.register_plot(TestPlot, name='test-with-name')
     self.assertIs(plot.get_plot('test-with-name'), TestPlot)
Esempio n. 4
0
    def test_registry(self):
        # test get
        p = plot.get_plot(None)
        self.assertIs(p, plot.SummaryPlot)
        p = plot.get_plot('\'data\'')
        self.assertIs(p, plot.DataPlot)
        self.assertRaises(ValueError, plot.get_plot, 'dfskaewf')

        # test register
        class TestPlot(object):
            type = 'test'
            pass

        plot.register_plot(TestPlot)
        self.assertRaises(ValueError, plot.register_plot, TestPlot)
        plot.register_plot(TestPlot, force=True)
        self.assertIs(plot.get_plot('test'), TestPlot)
        plot.register_plot(TestPlot, name='test-with-name')
        self.assertIs(plot.get_plot('test-with-name'), TestPlot)
Esempio n. 5
0
 def setup_class(cls):
     cls.PLOT = gwsumm_plot.get_plot(cls.TYPE)
Esempio n. 6
0
def test_get_plot(name, plot):
    assert gwsumm_plot.get_plot(name) is plot
    with pytest.raises(ValueError):
        gwsumm_plot.get_plot('dfskaewf')
Esempio n. 7
0
    def init_plots(self, plotdir=os.curdir):
        """Configure the default list of plots for this tab

        This method configures a veto-trigger glitchgram, histograms of
        before/after SNR and frequency/template duration,
        before and after glitchgrams, and a segment plot.

        This method is a mess, and should be re-written in a better way.
        """
        if self.intersection:
            label = 'Intersection'
        else:
            label = 'Union'

        self.layout = [
            1,
        ]
        before = get_channel(str(self.channel))
        for state in self.states:
            if self.channel:
                after = get_channel(
                    veto_tag(before, self.metaflag, mode='after'))
                vetoed = get_channel(
                    veto_tag(before, self.metaflag, mode='vetoed'))
                # -- configure trigger plots
                params = etg.get_etg_parameters(self.etg)
                glitchgramargs = {
                    'etg': self.etg,
                    'x': 'time',
                    'y': params['frequency'],
                    'logy': params.get('frequency-log', True),
                    'ylabel': get_column_label(params['frequency']),
                    'edgecolor': 'none',
                    'legend-scatterpoints': 1,
                    'legend-borderaxespad': 0,
                    'legend-bbox_to_anchor': (1.01, 1),
                    'legend-loc': 'upper left',
                }
                # plot before/after glitchgram
                self.plots.append(
                    get_plot('triggers')([after, vetoed],
                                         self.start,
                                         self.end,
                                         state=state,
                                         title='Impact of %s (%s)' %
                                         (label_to_latex(self.name), self.etg),
                                         outdir=plotdir,
                                         labels=['_', 'Vetoed'],
                                         colors=['lightblue', 'red'],
                                         **glitchgramargs))

                # plot histograms
                statistics = ['snr']
                if params['det'] != params['snr']:
                    statistics.append('det')
                self.layout.append(len(statistics) + 1)
                for column in statistics + ['frequency']:
                    self.plots.append(
                        get_plot('trigger-histogram')(
                            [before, after],
                            self.start,
                            self.end,
                            state=state,
                            column=params[column],
                            etg=self.etg,
                            outdir=plotdir,
                            title='Impact of %s (%s)' %
                            (label_to_latex(self.name), self.etg),
                            labels=['Before', 'After'],
                            xlabel=params.get('%s-label' % column,
                                              get_column_label(
                                                  params[column])),
                            color=['red', (0.2, 0.8, 0.2)],
                            logx=params.get('%s-log' % column, True),
                            logy=True,
                            histtype='stepfilled',
                            alpha=0.6,
                            weights=1 / float(abs(self.span)),
                            bins=100,
                            ybound=1 / float(abs(self.span)) * 0.5,
                            **{
                                'legend-borderaxespad': 0,
                                'legend-bbox_to_anchor': (1.01, 1),
                                'legend-loc': 'upper left'
                            }))

                # plot triggers before and after
                for stat in statistics:
                    column = params[stat]
                    glitchgramargs.update({
                        'color':
                        column,
                        'clim':
                        params.get('%s-limits' % stat, [3, 100]),
                        'logcolor':
                        params.get('%s-log' % stat, True),
                        'colorlabel':
                        params.get('%s-label' % stat,
                                   get_column_label(column)),
                    })
                    self.plots.append(
                        get_plot('triggers')([before],
                                             self.start,
                                             self.end,
                                             state=state,
                                             outdir=plotdir,
                                             **glitchgramargs))
                    self.plots.append(
                        get_plot('triggers')(
                            [after],
                            self.start,
                            self.end,
                            state=state,
                            title='After %s (%s)' %
                            (label_to_latex(self.name), self.etg),
                            outdir=plotdir,
                            **glitchgramargs))
                    self.layout.append(2)

            # -- configure segment plot
            segargs = {
                'state': state,
                'known': {
                    'alpha': 0.1,
                    'facecolor': 'lightgray'
                },
                'color': 'red',
            }
            if len(self.flags) == 1:
                sp = get_plot('segments')(self.flags,
                                          self.start,
                                          self.end,
                                          outdir=plotdir,
                                          labels=self.labels,
                                          **segargs)
            else:
                sp = get_plot('segments')(
                    [self.metaflag] + self.flags,
                    self.start,
                    self.end,
                    labels=([self.intersection and 'Intersection' or 'Union'] +
                            self.labels),
                    outdir=plotdir,
                    **segargs)
            self.plots.append(sp)
            self.layout.append(1)
Esempio n. 8
0
    def init_plots(self, plotdir=os.curdir):
        """Configure the default list of plots for this tab

        This method configures a veto-trigger glitchgram, histograms of
        before/after SNR and frequency/template duration,
        before and after glitchgrams, and a segment plot.

        This method is a mess, and should be re-written in a better way.
        """
        if self.intersection:
            label = 'Intersection'
        else:
            label = 'Union'

        etgstr = self.etg.replace('_', r'\\_')

        self.set_layout([1,])
        before = get_channel(str(self.channel))
        for state in self.states:
            if self.channel:
                after = get_channel(veto_tag(before, self.metaflag,
                                             mode='after'))
                vetoed = get_channel(veto_tag(before, self.metaflag,
                                              mode='vetoed'))
                # -- configure trigger plots
                params = etg.get_etg_parameters(self.etg, IFO=before.ifo)
                glitchgramargs = {
                    'etg': self.etg,
                    'x': params['time'],
                    'y': params['frequency'],
                    'logy': params.get('frequency-log', True),
                    'ylabel': params.get('frequency-label',
                                         get_column_label(params['frequency'])),
                    'edgecolor': 'none',
                    'legend-scatterpoints': 1,
                    'legend-borderaxespad': 0,
                    'legend-bbox_to_anchor': (1.01, 1),
                    'legend-loc': 'upper left',
                }
                # plot before/after glitchgram
                self.plots.append(get_plot('triggers')(
                    [after, vetoed], self.start, self.end, state=state,
                    title='Impact of %s (%s)' % (
                        label_to_latex(self.name), etgstr),
                    outdir=plotdir, labels=['_', 'Vetoed'],
                    colors=['lightblue', 'red'], **glitchgramargs))

                # plot histograms
                statistics = ['snr']
                if params['det'] != params['snr']:
                    statistics.append('det')
                self.layout.append(len(statistics) + 1)
                for column in statistics + ['frequency']:
                    self.plots.append(get_plot('trigger-histogram')(
                        [before, after], self.start, self.end, state=state,
                        column=params[column], etg=self.etg, outdir=plotdir,
                        title='Impact of %s (%s)' % (
                            label_to_latex(self.name), etgstr),
                        labels=['Before', 'After'],
                        xlabel=params.get('%s-label' % column,
                                          get_column_label(params[column])),
                        color=['red', (0.2, 0.8, 0.2)],
                        logx=params.get('%s-log' % column, True),
                        logy=True,
                        histtype='stepfilled', alpha=0.6,
                        weights=1/float(abs(self.span)), bins=100,
                        ybound=1/float(abs(self.span)) * 0.5, **{
                            'legend-borderaxespad': 0,
                            'legend-bbox_to_anchor': (1.01, 1),
                            'legend-loc': 'upper left'}
                    ))

                # plot triggers before and after
                for stat in statistics:
                    column = params[stat]
                    glitchgramargs.update({
                        'color': column,
                        'clim': params.get('%s-limits' % stat, [3, 100]),
                        'logcolor': params.get('%s-log' % stat, True),
                        'colorlabel': params.get('%s-label' % stat,
                                                 get_column_label(column)),
                    })
                    self.plots.append(get_plot('triggers')(
                        [before], self.start, self.end, state=state,
                        outdir=plotdir, **glitchgramargs))
                    self.plots.append(get_plot('triggers')(
                        [after], self.start, self.end, state=state,
                        title='After %s (%s)' % (
                            label_to_latex(self.name), self.etg),
                        outdir=plotdir, **glitchgramargs))
                    self.layout.append(2)

            # -- configure segment plot
            segargs = {
                'state': state,
                'known': {'alpha': 0.1, 'facecolor': 'lightgray'},
                'color': 'red',
            }
            if len(self.flags) == 1:
                sp = get_plot('segments')(self.flags, self.start, self.end,
                                          outdir=plotdir, labels=self.labels,
                                          **segargs)
            else:
                sp = get_plot('segments')(
                    [self.metaflag] + self.flags, self.start, self.end,
                    labels=([self.intersection and 'Intersection' or 'Union'] +
                            self.labels), outdir=plotdir, **segargs)
            self.plots.append(sp)
            self.layout.append(1)
Esempio n. 9
0
File: tabs.py Progetto: tjma12/vet
    def init_plots(self, plotdir=os.curdir):
        """Configure the default list of plots for this tab

        This method configures a veto-trigger glitchgram, histograms of
        before/after SNR and frequency/template duration,
        before and after glitchgrams, and a segment plot.

        This method is a mess, and should be re-written in a better way.
        """
        namestr = self.title.split('/')[0]
        before = get_channel(str(self.channel))
        for state in self.states:
            # -- configure segment plot
            segargs = {
                'state': state,
                'known': {
                    'alpha': 0.1,
                    'facecolor': 'lightgray'
                },
                'color': 'red',
            }
            if len(self.flags) == 1:
                sp = get_plot('segments')(self.flags,
                                          self.start,
                                          self.end,
                                          outdir=plotdir,
                                          labels=self.labels,
                                          title='Veto segments: %s' %
                                          (texify(namestr)),
                                          **segargs)
            else:
                sp = get_plot('segments')(
                    [self.metaflag] + self.flags,
                    self.start,
                    self.end,
                    labels=([self.intersection and 'Intersection' or 'Union'] +
                            self.labels),
                    outdir=plotdir,
                    title='Veto segments: %s' % texify(namestr),
                    **segargs)
            self.plots.append(sp)

            if self.channel:
                self.set_layout([
                    2,
                ])
                after = get_channel(
                    veto_tag(before, self.metaflag, mode='after'))
                vetoed = get_channel(
                    veto_tag(before, self.metaflag, mode='vetoed'))
                # -- configure trigger plots
                params = etg.get_etg_parameters(self.etg, IFO=before.ifo)
                glitchgramargs = {
                    'etg':
                    self.etg,
                    'x':
                    params['time'],
                    'y':
                    params['frequency'],
                    'yscale':
                    params.get('frequency-scale', 'log'),
                    'ylabel':
                    params.get('frequency-label',
                               get_column_label(params['frequency'])),
                    'ylim':
                    params.get('ylim', [10, 5000]),
                    'edgecolor':
                    'none',
                    'legend-scatterpoints':
                    1,
                    'legend-borderaxespad':
                    0,
                    'legend-bbox_to_anchor': (1, 1),
                    'legend-loc':
                    'upper left',
                    'legend-frameon':
                    False,
                }
                glitchgramargs.update(self.glitchgramargs)
                # plot before/after glitchgram
                self.plots.append(
                    get_plot('triggers')([after, vetoed],
                                         self.start,
                                         self.end,
                                         state=state,
                                         title='Impact of %s (%s)' %
                                         (texify(namestr), self.etg),
                                         outdir=plotdir,
                                         labels=['After', 'Vetoed'],
                                         **glitchgramargs))

                # plot histograms
                if params['det'] != params['snr']:
                    statistics = ['snr', 'det']
                    xlims = [(5, 16384), (6, 15), (8, 8192)]
                else:
                    statistics = ['snr']
                    xlims = [(5, 16384), (8, 8192)]
                self.layout.append(len(statistics) + 1)
                for column, xlim in zip(statistics + ['frequency'], xlims):
                    self.plots.append(
                        get_plot('trigger-histogram')(
                            [before, after],
                            self.start,
                            self.end,
                            state=state,
                            column=params[column],
                            etg=self.etg,
                            outdir=plotdir,
                            filterstr=self.filterstr,
                            title='Impact of %s (%s)' %
                            (texify(namestr), self.etg),
                            labels=['Before', 'After'],
                            xlim=xlim,
                            xlabel=params.get('%s-label' % column,
                                              get_column_label(
                                                  params[column])),
                            color=['#ffa07a', '#1f77b4'],
                            alpha=1,
                            xscale=params.get('%s-scale' % column, 'log'),
                            yscale='log',
                            histtype='stepfilled',
                            weights=1 / float(abs(self.span)),
                            bins=100,
                            ylim=(1 / float(abs(self.span)) * 0.5, 1),
                            **{
                                'legend-borderaxespad': 0,
                                'legend-bbox_to_anchor': (1., 1.),
                                'legend-loc': 'upper left',
                                'legend-frameon': False,
                            }))

                # plot triggers before and after
                for stat in statistics:
                    column = params[stat]
                    glitchgramargs.update({
                        'color':
                        column,
                        'clim':
                        params.get('%s-limits' % stat, [3, 100]),
                        'logcolor':
                        params.get('%s-log' % stat, True),
                        'colorlabel':
                        params.get('%s-label' % stat,
                                   get_column_label(column)),
                    })
                    self.plots.append(
                        get_plot('triggers')([before],
                                             self.start,
                                             self.end,
                                             state=state,
                                             outdir=plotdir,
                                             filterstr=self.filterstr,
                                             **glitchgramargs))
                    self.plots.append(
                        get_plot('triggers')(
                            [after],
                            self.start,
                            self.end,
                            state=state,
                            title='%s after %s (%s)' % (texify(
                                str(self.channel)), texify(namestr), self.etg),
                            outdir=plotdir,
                            filterstr=self.filterstr,
                            **glitchgramargs))
                    self.layout.append(2)

            else:
                self.set_layout([
                    1,
                ])
Esempio n. 10
0
 def setup_class(cls):
     cls.PLOT = gwsumm_plot.get_plot(cls.TYPE)
Esempio n. 11
0
def test_get_plot(name, plot):
    assert gwsumm_plot.get_plot(name) is plot
    with pytest.raises(ValueError):
        gwsumm_plot.get_plot('dfskaewf')