def test_unsupported_column_warns(self, df_from_inv): """Ensure an unsupported column issues a warning.""" df_from_inv["bob"] = 1 with pytest.warns(UserWarning) as w: df_to_inventory(df_from_inv) assert len(w) == 1 assert "found unexpected columns" in w.list[0].message.args[0]
def test_mixing_nrl_with_station_client(self, df_with_both_response_cols): """ Ensure mixing the two types of responses raises an Error. """ df = df_with_both_response_cols with pytest.raises(AmbiguousResponseError): df_to_inventory(df)
def test_make_station_level_inventory(self, df_from_inv): """Ensure station level invs can be constructed.""" df = df_from_inv.drop(columns="channel") inv = df_to_inventory(df) for net in inv: for sta in net: assert not sta.channels, "there should be no channels"
def test_00_location_code(self, df_from_inv): """Ensure a 00 location code makes it into the inventory.""" df = df_from_inv.copy() df["location"] = "00" inv = df_to_inventory(df) for channel in inv.get_contents()["channels"]: assert channel.split(".")[2] == "00"
def inv_issue_115(self): """Get an inventory for testing issue 115.""" sta1 = dict( network="LF", location="", station="BOB", channel="HHZ", start_date="2019-01-01", end_date="2100-01-01", sample_rate=250, latitude=0, longitude=0, elevation=0, depth=0, ) sta2 = dict( network="01", location="", station="01", channel="BHZ", start_date="2019-01-01", end_date="2100-01-01", sample_rate=1000, latitude=0, longitude=0, elevation=0, depth=0, ) return df_to_inventory(pd.DataFrame([sta1, sta2]))
def test_response_one_missing(self, df_with_partial_responses): """Ensure responses which can be got are fetched.""" df = df_with_partial_responses with suppress_warnings(): inv = df_to_inventory(df) missing = df["sensor_keys"].isnull() | df["datalogger_keys"].isnull() missing_seed_ids = set(get_seed_id_series(df[missing])) assert self.has_valid_response(inv, missing_seed_ids)
def test_get_stations_client(self, df_with_get_stations_kwargs): """Ensure get_station_kwargs results responses.""" df = df_with_get_stations_kwargs col = "get_station_kwargs" missing = df[col].isnull() | (df[col] == "") missing_seed_ids = set(get_seed_id_series(df[missing])) with suppress_warnings(): inv = df_to_inventory(df) assert self.has_valid_response(inv, missing_seed_ids)
def test_nslc_variations_float(self, nslc_dtype_variation): """Make sure data types get set (particularly for NSLC columns)""" inp = nslc_dtype_variation[0] expect = nslc_dtype_variation[1] inv = df_to_inventory(inp) for network in inv.networks: assert network.code == expect for station in network: assert station.code == expect for channel in station: assert channel.code == expect assert channel.location_code == expect
def split_inventory(self, inv_df, cat): """ Split the inventory and duplicate so first have encompasses half of the events and second gets the second half. """ edf = obsplus.events_to_df(cat).sort_values("time") ser = edf.loc[len(edf) // 2] inv1, inv2 = inv_df.copy(), inv_df.copy() inv1["end_date"] = ser["time"] inv2["start_date"] = ser["time"] new = pd.concat([inv1, inv2], ignore_index=True, axis=0).reset_index() return df_to_inventory(new)
def test_duplicate_stations(self, inv_df_duplicate_channels): """ Ensure duplicate stations create Station objects with correct time range. """ df = inv_df_duplicate_channels fur_df = df[df["station"] == "FUR"] inv = df_to_inventory(fur_df).select(station="FUR") stations = inv.networks assert len(stations) == 1 fur = stations[0] assert fur.start_date == to_utc(fur_df["start_date"].min()) assert fur.end_date == to_utc(fur_df["end_date"].max())
def test_NaN_in_non_time_columns(self, df_from_inv): """ If there are NaN values in non-time these should just be interp. as None. """ df_from_inv.loc[2, "dip"] = np.NaN df_from_inv.loc[3, "azimuth"] = np.NaN # convert to inv inv = df_to_inventory(df_from_inv) # make sure dip is None dip_row = df_from_inv.loc[2] kwargs = {x: getattr(dip_row, x) for x in NSLC} inv_sub = inv.get_stations(**kwargs) assert inv_sub[0][0][0].dip is None # make sure azimuth is None dip_row = df_from_inv.loc[3] kwargs = {x: getattr(dip_row, x) for x in NSLC} inv_sub = inv.get_stations(**kwargs) assert inv_sub[0][0][0].azimuth is None
def test_ambiguous_query_raises(self, df_ambiguous_client_query): """Ensure a query that returns multiple channels will raise.""" df = df_ambiguous_client_query with pytest.raises(AmbiguousResponseError): df_to_inventory(df)
def inv_from_df(self, df_from_inv): """convert the station df back into an inventory.""" return df_to_inventory(df_from_inv)
def test_nrl_responses(self, df_with_nrl_response): """Ensure the NRL is used to pull responses.""" with suppress_warnings(): inv = df_to_inventory(df_with_nrl_response) assert self.has_valid_response(inv)
def test_make_network_level_inventory(self, df_from_inv): """Ensure station level invs can be constructed.""" df = df_from_inv.drop(columns=["channel", "station"]) inv = df_to_inventory(df) for net in inv: assert not net.stations
def test_invalid_nslc(self, invalid_nslc): """Make sure data types get set (particularly for NSLC columns)""" with pytest.raises(TypeError, match="cannot contain '.'"): df_to_inventory(invalid_nslc)