Ejemplo n.º 1
0
    def test_writeread(self):
        nslc_ids = [('', 'STA', '', '*')]

        event = model.Event(lat=111., lon=111., depth=111., time=111.)

        _marker = marker.Marker(nslc_ids=nslc_ids, tmin=1., tmax=10.)
        emarker = marker.EventMarker(event=event)
        pmarker = marker.PhaseMarker(nslc_ids=nslc_ids,  tmin=1., tmax=10.)
        pmarker.set_event(event)

        emarker.set_alerted(True)

        markers = [_marker, emarker, pmarker]
        fn = tempfile.mkstemp()[1]

        marker.save_markers(markers, fn)

        in_markers = marker.load_markers(fn)
        in__marker, in_emarker, in_pmarker = in_markers
        for i, m in enumerate(in_markers):
            if not isinstance(m, marker.EventMarker):
                assert (m.tmax - m.tmin) == 9.
            else:
                assert not m.is_alerted()

        marker.associate_phases_to_events([in_pmarker, in_emarker])

        in_event = in_pmarker.get_event()

        assert all((in_event.lat == 111., in_event.lon == 111.,
                    in_event.depth == 111., in_event.time == 111.))

        assert in_pmarker.get_event_hash() == in_event.get_hash()
        assert in_pmarker.get_event_time() == 111.
Ejemplo n.º 2
0
 def pyrocko_phase_marker(self, event=None):
     return marker.PhaseMarker(event=event,
                               nslc_ids=[self.waveform_id.nslc_id],
                               tmin=self.time.value,
                               tmax=self.time.value,
                               phasename=self.phase_hint.value,
                               polarity=self.pyrocko_polarity,
                               automatic=self.evaluation_mode)
Ejemplo n.º 3
0
    def get_pyrocko_phase_marker(self, event=None):
        if not self.phase_hint:
            logger.warn('Pick %s: phase_hint undefined' % self.public_id)
            phasename = 'undefined'
        else:
            phasename = self.phase_hint.value

        return marker.PhaseMarker(event=event,
                                  nslc_ids=[self.waveform_id.nslc_id],
                                  tmin=self.time.value,
                                  tmax=self.time.value,
                                  phasename=phasename,
                                  polarity=self.pyrocko_polarity,
                                  automatic=self.evaluation_mode)
Ejemplo n.º 4
0
def command_view(args):
    def setup(parser):
        parser.add_option('--extract',
                          dest='extract',
                          metavar='start:stop[:step|@num],...',
                          help='specify which traces to show')

        parser.add_option('--show-phases',
                          dest='showphases',
                          default=None,
                          metavar='[phase_id1,phase_id2,...|all]',
                          help='add phase markers from ttt')

        parser.add_option('--qt5',
                          dest='gui_toolkit_qt5',
                          action='store_true',
                          default=False,
                          help='use Qt5 for the GUI')

        parser.add_option('--qt4',
                          dest='gui_toolkit_qt4',
                          action='store_true',
                          default=False,
                          help='use Qt4 for the GUI')

        parser.add_option('--opengl',
                          dest='opengl',
                          action='store_true',
                          default=False,
                          help='use OpenGL for drawing')

    parser, options, args = cl_parse('view', args, setup=setup)

    if options.gui_toolkit_qt4:
        config.override_gui_toolkit = 'qt4'

    if options.gui_toolkit_qt5:
        config.override_gui_toolkit = 'qt5'

    gdef = None
    if options.extract:
        try:
            gdef = gf.meta.parse_grid_spec(options.extract)
        except gf.meta.GridSpecError as e:
            die(e)

    store_dirs = get_store_dirs(args)

    alpha = 'abcdefghijklmnopqrstxyz'.upper()

    markers = []
    traces = []

    try:
        for istore, store_dir in enumerate(store_dirs):
            store = gf.Store(store_dir)
            if options.showphases == 'all':
                phasenames = [pn.id for pn in store.config.tabulated_phases]
            elif options.showphases is not None:
                phasenames = options.showphases.split(',')

            ii = 0
            for args in store.config.iter_extraction(gdef):
                gtr = store.get(args)

                loc_code = ''
                if len(store_dirs) > 1:
                    loc_code = alpha[istore % len(alpha)]

                if gtr:

                    sta_code = '%04i (%s)' % (ii, ','.join('%gk' % (x / 1000.)
                                                           for x in args[:-1]))
                    tmin = gtr.deltat * gtr.itmin

                    tr = trace.Trace('',
                                     sta_code,
                                     loc_code,
                                     '%02i' % args[-1],
                                     ydata=gtr.data,
                                     deltat=gtr.deltat,
                                     tmin=tmin)

                    if options.showphases:
                        for phasename in phasenames:
                            phase_tmin = store.t(phasename, args[:-1])
                            if phase_tmin:
                                m = marker.PhaseMarker([
                                    ('', sta_code, loc_code, '%02i' % args[-1])
                                ],
                                                       phase_tmin,
                                                       phase_tmin,
                                                       0,
                                                       phasename=phasename)
                                markers.append(m)

                    traces.append(tr)

                ii += 1

    except (gf.meta.GridSpecError, gf.StoreError, gf.meta.OutOfBounds) as e:
        die(e)

    trace.snuffle(traces, markers=markers, opengl=options.opengl)