def strange_picks_added_origins(self, inv): """ make sure "rejected" picks and oddball phase hints get skipped """ # Pick w/ good phase hint but bad evaluation status pick1 = ev.Pick( time=obspy.UTCDateTime(), phase_hint="P", evaluation_status="rejected", waveform_id=ev.WaveformStreamID(seed_string="UU.TMU..HHZ"), ) # Pick w/ bad phase hint but good evaluation status pick2 = ev.Pick( time=obspy.UTCDateTime(), phase_hint="junk", evaluation_status="reviewed", waveform_id=ev.WaveformStreamID(seed_string="UU.CTU..HHZ"), ) # Pick w/ good phase hint and evaluation status pick3 = ev.Pick( time=obspy.UTCDateTime(), phase_hint="S", waveform_id=ev.WaveformStreamID(seed_string="UU.SRU..HHN"), ) eve = ev.Event() eve.picks = [pick1, pick2, pick3] return make_origins(events=eve, inventory=inv, phase_hints=["P", "S"]), pick3
def event_rejected_pick(self): """ Create an event with a rejected pick. """ wid = ev.WaveformStreamID(seed_string="UU.TMU.01.ENZ") time = obspy.UTCDateTime("2019-01-01") pick1 = ev.Pick( time=time, waveform_id=wid, phase_hint="P", evaluation_status="rejected" ) pick2 = ev.Pick(time=time, waveform_id=wid, phase_hint="P") return ev.Event(picks=[pick1, pick2])
def picks_no_origin(self): """ create a events that has picks but no origin """ t0 = UTCDateTime("2016-01-01T10:12:15.222") def wave_id(seed_str): return ev.WaveformStreamID(seed_string=seed_str) picks = [ ev.Pick(time=t0 + 2, waveform_id=wave_id("UU.TMU..HHZ")), ev.Pick(time=t0 + 1.2, waveform_id=wave_id("UU.BOB.01.ELZ")), ev.Pick(time=t0 + 3.2, waveform_id=wave_id("UU.TEX..EHZ")), ] return picks_to_dataframe(ev.Event(picks=picks))
def pick_generator(scnls): picks = [] for scnl in scnls: p = ev.Pick(time=UTCDateTime(), waveform_id=ev.WaveformStreamID(seed_string=scnl)) picks.append(p) return picks
def _create_pick(): # setup some of the classes creation = ev.CreationInfo( agency='SwanCo', author='Indago', creation_time=UTCDateTime(), version='10.10', author_url=ev.ResourceIdentifier('smi:local/me.com'), ) pick = ev.Pick( time=state['time'], comments=[ev.Comment(x) for x in 'BOB'], evaluation_mode='manual', evaluation_status='final', creation_info=creation, phase_hint='P', polarity='positive', onset='emergent', back_azimith_errors={"uncertainty": 10}, slowness_method_id=ev.ResourceIdentifier('smi:local/slow'), backazimuth=122.1, horizontal_slowness=12, method_id=ev.ResourceIdentifier(), horizontal_slowness_errors={'uncertainty': 12}, filter_id=ev.ResourceIdentifier(), waveform_id=ev.WaveformStreamID('UU', 'FOO', '--', 'HHZ'), ) state['pick_id'] = pick.resource_id return pick
def test_none_onset(self): """ Make sure Nones in the data get handled properly """ waveform_id = ev.WaveformStreamID(station_code="A") pick = ev.Pick(time=UTCDateTime(), waveform_id=waveform_id) df = picks_to_dataframe(pick) assert df.onset.iloc[0] == "" assert df.polarity.iloc[0] == ""
def test_dot_in_location_code(self): """Ensure a dot in the location code causes a ValueError. """ waveform_id = ev.WaveformStreamID( network_code="UU", station_code="TMU", location_code="1.0", channel_code="HHZ", ) pick = ev.Pick(time=obspy.UTCDateTime("2020-01-01"), waveform_id=waveform_id) with pytest.raises(ValueError): _ = obsplus.picks_to_df([pick])
def cat_duplicate_unknown_phase_hints(self, cat1): """Create duplicate picks with unknown phase hints""" cat = cat1.copy() eve = cat[0] eve.picks.append( ev.Pick( time=obspy.UTCDateTime(), waveform_id=ev.WaveformStreamID(network_code="UK", station_code="STA", channel_code="HHZ"), phase_hint="?", )) eve.picks.append( ev.Pick( time=obspy.UTCDateTime(), waveform_id=ev.WaveformStreamID(network_code="UK", station_code="STA", channel_code="HHN"), phase_hint="?", )) return cat
def picks_from_picksdict(picks, creation_info=None): picks_list = list() for station, onsets in picks.items(): for label, phase in onsets.items(): if not isinstance(phase, dict) and not isinstance( phase, AttribDict): continue onset = phase['mpp'] try: ccode = phase['channel'] ncode = phase['network'] except: continue pick = ope.Pick() if creation_info: pick.creation_info = creation_info pick.time = onset error = phase['spe'] pick.time_errors.uncertainty = error try: epp = phase['epp'] lpp = phase['lpp'] pick.time_errors.lower_uncertainty = onset - epp pick.time_errors.upper_uncertainty = lpp - onset except (KeyError, TypeError) as e: warnings.warn(str(e), RuntimeWarning) try: picker = phase['picker'] except KeyError as e: warnings.warn(e.message, RuntimeWarning) picker = 'Unknown' pick.phase_hint = label pick.method_id = ope.ResourceIdentifier(id=picker) pick.waveform_id = ope.WaveformStreamID(station_code=station, channel_code=ccode, network_code=ncode) try: polarity = phase['fm'] if polarity == 'U' or '+': pick.polarity = 'positive' elif polarity == 'D' or '-': pick.polarity = 'negative' else: pick.polarity = 'undecidable' except KeyError as e: if 'fm' in str( e): # no polarity information found for this phase pass else: raise e picks_list.append(pick) return picks_list
def test_read_uncertainty(self): """ tests that uncertainties in time_errors attribute are read. See #55. """ kwargs = dict(lower_uncertainty=1, upper_uncertainty=2, uncertainty=12) time_error = ev.QuantityError(**kwargs) waveform_id = ev.WaveformStreamID(station_code="A") pick = ev.Pick( time=UTCDateTime(), time_errors=time_error, waveform_id=waveform_id ) df = picks_to_dataframe(pick) assert set(kwargs).issubset(df.columns) assert len(df) == 1 ser = df.iloc[0] assert all([ser[i] == kwargs[i] for i in kwargs])
def cat_picks(self, cat_w_two_events): """Add some picks to the events, including rejected picks""" eve = cat_w_two_events[0] wid = ev.WaveformStreamID(seed_string="UU.TMU.01.ENZ") time = obspy.UTCDateTime() eve.picks.append( ev.Pick(time=time, waveform_id=wid, phase_hint="P", evaluation_status="reviewed")) eve.picks.append( ev.Pick(time=time, waveform_id=wid, phase_hint="P", evaluation_status="rejected")) eve = cat_w_two_events[1] eve.picks.append( ev.Pick( time=time, waveform_id=wid, phase_hint="P", evaluation_status="preliminary", )) eve.picks.append( ev.Pick( time=time, waveform_id=wid, phase_hint="P", evaluation_status="confirmed", )) eve.picks.append( ev.Pick(time=time, waveform_id=wid, phase_hint="P", evaluation_status="final")) return cat_w_two_events
def _setPick(self, xdata, phase, channel, polarity='undecideable', overwrite_existing=False): ''' Write obspy.core.event.Pick into self._picks list ''' picktime = self._current_st[0].stats.starttime +\ (xdata * self._current_st[0].stats.delta) this_pick = event.Pick() overwrite = True # Overwrite existing phase's picktime if overwrite_existing: for _pick in self._getPicks(): if _pick.phase_hint == phase and\ _pick.waveform_id.channel_code == channel: this_pick = _pick overwrite = False break creation_info = event.CreationInfo(author='ObsPy.StreamPick', creation_time=UTCDateTime()) # Create new event.Pick() this_pick.time = picktime this_pick.phase_hint = phase this_pick.waveform_id = event.WaveformStreamID( network_code=self._current_st[0].stats.network, station_code=self._current_st[0].stats.station, location_code=self._current_st[0].stats.location, channel_code=channel) this_pick.evaluation_mode = 'manual' this_pick.creation_info = creation_info this_pick.onset = self.onset_types[self.onsetGrp.checkedId()] this_pick.evaluation_status = 'preliminary' this_pick.polarity = polarity #if self._current_filter is not None: # this_pick.comments.append(event.Comment( # text=str(self.bpfilter[self.fltrcb.currentIndex()]))) if overwrite: self._picks.append(this_pick)
def null_catalog(self): """ create a catalog object, hide some nullish station codes in picks and such """ def make_wid(net="UU", sta="TMU", loc="01", chan="HHZ"): kwargs = dict(network_code=net, station_code=sta, location_code=loc, channel_code=chan) wid = ev.WaveformStreamID(**kwargs) return wid cat = obspy.read_events() ev1 = cat[0] # make a pick picks = [] for val in NULL_SEED_CODES: wid = make_wid(loc=val) picks.append(ev.Pick(waveform_id=wid, time=obspy.UTCDateTime())) ev1.picks.extend(picks) return cat
def _create_pick(ser): """ create picks """ ser = ser[(ser != -1) & ~(ser.isnull())] co = oe.CreationInfo( agencey_idr=ser.get('auth'), creation_time=UTC(ser.get('lddate')), ) seed_str = _get_seed_str(ser) wid = oe.WaveformStreamID(seed_string=seed_str) pick = oe.Pick( time=UTC(ser.time), resource_id=rid(ser.arid), creation_info=co, waveform_id=wid, ) return pick
def create_pick(origintime, picknum, picktime, eventnum, cinfo, phase, station, wfseedstr, authority_id): ''' create_pick - function to create an ObsPy Pick :param origintime: :type origintime: :param picknum: number of the created pick :type picknum: int :param picktime: :type picktime: :param eventnum: human-readable event identifier :type eventnum: str :param cinfo: An ObsPy :class: `~obspy.core.event.CreationInfo` object holding information on the creation of the returned object :type cinfo: :class: `~obspy.core.event.CreationInfo` object :param phase: name of the arrivals seismic phase :type phase: str :param station: name of the station at which the seismic phase has been picked :type station: str :param wfseedstr: A SEED formatted string of the form network.station.location.channel in order to set a referenced waveform :type wfseedstr: str, SEED formatted :param authority_id: name of the institution carrying out the processing :type authority_id: str :return: An ObsPy :class: `~obspy.core.event.Pick` object ''' pickID = eventnum + '_' + station.strip() + '/{0:03d}'.format(picknum) pickresID = create_resourceID(origintime, 'pick', authority_id, pickID) pick = ope.Pick() pick.resource_id = pickresID pick.time = picktime pick.creation_info = cinfo pick.phase_hint = phase pick.waveform_id = ope.ResourceIdentifier(id=wfseedstr, prefix='file:/') return pick
def picks(self): """Create picks for testing.""" t1, t2 = UTCDateTime("2016-01-01"), UTCDateTime("2015-01-01") picks = [ev.Pick(time=t1), ev.Pick(time=t2), ev.Pick()] return picks
def picks(self): t1, t2 = UTCDateTime("2016-01-01"), UTCDateTime("2015-01-01") picks = [ev.Pick(time=t1), ev.Pick(time=t2), ev.Pick()] return picks