pisces.fdsn.client#

Pisces Client mirrors the ObsPy FDSN Client interface.

class pisces.fdsn.client.Client(dburl_or_session, **tables)[source]#

Bases: object

Basic database request client.

property contributors[source]#

Sorted list of distinct origin authors (Origin.auth)

get_availability(network=None, station=None, channel=None, starttime=None, endtime=None, mergegaps=0.0, mergesamplerate=None, show=None, includerestricted=True, restricted_substring=None)[source]#

Get waveform availability for a requested time window.

Parameters:
network, station, channelstr, optional

Network, station, and channel patterns. Comma-separated values and */? wildcards are supported.

starttime, endtimeobspy.UTCDateTime

Required request bounds.

mergegapsfloat, optional

Merge spans separated by no more than this many seconds.

mergesampleratefloat, optional

Merge spans whose sample rates differ by no more than this amount.

showstr or None, optional

"latestupdate" or None. Include the latest contributing update time.

includerestrictedbool, optional

Include restricted data by default.

restricted_substringstr, optional

Substring used to identify restricted Site or Network metadata when includerestricted=False.

get_events(starttime: UTCDateTime = None, endtime: UTCDateTime = None, minlatitude: float | None = None, maxlatitude: float | None = None, minlongitude: float | None = None, maxlongitude: float | None = None, latitude: float | None = None, longitude: float | None = None, minradius: float | None = None, maxradius: float | None = None, mindepth: float | None = None, maxdepth: float | None = None, minmagnitude: float | None = None, maxmagnitude: float | None = None, magnitudetype: str | None = None, eventtype: str | None = None, includeallorigins: bool = True, includeallmagnitudes: bool = False, includearrivals: bool = False, preferred_magnitude: tuple = ('mb', 'mw', 'ms'), eventid: str | None = None, limit: int | None = None, offset: int | None = None, orderby: bool | None = None, contributor: str | None = None, updatedafter: UTCDateTime = None, asquery: bool = False, **kwargs)[source]#

Query event data.

>>> cat = client.get_events(eventid=609301)

The return value is a Catalog object which can contain any number of events.

>>> t1 = UTCDateTime("2001-01-07T00:00:00")
>>> t2 = UTCDateTime("2001-01-07T03:00:00")
>>> cat = client.get_events(starttime=t1, endtime=t2, minmagnitude=4,
...                         contributor="ISC")
>>> print(cat)
3 Event(s) in Catalog:
2001-01-07T02:55:59.290000Z |  +9.801,  +76.548 | 4.9 mb
2001-01-07T02:35:35.170000Z | -21.291,  -68.308 | 4.4 mb
2001-01-07T00:09:25.630000Z | +22.946, -107.011 | 4.0 mb
starttimeobspy.UTCDateTime, optional [Origin]

Limit to events on or after the specified start time.

endtimeobspy.UTCDateTime optional [Origin]

Limit to events on or before the specified end time.

minlatitudefloat, optional [Origin]

Limit to events with a latitude larger than the specified minimum.

maxlatitudefloat, optional [Origin]

Limit to events with a latitude smaller than the specified maximum.

minlongitudefloat, optional [Origin]

Limit to events with a longitude larger than the specified minimum.

maxlongitudefloat, optional [Origin]

Limit to events with a longitude smaller than the specified maximum.

latitudefloat, optional [Origin]

Specify the latitude to be used for a radius search. Not currently implemented.

longitudefloat, optional [Origin]

Specify the longitude to the used for a radius search. Not currently implemented.

minradiusfloat, optional [Origin]

Limit to events within the specified minimum number of degrees from the geographic point defined by the latitude and longitude parameters. Not currently implemented.

maxradiusfloat, optional [Origin]

Limit to events within the specified maximum number of degrees from the geographic point defined by the latitude and longitude parameters. Not currently implemented.

mindepthfloat, optional [Origin]

Limit to events with depth, in kilometers, larger than the specified minimum.

maxdepthfloat, optional [Origin]

Limit to events with depth, in kilometers, smaller than the specified maximum.

minmagnitudefloat, optional [Origin, Netmag]

Limit to events with a magnitude larger than the specified minimum.

maxmagnitudefloat, optional [Origin, Netmag]

