コード例 #1
0
ファイル: test_marker.py プロジェクト: wsja/pyrocko
    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.
コード例 #2
0
ファイル: data.py プロジェクト: chaoshunh/pinky
    def setup(self):
        self.data_pile = pile.make_pile(
            self.data_paths, fileformat=self.data_format)

        if self.data_pile.is_empty():
            sys.exit('Data pile is empty!')

        self.deltat_want = self.config.deltat_want or \
                min(self.data_pile.deltats.keys())

        self.n_samples = int(
                (self.config.sample_length + self.config.tpad) / self.deltat_want)

        logger.debug('loading marker file %s' % self.fn_markers)

        # loads just plain markers:
        markers = marker.load_markers(self.fn_markers)

        if self.fn_events:
            markers.extend(
                    [marker.EventMarker(e) for e in
                load_events(self.fn_events)])

        if self.sort_markers:
            logger.info('sorting markers!')
            markers.sort(key=lambda x: x.tmin)
        marker.associate_phases_to_events(markers)

        markers_by_nsl = {}
        for m in markers:
            if not m.match_nsl(self.config.reference_target.codes[:3]):
                continue

            if m.get_phasename().upper() != self.align_phase:
                continue

            markers_by_nsl.setdefault(m.one_nslc()[:3], []).append(m)

        assert(len(markers_by_nsl) == 1)

        # filter markers that do not have an event assigned:
        self.markers = list(markers_by_nsl.values())[0]

        if not self.labeled:
            dummy_event = Event(lat=0., lon=0., depth=0.)
            for m in self.markers:
                if not m.get_event():
                    m.set_event(dummy_event)

        self.markers = [m for m in self.markers if m.get_event() is not None]

        if not len(self.markers):
            raise Exception('No markers left in dataset')

        self.config.channels = list(self.data_pile.nslc_ids.keys())
        self.config.channels.sort()
コード例 #3
0
ファイル: data.py プロジェクト: zhengjing8628/pinky
    def setup(self):
        self.data_pile = pile.make_pile(
            self.data_paths, fileformat=self.data_format)

        if self.data_pile.is_empty():
            sys.exit('Data pile is empty!')

        self.deltat_want = self.config.deltat_want or \
                min(self.data_pile.deltats.keys())

        self.n_samples = int(
                (self.config.sample_length + self.config.tpad) / self.deltat_want)

        logger.debug('loading marker file %s' % self.fn_markers)

        # loads just plain markers:
        markers = marker.load_markers(self.fn_markers)

        if self.fn_events:
            markers.extend(
                    [marker.EventMarker(e) for e in
                load_events(self.fn_events)])

        marker.associate_phases_to_events(markers)
        markers = [m for m in markers if isinstance(m, marker.PhaseMarker)]

        markers_dict = defaultdict(list)
        for m in markers:
            if m.get_phasename().upper() != self.align_phase:
                continue

            markers_dict[m.get_event()].append(m)

        self.markers = []
        for e, _markers in markers_dict.items():
            first = min(_markers, key=lambda x: x.tmin)
            self.markers.append(first)

        if not self.labeled:
            dummy_event = Event(lat=0., lon=0., depth=0.)
            for m in self.markers:
                if not m.get_event():
                    m.set_event(dummy_event)

        self.markers = [m for m in self.markers if m.get_event() is not None]

        if not len(self.markers):
            raise Exception('No markers left in dataset')

        self.config.channels = list(self.data_pile.nslc_ids.keys())
        self.config.channels.sort()