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 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 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
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 make_amplitudes(scnls=None, picks=None): """Create amplitudes for testing.""" counter = 1 amps = [] scnls = scnls or [] params = { "type": "A", "unit": "dimensionless", "method_id": "mag_calculator", "filter_id": ev.ResourceIdentifier("Wood-Anderson"), "magnitude_hint": "M", "category": "point", "evaluation_mode": "manual", "evaluation_status": "confirmed", } for scnl in scnls: a = ev.Amplitude( generic_amplitude=counter, generic_amplitude_errors=ev.QuantityError( uncertainty=counter * 0.1, confidence_level=95 ), period=counter * 2, snr=counter * 5, time_window=ev.TimeWindow(0, 0.1, UTCDateTime()), waveform_id=ev.WaveformStreamID(seed_string=scnl), scaling_time=UTCDateTime(), scaling_time_errors=ev.QuantityError( uncertainty=counter * 0.001, confidence_level=95 ), creation_info=ev.CreationInfo( agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime() ), **params, ) amps.append(a) counter += 1 picks = picks or [] for pick in picks: a = ev.Amplitude( generic_amplitude=counter, generic_amplitude_errors=ev.QuantityError( uncertainty=counter * 0.1, confidence_level=95 ), period=counter * 2, snr=counter * 5, time_window=ev.TimeWindow(0, 0.1, UTCDateTime()), pick_id=pick.resource_id, scaling_time=UTCDateTime(), scaling_time_errors=ev.QuantityError( uncertainty=counter * 0.001, confidence_level=95 ), creation_info=ev.CreationInfo( agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime() ), **params, ) amps.append(a) counter += 1 return amps
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 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 cat_bad_first_picks(self, cat_only_picks): """Return a catalog with only picks, no origins or magnitudes""" # change the first picks to a station not in the inventory cat = cat_only_picks.copy() bad_wid = ev.WaveformStreamID(seed_string="SM.RDD..HHZ") for event in cat: first_pick = sorted(event.picks, key=lambda x: x.time)[0] first_pick.waveform_id = bad_wid event.origins.clear() return cat
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 _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 _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 sm_generator(scnls=None, amplitudes=None): """Function to create station magntiudes for testing.""" counter = 1 sms = [] scnls = scnls or [] params = { "origin_id": ev.ResourceIdentifier(), "station_magnitude_type": "M", "method_id": "mag_calculator", } for scnl in scnls: sm = ev.StationMagnitude( mag=counter, mag_errors=ev.QuantityError(uncertainty=counter * 0.1, confidence_level=95), waveform_id=ev.WaveformStreamID(seed_string=scnl), creation_info=ev.CreationInfo(agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime()), **params, ) sms.append(sm) counter += 1 amplitudes = amplitudes or [] for amp in amplitudes: sm = ev.StationMagnitude( mag=counter, mag_errors=ev.QuantityError(uncertainty=counter * 0.1, confidence_level=95), amplitude_id=amp.resource_id, creation_info=ev.CreationInfo(agency_id="dummy_agency", author="dummy", creation_time=UTCDateTime()), **params, ) sms.append(sm) counter += 1 return sms
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 wave_id(seed_str): return ev.WaveformStreamID(seed_string=seed_str)