Example #1
0
 def test_unique_resource_ids(self, catalog, duplicated_catalog):
     """ensure all resource ids are unique in duplicated event"""
     ev1, ev2 = catalog, duplicated_catalog
     rids1 = {
         x
         for x in get_instances_from_tree(ev1, cls=ResourceIdentifier)
     }
     rids2 = {
         x
         for x in get_instances_from_tree(ev2, cls=ResourceIdentifier)
     }
     assert len(rids1) and len(rids2)  # ensure rids not empty
     commons = rids1 & rids2
     # all shared resource_ids should not refer to an object
     assert all(x.get_referred_object() is None for x in commons)
Example #2
0
def _get_update_time(eve):
    """return the most recent time anything was updated in event"""
    creations = get_instances_from_tree(eve, cls=ev.CreationInfo)
    timestamps = [
        getattr(x.creation_time, "timestamp", None) or 0 for x in creations
    ]
    return {"updated": max(timestamps) if timestamps else np.NaN}
Example #3
0
def _event_to_inv_df(event):
    """
    Pull WaveformStreamIDs out of an event and put it in a dataframe.
    """
    wids = get_instances_from_tree(event, WaveformStreamID)
    wid_str = {x.get_seed_string() for x in wids}
    df = pd.DataFrame(sorted(wid_str), columns=["seed_id"])
    seed = df["seed_id"].str.split(".", expand=True)
    df["network"], df["station"] = seed[0], seed[1]
    df["location"], df["channel"] = seed[2], seed[3]
    df["start_date"] = np.nan
    df["end_date"] = np.nan
    df["latitude"] = np.nan
    df["longitude"] = np.nan
    df["elevation"] = np.nan
    return stations_to_df(df)
Example #4
0
def _filter(obj, cls, **kwargs):
    out = (x for x in get_instances_from_tree(obj, cls=cls)
           if _keep_obj(x, **kwargs))
    return out