Esempio n. 1
0
 def test_dataframe_input(self, cat):
     """
     Any dataframe should be valid input provided it has the required columns.
     """
     data = [[10.1, 10.1, 0, "some_id"]]
     cols = ["latitude", "longitude", "elevation", "id"]
     df = pd.DataFrame(data, columns=cols)
     dist_df = get_distance_df(df, cat)
     # make sure output has expected shape and ids
     assert len(dist_df) == len(cat) * len(df)
     id1 = dist_df.index.get_level_values("id1")
     assert "some_id" in set(id1)
Esempio n. 2
0
 def __init__(
         self,
         catalog: Catalog,
         inventory: Inventory,
         st_dict: Dict[str, Stream],
         motion_type: Union[str, Dict[str, str]] = 'velocity',
         phases: Optional[Collection[str]] = None,
 ):
     # check inputs
     st_dict, catalog = self._validate_inputs(catalog, inventory, st_dict)
     # get a df of all input data, perform sanity checks
     self.distance = get_distance_df(catalog, inventory)
     df = self._get_meta_df(catalog, inventory, st_dict, phases=phases)
     self.data = df
     # add sampling rate to stats
     sampling_rate = self.data['sampling_rate'].unique()[0]
     self._stats = AttribDict(motion_type=motion_type,
                              sampling_rate=sampling_rate)
Esempio n. 3
0
 def test_cat_cat(self, cat):
     """ ensure it works with two catalogs """
     df = get_distance_df(cat, cat)
     event_ids = {str(x.resource_id) for x in cat}
     combinations = set(itertools.permutations(event_ids, 2))
     assert combinations == set(df.index)
Esempio n. 4
0
 def distance_df(self, cat, inv):
     """ Return a dataframe from all the crandall events and stations. """
     return get_distance_df(entity_1=cat, entity_2=inv)