Limit to events with a magnitude smaller than the specified maximum.

magnitudetypestr, optional [Origin, Netmag]

Specify a magnitude type to use for testing the minimum and maximum limits. If not provided, any magnitude range constraints are applied to all magnitude types. Netmag table is required for magnitudes other than ‘ml’, ‘mb’, or ‘ms’. Wildcards are accepted.

eventtype: str, optional [Origin]

Limit to events with a specified event type. Multiple types are comma-separated e.g., “earthquake,quarry blast”. Allowed values are from QuakeML. See obspy.core.event.header.EventType for a list of allowed event types.

includealloriginsbool, optional (Origin [, Event])

Include all matching origins. Non-preferred origins are retained even without Netmag rows, but then have no QuakeML magnitudes. Default is True.

includeallmagnitudesbool, optional [Netmag]

Include all Netmag rows. When False (default), include only the preferred magnitude for the event’s preferred origin.

preferred_magnitudetuple of str, optional

Network magnitude types in preferred order, case-insensitive. Defaults to ("mb", "mw", "ms").

includearrivalsbool, optional [Assoc, Arrival]

Specify if phase arrivals should be included. Default is False.

eventidstr or int, optional [Event | Origin]

Select a specific event by ID (evid), or comma-separated list of IDs. e.g. 1234 or ‘1234,5678’. If provided, all other parameters are ignored.

limitint, optional [not yet implemented]k

Limit the results to the specified number of events.

offsetint, optional [not yet implemented]

Return results starting at the event count specified, starting at 1.

orderbystr, optional [Origin]

Order the result by time or magnitude with the following possibilities:

  • time: order by origin descending time [not yet implemented]

  • time-asc: order by origin ascending time [not yet implemented]

  • magnitude: order by descending magnitude [ignored]

    KB Core events doen’t have a preferred magnitude, so sorting is ignored.

  • magnitude-asc: order by ascending magnitude [ignored]

    See above.

catalogstr, optional [ignored]

KB Core tables have no concept of a catalog. This parameter is ignored. See ‘contributor’ below.

contributorstr, optional [Origin]

Limit to events contributed by a specified contributor. Matches strings inside the ‘auth’ field in the Origin table. Catalog sources are embedded within this field, so add them here with wildcards, like ‘ISC’.

updatedafterobspy.UTCDateTime, optional [Origin]

Limit to events updated after the specified time. KB Core doesn’t keep track of updates, so this parameter filters Origin.lddate, the date the origin was added to the database.

asquerybool

Return the raw SQLAlchemy query instead of direct results.

Returns:
resultobspy.Catalog or sqlalchemy.orm.Query instance
Raises:
ValueError

Missing or improper inputs.

get_extent(network=None, station=None, channel=None, starttime=None, endtime=None, includerestricted=True, restricted_substring=None)[source]#

Get waveform extents for a requested time window.

Parameters:
network, station, channelstr, optional

Network, station, and channel patterns. Comma-separated values and */? wildcards are supported.

starttime, endtimeobspy.UTCDateTime

Required request bounds.

includerestrictedbool, optional

Include restricted data by default.

restricted_substringstr, optional

Substring used to identify restricted Site or Network metadata when includerestricted=False.

get_stations(starttime: UTCDateTime = None, endtime: UTCDateTime = None, startbefore: UTCDateTime = None, startafter: UTCDateTime = None, endbefore: UTCDateTime = None, endafter: UTCDateTime = None, network: str | None = None, station: str | None = None, channel: str | None = None, minlatitude: float | None = None, maxlatitude: float | None = None, minlongitude: float | None = None, maxlongitude: float | None = None, latitude: float | None = None, longitude: float | None = None, minradius: float | None = None, maxradius: float | None = None, level: str = 'station', updatedafter: UTCDateTime = None, matchtimeseries: bool | None = None, filename: str | None = None, format: str = 'xml', asquery: bool = False, **kwargs)[source]#

Build a station metadata query or Inventory.

Parameters:
starttime, endtimeUTCDateTime, optional

Filter metadata epochs overlapping the requested interval. Network-level queries filter Affiliation epochs; station-level queries filter Site, Sitechan, and response epochs in their respective tables.

network, station, channelstr, optional

