obsplus.utils.stations module¶
Utilities for working with inventories.
- obsplus.utils.stations.df_to_inventory(df, client=None)[source]¶
Create an inventory from a dataframe.
- Parameters:
df (
DataFrame
) –- A dataframe with the same columns and dtypes as the one returned by
obsplus.stations_to_df()
, which are:network: nslc_code station: nslc_code location: nslc_code channel: nslc_code seed_id: str latitude: float longitude: longitude elevation: float depth: float azimuth: float dip: float sample_rate: float start_date: datetime64[ns] end_date: datetime64[ns]
extra columns, except for those mentioned in the notes, are ignored.
client (
Optional
[StationClient
]) – Any client with a get_stations method. Only used if the dataframe contains special columns for retrieving channel responses.
- Return type:
Inventory
Notes
There are two ways to include response information:
1. Using the Nominal Response Library (NRL): (https://docs.obspy.org/master/packages/obspy.clients.nrl.html) If the dataframe has columns named “sensor_keys” and “datalogger_keys” these will indicate the response information should be fetched using ObsPy’s NRL client. Each of these columns should either contain lists or josn-loadable strings. For example, to specify sensor keys: [“Nanometrics”, “Trillium 120 Horizon”] or ‘[“Nanometrics”, “Trillium 120 Horizon”]’ are both valid.
2. Using a station client: If the dataframe contains a column get_stations_kwargs it indicates that either a client was passed as the client argument or the fdsn IRIS client should be used to download at least some channel response information. The contents of this column must be a dictionary or json string of acceptable keyword arguments for the client’s get_stations method. All time values must be provided as iso8601 strings. For example, {‘network’: ‘UU’, ‘station’: ‘TMU’, ‘location’: ‘01’, ‘channel’: ‘HHZ’,
‘starttime’: ‘2017-01-02’,}
would be passed to the provided client to download a response for the corresponding channel. - If more than one channel is returned from the get_stations call an
AmbiguousResponseError will be raised and a more specific query will be required.
If not all the required seed_id information is provided it will be ascertained from the appropriate column.
To simply fetch a response using only the info provided in other columns use an empty dict, or json string (eg ‘{}’).
No responses will be fetched for any rows with empty strings or null values in the get_stations_kwargs column.
If both NRL and client methods are indicated by column contents an AmbiguousResponseError will be raised.
- obsplus.utils.stations.get_station_client(stations)[source]¶
Extract a station client from various inputs.
- Parameters:
stations (
Union
[str
,Path
,Inventory
]) –- Any of the following:
A path to an obspy-readable station file
A path to a directory of obspy-readable station files
An obspy.Inventory instance
An instance of
EventBank
Any other object that has a get_stations method
- Raises:
TypeError – If a station client cannot be determined from the input.
- Return type: