seismic.inventory package¶
Subpackages¶
Submodules¶
seismic.inventory.add_time_corrections module¶
seismic.inventory.engd2stxml module¶
seismic.inventory.fdsnxml_convert module¶
Helper functions to convert FDSN station XML files to Seiscomp3 SC3ML format.
Can be used as a standalone tool as well:
fdsnxml_convert.py src_path dst_path
- seismic.inventory.fdsnxml_convert.sc3_conversion_available()[source]¶
- Check whether conversion to seiscomp3 format is available os this system.
Only works for Python 3, for Python 2 it always returns True (i.e. give it a try).
- Returns:
True if conversion to sc3ml can be performed on this system, False otherwise.
- Return type:
- seismic.inventory.fdsnxml_convert.toSc3ml(src_path, dst_path, response_fdsnxml=None)[source]¶
Convert file(s) in src_path from FDSN station XML to SC3ML and emit result(s) to dst_path.
If src_path is a file, dst_path will be treated as a file. If dst_path already exists as a folder, an exception is raised.
If src_path is a folder, dst_path will be treated as a folder. If dst_path already exists as a file, an exception is raised. The src_path directory hierarchy will be walked to find all .xml files, each of which will be converted to a mirrored relative path under dst_path.
- Parameters:
src_path (str or pathlib.Path) – The source path from which to input XML file(s).
dst_path (str or pathlib.Path) – The destination path into which converted sc3ml file(s) are output.
response_fdsnxml (str or Path) – Path to existing for containing dummy response to insert into records where instrument response is missing.
- Raises:
OSError, FileNotFoundError, RuntimeError, FileExistsError
seismic.inventory.generate_network_plots module¶
seismic.inventory.inventory_merge module¶
seismic.inventory.inventory_split module¶
Split a station inventory file into a separate file per network.
- seismic.inventory.inventory_split.inventory_split(inv_file, output_folder, sc3ml=False)[source]¶
Split an inventory file (station XML) into separate inventory file per network, stored in folder output_folder.
- Parameters:
inv_file (str or path) – Station inventory to be split. This file is not changed by the script.
output_folder (str or path to folder) – Folder where per-network station xml files will be generated.
sc3ml (bool, optional) – If True, try to convert output files to sc3ml format if possible using seiscomp3. Defaults to False.
- seismic.inventory.inventory_split.split_inventory_by_network(obspy_inv, output_folder, validate=False)[source]¶
Export a station XML file per network for each network in given obspy Inventory.
- Parameters:
obspy_inv (obspy.core.inventory.inventory.Inventory) – Obspy Inventory containing the networks to export to file.
output_folder (str or pathlib.Path) – Folder in which to output the per-network XML files. Will be created if doesn’t yet exist.
validate (bool, optional) – Whether to validate the station data on write, defaults to False
seismic.inventory.inventory_util module¶
Utility functions and constants shared amongst inventory management modules.
- class seismic.inventory.inventory_util.Instrument(sensor, response)¶
Bases:
tuple
Create new instance of Instrument(sensor, response)
- property response¶
Alias for field number 1
- property sensor¶
Alias for field number 0
- seismic.inventory.inventory_util.extract_unique_sensors_responses(inv, req, show_progress=True, blacklisted_networks=None, test_mode=False)[source]¶
For the channel codes in the given inventory, determine a nominal instrument response suitable for that code. Note that no attempt is made here to determine an ACTUAL correct response for a given network and station. The only requirement here is to populate a plausible, non-empty response for a given channel code, to placate Seiscomp3 which requires that an instrument response always be present.
- Parameters:
inv (obspy.core.inventory.inventory.Inventory) – Seismic station inventory
req (Object conforming to interface of 'requests' library) – Request object to use for URI query
- Returns:
Python dict of (obspy.core.inventory.util.Equipment, obspy.core.inventory.response.Response) indexed by str representing channel code
- Return type:
{str: Instrument(obspy.core.inventory.util.Equipment, obspy.core.inventory.response.Response) } where Instrument is a collections.namedtuple(“Instrument”, [‘sensor’, ‘response’])
- seismic.inventory.inventory_util.load_station_xml(inventory_file)[source]¶
Load a stationxml file
- Parameters:
inventory_file (str or path) – Name of stationxml file to load
- Returns:
Station inventory as Obspy Inventory
- Return type:
- seismic.inventory.inventory_util.obtain_nominal_instrument_response(netcode, statcode, chcode, req)[source]¶
For given network, station and channel code, find suitable response(s) in IRIS database and return as dict of obspy instrument responses.
- Parameters:
- Returns:
Dictionary of instrument responses from IRIS for given network(s), station(s) and channel(s).
- Return type:
dict of {str, Instrument(obspy.core.inventory.util.Equipment, obspy.core.inventory.response.Response)}
seismic.inventory.iris_query module¶
Helper functions for making and managing web queries to IRIS web service.
- seismic.inventory.iris_query.form_channel_request_url(netmask='*', statmask='*', chanmask='*')[source]¶
Form request URL to download station inventory in stationxml format, down to channel level, with the given filters applied to network codes, station codes and channel codes.
- Parameters:
netmask (str, optional) – Pattern of network codes to match, comma separated with wildcards, defaults to “*”
statmask (str, optional) – Pattern of station codes to match, comma separated with wildcards, defaults to “*”
chanmask (str, optional) – Pattern of channel codes to match, comma separated with wildcards, defaults to “*”
- Returns:
Fully formed URL to perform IRIS query and get back FDSN station XML result.
- Return type:
- seismic.inventory.iris_query.form_response_request_url(netmask, statmask, chanmask)[source]¶
Form request URL to download station inventory in stationxml format, down to response level, for the given network, station and channel codes.
- Parameters:
- Returns:
Fully formed URL to perform IRIS query and get back FDSN station XML result.
- Return type:
- seismic.inventory.iris_query.set_text_encoding(resp, quiet=False)[source]¶
For the given response object, set its encoding from the contents of the text returned from server.
- Parameters:
resp (requests.Response) – Query response object returned by response.get()
seismic.inventory.pdconvert module¶
seismic.inventory.plotting module¶
seismic.inventory.response module¶
- Description:
Implements a Class for reading/storing responses from a number of sources. The ResponseFactory class is used for attaching ‘bogus’ responses to station inventories that lack them.
References:
CreationDate: 14/02/19
Developer: rakib.hassan@ga.gov.au
- Revision History:
LastUpdate: 14/02/19 RH LastUpdate: dd/mm/yyyy Who Optional description
- class seismic.inventory.response.ResponseFactory[source]¶
Bases:
object
The ResponseFactory class encapsulates the generation of a collection of named Instrument Response Objects from a variety of sources. Currently it provides the facility to create Response objects from two sources, namely, Poles and Zeroes supplied by the user and from StationXML files generated from RESP files using the PDCC tool (link below). The conversion of RESP files into a corresponding StationXML file, at this stage, must take place externally, because ObsPy lacks that functionality. The intended usage of this class during the creation of an ASDF dataset is as follows:
1. User creates a number of uniquely named Response objects (see associated tests as well) pertaining to different channels in a given survey. 2. User fetches these Response objects from an instance of ResponseFactory as needed, while creating ObsPy Channel objects, during which Response objects can be passed in as an argument. 3. User builds a hierarchy of channel->station->network inventories, with the appropriate instrument response information embedded 4. The master FDSN StaionXML file output after step 3 can then be converted into an SC3ML file (which can be ingested by SeisComp3) using the fdsnxml2inv tool.
PDCC tool: https://ds.iris.edu/ds/nodes/dmc/software/downloads/pdcc/
- CreateFromInventory(name, obspy_inventory)[source]¶
Create response from an Inventory
- Parameters:
name (str) – Name of the response for later retrieval
obspy_inventory (obspy.core.inventory.inventory.Inventory) – Inventory from which to extract response
- CreateFromPAZ(name, pzTransferFunctionType, normFactor, normFreq, stageGain, stageGainFreq, poles, zeros)[source]¶
- class ResponseFromInventory(source_inventory)[source]¶
Bases:
object
Helper class to get Obspy Response object from an Inventory
- Raises:
RuntimeError – Raises error if response not found
Constructor
- Parameters:
source_inventory (obspy.core.inventory.inventory.Inventory) – Inventory from which to extract response
- class ResponseFromPAZ(pzTransferFunctionType='LAPLACE (RADIANS/SECOND)', normFactor=80000.0, normFreq=0.01, stageGain=2000.0, stageGainFreq=0.01, poles=[0j], zeros=[0j])[source]¶
Bases:
object
- class ResponseFromStationXML(respFileName)[source]¶
Bases:
ResponseFromInventory
Helper class to get Obspy Response object from a station xml file
Constructor
- Parameters:
respFileName (str) – XML file to load
- getResponse(name)[source]¶
Retrieve response by name
- Parameters:
name (str) – Name given to response at creation time
- Raises:
RuntimeError – Raises error if name is not recognized
- Returns:
The requested response
- Return type:
seismic.inventory.table_format module¶
seismic.inventory.update_iris_inventory module¶
Automatically update IRIS-ALL.xml file from IRIS web portal.
Output file is saved as FDSN station xml. Script also generates human readable form as IRIS-ALL.txt.
Example usages:
python update_iris_inventory.py
python update_iris_inventory.py -o outfile.xml
python update_iris_inventory.py --netmask=U* --statmask=K*
python update_iris_inventory.py --netmask=UW,LO --output outfile.xml
- seismic.inventory.update_iris_inventory.cleanup(tmp_filename)[source]¶
Helper function to clean up temporary file on disk.
- Parameters:
tmp_filename (str) – File name to clean up
- seismic.inventory.update_iris_inventory.regenerate_human_readable(iris_data, outfile)[source]¶
Generate human readable, tabular version of the IRIS database.
- seismic.inventory.update_iris_inventory.repair_iris_metadata(iris)[source]¶
Perform text subtitutions to fix known errors in station xml returned from IRIS.
- Parameters:
iris (requests.models.Response) – Response to IRIS query request containing response text
- Returns:
The text from the response with known faulty data substituted with fixed data.
- Return type:
- seismic.inventory.update_iris_inventory.update_iris_station_xml(req, output_file, options=None)[source]¶
Pull the latest IRIS complete station inventory (down to station level, not including instrument responses) from IRIS web service and save to file in FDSN station xml format.
- Parameters:
req (Object conforming to interface of 'requests' library) – Request object to use for URI query
output_file (str) – Destination file to generate
options (Python dict of key-values pairs matching command line options, optional) – Filtering options for network, station and channel codes, defaults to None