def pass_origin_quality(origin, magnitude): """Check if at least 2 stations have P and S phases picked, if not check if magnitude is greater than 2.5 and if has at least 12 P phases picked Parameters ---------- origin : obspy.core.event.origin Origin to be checked magnitude : float Magnitude of the event Returns ------- bool True if origin is good, False if not """ # get arrivals in dataframe format arrivals = obsplus.arrivals_to_df(origin) try: # check if at least 2 stations have P and S phases picked (two phases picked) ps_count = arrivals.groupby( 'station')['phase'].count().value_counts()[2] except KeyError: return False if ps_count < 2: # count P phases p_count = arrivals['phase'].value_counts()['P'] if p_count > 12 and magnitude > 2.5: return True else: return False else: return True
def _get_picks_df(restrict_to_arrivals): """Get the picks dataframe, remove picks flagged as rejected.""" pdf = obsplus.picks_to_df(event) pdf["seed_id_less"] = pdf["seed_id"].str[:-1] if restrict_to_arrivals: adf = obsplus.arrivals_to_df(event) pdf = pdf.loc[pdf["resource_id"].isin(adf["pick_id"])] # remove rejected picks pdf = pdf[pdf.evaluation_status != "rejected"] # Toss any picks from stations that have S-picks that are earlier than P-picks if {"P", "S"}.issubset(pdf["phase_hint"]): phs = pdf.groupby("phase_hint") p_picks = phs.get_group("P") s_picks = phs.get_group("S") both = set(p_picks["seed_id_less"]).intersection( s_picks["seed_id_less"]) p_picks = (p_picks.loc[p_picks["seed_id_less"].isin( both)].set_index("seed_id_less").sort_index()) s_picks = (s_picks.loc[s_picks["seed_id_less"].isin( both)].set_index("seed_id_less").sort_index()) mask = p_picks["time"] > s_picks["time"] bad_p = p_picks.loc[mask] bad_s = s_picks.loc[mask] if mask.any(): warnings.warn( "S-pick is earlier than P-pick for one or more picks." "Skipping phases.") pdf = pdf.loc[~pdf["resource_id"].isin(bad_s["resource_id"]) & ~pdf["resource_id"].isin(bad_p["resource_id"])] if not len(pdf): raise NoPhaseInformationError( f"No valid phases for event:\n{event}") # # add seed_id column # pdf["seed_id"] = obsplus.utils.get_nslc_series(pdf) # add the seed id column that drops the component from the channel # rename the resource_id column for later merging pdf.rename(columns={"resource_id": "pick_id"}, inplace=True) return pdf
def test_no_origin(self, no_origin): """ ensure returns empty df with required columns """ df = arrivals_to_df(no_origin) assert isinstance(df, pd.DataFrame) assert not len(df) assert set(df.columns).issubset(ARRIVAL_COLUMNS)
def read_arr_output(self, dummy_cat): return arrivals_to_df(dummy_cat)