obsplus.Fetcher

class obsplus.Fetcher(waveforms, stations=None, events=None, picks=None, stream_processor=None, time_before=None, time_after=None, event_query=None)[source]

A class for serving up data from various sources.

Integrates station, event, and waveform clients to enable dataset-aware querying.

Parameters:
  • waveforms (Union[WaveformClient, str, Path, Trace, Stream, WaveBank]) – Any argument from which a waveform client can be extracted. This includes an obspy waveforms, directory of waveform files, or an object with a get_waveforms method.

  • stations (Union[Path, str, Catalog, Event, EventClient, DataFrame, EventBank, None]) – Any argument from which an station client can be extracted. This includes an obspy Inventory, directory of station files, or an object with a get_stations method.

  • events (Union[Path, str, Catalog, Event, EventClient, DataFrame, EventBank, None]) – Any argument from which an event client can be extracted. This includes an obspy Catalog, directory of event files, or an object with a get_events method.

  • picks (Optional[DataFrame]) – Data from which picks can be extracted. A dataframe, events, or event_client are all acceptable.

  • stream_processor (Optional[Callable[[Stream], Stream]]) – A callable that takes an obspy waveforms as input and returns an obspy waveforms.

  • time_before (Optional[float]) – The default time before an given time to fetch.

  • time_after (Optional[float]) – The default time after a supplied time to fetch.

  • event_query (Optional[dict]) – A dict of arguments used to filter events.

Examples

>>> import obsplus
>>> import obspy
>>> #--- Init a Fetcher
>>> # from a dataset
>>> ds = obsplus.load_dataset('bingham_test')
>>> ds_fetcher = ds.get_fetcher()
>>> assert isinstance(ds_fetcher, obsplus.Fetcher)
>>> # from separate clients (includes Stream, Inventory, Catalog)
>>> waveforms = ds.waveform_client
>>> events = ds.event_client
>>> stations = ds.station_client
>>> kwargs = dict(events=events, waveforms=waveforms, stations=stations)
>>> fetcher = obsplus.Fetcher(**kwargs)
>>> assert isinstance(fetcher, obsplus.Fetcher)
>>> # --- get contiguous (not event) waveform data
>>> # simple get_waveform calls are passed to the waveforms client
>>> fetcher = obsplus.load_dataset('ta_test').get_fetcher()
>>> t1 = obspy.UTCDateTime('2007-02-15')
>>> t2 = t1 + 60
>>> station = 'M14A'
>>> st = fetcher.get_waveforms(starttime=t1, endtime=t2, station=station)
>>> print(st)
3 Trace(s) ...
>>> # iterate over a range of times
>>> t1 = obspy.UTCDateTime('2007-02-16')
>>> t2 = t1 + (3600 * 24)
>>> for st in fetcher.yield_waveforms(starttime=t1, endtime=t2):
...     assert len(st)
>>> # --- get event waveforms
>>> fetcher = obsplus.load_dataset('bingham_test').get_fetcher()
>>> # iterate each event yielding streams 30 seconds after origin
>>> kwargs = dict(time_before=0, time_after=30, reference='origin')
>>> for event_id, st in fetcher.yield_event_waveforms(**kwargs):
...     assert isinstance(event_id, str)
...     assert isinstance(st, obspy.Stream)
__init__(waveforms, stations=None, events=None, picks=None, stream_processor=None, time_before=None, time_after=None, event_query=None)[source]

Methods

__init__(waveforms[, stations, events, ...])

copy()

Return a deep copy of the fetcher.

get_event_waveforms([time_before, ...])

Return a dict of event_ids and waveforms for each event in events.

get_waveforms(*args, **kwargs)

Get waveforms for all channels in stations.

set_events(events)

Set event state in fetcher.

set_stations(stations)

Set the station state in fetcher.

set_waveforms(waveforms)

Set waveform state in Fetcher.

yield_event_waveforms([time_before, ...])

Yield event_id and streams for each event.

yield_waveforms([network, station, ...])

Yield time-series segments from the waveform client.

Attributes

picks_df

return a dataframe from the picks (if possible)

reference_funcs