Comma-separated codes or */? wildcard patterns.

minlatitude, maxlatitude, minlongitude, maxlongitudefloat, optional

Rectangular geographic bounds applied to Site rows.

levelstr, optional

One of {"network", "station", "channel", "response"}. Metadata detail level. Defaults to "station".

asquerybool, optional

Return the SQLAlchemy query instead of building an ObsPy Inventory.

Returns
——-
sqlalchemy.orm.Query or obspy.core.inventory.Inventory

The SQLAlchemy query when asquery=True; otherwise the requested station metadata as an Inventory.

Raises:
ValueError

If level is invalid or the tables required for that level are absent.

get_waveforms(network, station, location, channel, starttime, endtime, quality=None, minimumlength=None, longestonly=None, attach_response=False, asquery=False, **kwargs)[source]#

Get waveforms from the database.

Requires the data and response directories in ‘dir’ and ‘dfile’ columns to be available/mounted on the client machine.

networkstr

Select one or more network codes. Can be SEED network codes or data center defined codes. Multiple codes are comma-separated (e.g. “IU,TA”). Wildcards are allowed.

stationstr

Select one or more SEED station codes. Multiple codes are comma-separated (e.g. “ANMO,PFO”). Wildcards are allowed.

locationstr

Select one or more SEED location identifiers. Multiple identifiers are comma-separated (e.g. “00,01”). Wildcards are allowed. Not implemented for CSS Wfdisc tables.

channelstr

Select one or more SEED channel codes. Multiple codes are comma-separated (e.g. “BHZ,HHZ”).

starttimeobspy.core.utcdatetime.UTCDateTime

Limit results to time series samples on or after the specified start time

endtimeobspy.core.utcdatetime.UTCDateTime

Limit results to time series samples on or before the specified end time

qualitystr, optional

Select a specific SEED quality indicator, handling is data center dependent. Not currently implemented.

minimumlengthfloat, optional

Limit results to continuous data segments of a minimum length specified in seconds.

longestonlybool, optional

Limit results to the longest continuous segment per channel. Not implemented.

attach_responsebool, optional

Attach instrument responses. Not implemented.

asquerybool, optional

If True, return the SQLAlchemy Query instance instead of a Stream. minimumlength is supported; quality, longestonly, attach_response, and additional keyword arguments are not implemented.

Any additional keyword arguments will be passed to the query engine as additional arguments. If you pass one of the default parameters and the query engine does not support it, a warning will be issued. Passing any non-default parameters that the query engine does not support will raise an error.

Examples

>>> t1 = UTCDateTime("2010-02-27T06:30:00.000")
>>> t2 = t1 + 5
>>> st = client.get_waveforms("IU", "A*", "1?", "LHZ", t1, t2)
>>> print(st)
3 Trace(s) in Stream:
IU.ADK.10.LHZ  | 2010-02-27T06:30:00.069538Z - ... | 1.0 Hz, 5 samples
IU.AFI.10.LHZ  | 2010-02-27T06:30:00.069538Z - ... | 1.0 Hz, 5 samples
IU.ANMO.10.LHZ | 2010-02-27T06:30:00.069538Z - ... | 1.0 Hz, 5 samples
get_waveforms_bulk(bulk, quality=None, minimumlength=None, longestonly=None, filename=None, **kwargs)[source]#

Query the dataselect service of the client. Bulk request.

Send a bulk request for waveforms to the server. bulk can either be specified as a filename, a file-like object or a string (with information formatted according to the FDSN standard) or a list of lists (each specifying network, station, location, channel, starttime and endtime). See examples and parameter description for more details.

bulk can be provided in the following forms:

  1. As a list of lists. Each list item has to be list of network, station, location, channel, starttime and endtime.

  2. As a valid request string/file as defined in the FDSNWS documentation.

    The request information can be provided as:

    • a string containing the request information

    • a string with the path to a local file with the request

    • an open file handle (or file-like object) with the request

