def _get_origin_quality(eve: ev.Event): """ get information from origin quality """ # ensure resource_ids in arrivals don't point to picks that dont exist ori = get_preferred(eve, "origin", init_empty=True) for pick in eve.picks: pick.resource_id.set_referred_object(pick) pick_dict = {str(p.resource_id): p for p in eve.picks} apid = {str(ar.pick_id): ar for ar in ori.arrivals} assert set(apid).issubset( set(pick_dict)), "arrivals link to non-existent picks" # desired attrs qual_set = { "standard_error", "associated_phase_count", "azimuthal_gap", "used_phase_count", } uncert_set = {"horizontal_uncertainty"} # objects to pull from qual = ori.quality uncert = ori.origin_uncertainty duncert = ori.depth_errors # out dict to populate out = {} for obsject, attrs in ((qual, qual_set), (uncert, uncert_set)): obsject = obsject or {} out.update(getattrs(obsject, attrs)) if duncert is not None: out["vertical_uncertainty"] = duncert.get("uncertainty", np.nan) else: out["vertical_uncertainty"] = np.nan out["p_phase_count"] = _get_phase_count(ori, "P") out["s_phase_count"] = _get_phase_count(ori, "S") out["p_pick_count"] = _get_pick_count("P", pick_dict) out["s_pick_count"] = _get_pick_count("S", pick_dict) # get station count and concat'ed string of stations arrivals = ori.arrivals picks = [pick_dict.get(arr.pick_id.id) for arr in arrivals] assert all(picks) pset = {p.waveform_id.station_code for p in picks} sl = sorted(list(pset)) out.update({"stations": ", ".join(sl), "station_count": len(sl)}) return out
def _get_origin_basic(eve): """ extract basic info from origin. """ ori = get_preferred(eve, "origin", init_empty=True) return getattrs(ori, set(origin_dtypes))
def test_none_returns_empty(self): """ make sure None returns empty dict""" out = getattrs(None, ["bob"]) assert isinstance(out, dict) assert not out