>>> client = Client(session, origin=Origin, site=Site)
>>> t1 = UTCDateTime("2010-02-27T06:30:00.000")
>>> t2 = t1 + 1
>>> t3 = t1 + 3
>>> bulk = [("IU", "ANMO", "*", "BHZ", t1, t2),
...         ("IU", "AFI", "1?", "BHE", t1, t3),
...         ("GR", "GRA1", "*", "BH*", t2, t3)]
>>> st = client.get_waveforms_bulk(bulk)
>>> print(st)
5 Trace(s) in Stream:
GR.GRA1..BHE   | 2010-02-27T06:30:01... | 20.0 Hz, 40 samples
GR.GRA1..BHN   | 2010-02-27T06:30:01... | 20.0 Hz, 40 samples
GR.GRA1..BHZ   | 2010-02-27T06:30:01... | 20.0 Hz, 40 samples
IU.ANMO.00.BHZ | 2010-02-27T06:30:00... | 20.0 Hz, 20 samples
IU.ANMO.10.BHZ | 2010-02-27T06:30:00... | 40.0 Hz, 40 samples
>>> bulk = '''quality=B
... longestonly=false
... IU ANMO * BHZ 2010-02-27 2010-02-27T00:00:02
... IU AFI 1? BHE 2010-02-27 2010-02-27T00:00:04
... GR GRA1 * BH? 2010-02-27 2010-02-27T00:00:02
... '''
>>> st = client.get_waveforms_bulk(bulk)
>>> print(st)
5 Trace(s) in Stream:
GR.GRA1..BHE   | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
GR.GRA1..BHN   | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
GR.GRA1..BHZ   | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
IU.ANMO.00.BHZ | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
IU.ANMO.10.BHZ | 2010-02-27T00:00:00... | 40.0 Hz, 80 samples
>>> st = client.get_waveforms_bulk("/tmp/request.txt")         ...
>>> print(st)
5 Trace(s) in Stream:
GR.GRA1..BHE   | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
GR.GRA1..BHN   | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
GR.GRA1..BHZ   | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
IU.ANMO.00.BHZ | 2010-02-27T00:00:00... | 20.0 Hz, 40 samples
IU.ANMO.10.BHZ | 2010-02-27T00:00:00... | 40.0 Hz, 80 samples
>>> t = UTCDateTime("2012-12-14T10:36:01.6Z")
>>> t1 = t + 300
>>> t2 = t + 400
>>> bulk = [("TA", "S42A", "*", "BHZ", t1, t2),
...         ("TA", "W42A", "*", "BHZ", t1, t2),
...         ("TA", "Z42A", "*", "BHZ", t1, t2)]
Parameters:
bulkstr, file or list[list]

Information about the requested data. See above for details.

qualitystr, optional [not implemented]

Select a specific SEED quality indicator, handling is data center dependent. Ignored when bulk is provided as a request string/file.

minimumlengthfloat, optional [not implemented]

Limit results to continuous data segments of a minimum length specified in seconds. Ignored when bulk is provided as a request string/file.

longestonlybool, optional [not implemented]

Limit results to the longest continuous segment per channel. Ignored when bulk is provided as a request string/file.

filenamestr or file

If given, the downloaded data will be saved there instead of being parsed to an ObsPy object. Thus it will contain the raw data from the webservices.

Any additional keyword arguments will be passed to the webservice as
additional arguments. If you pass one of the default parameters and the
webservice does not support it, a warning will be issued. Passing any
non-default parameters that the webservice does not support will raise
an error.
property magnitude_types[source]#

Sorted list of distinct Netmag.magtype

pisces.fdsn.client.origins_to_fdsntext(origins, header=False)[source]#

Convert a SQLAlchemy Origin instances to FDSN event text.

#EventID | Time | Latitude | Longitude | Depth/km | Author | Catalog | Contributor | ContributorID | MagType | Magnitude | MagAuthor | EventLocationName #origin.orid|origin.time|origin.lat|origin.lon|origin.depth|netmag.auth|netmag.auth|netmag.auth|netmag.magtype|netmag.magnitude|sregion.srname or event.evname #origin.orid|origin.time|origin.lat|origin.lon|origin.depth|origin.auth|origin.auth|origin.auth|(‘ml’,’ms’,’mb’)|origin.(‘ml’,’ms’,’mb’)|sregion.srname or event.evname header_string = ‘#EventID|Time|Latitude|Longitude|Depth/km|Author|Catalog|Contributor|ContributorID|MagType|Magnitude|MagAuthor|EventLocationName’