pisces.io.response#
- pisces.io.response.a0_from_pz(poles, zeros, a0f)[source]#
Calculate a0 from the poles and zeros of a transfer function
- Parameters:
- poles: list of complex numbers
- zeros: list of complex numbers
- a0f: float
The frequency at which a0 is to be calculated
- Returns:
- a0: float
The value of the transfer function at the provided a0f
Examples
>>> a0 = a0_from_pz(poles, zeros, a0f)
- pisces.io.response.format_datalogger(datalogObj)[source]#
Takes the output from channel.data_logger from an ObsPy Inventory-> channel object and formats the available data logger information into a single string description of the datalogger.
- Parameters:
- datalogObj: object
Channel.data_logger ObsPy object
- Returns
- ——-
- datalogger: string
Description of the data logger based on information avialable in the sensor object
- pisces.io.response.format_description(chanObj)[source]#
Takes an ObsPy Channel Object from an ObsPy Inventory-> channel objectand formats the available sensor, datalogger, and preamplifier information into a single string description of the instrument.
- Parameters:
- chanObj: object
Channel ObsPy object
- Returns
- ——-
- sensorDesc: string
Description of the sensor, data logger, and preamplifier based on information avialable in the channel object.
- pisces.io.response.format_preamp(preampObj)[source]#
Takes the output from channel.pre_amplifier from an ObsPy Inventory-> channel object and formats the available preamplifier information into a single string description of the instrument or returns None if no information is available.
- Parameters:
- preampObj: object
Channel.pre_amplifier ObsPy object
- Returns
- ——-
- preamp: string
Description of the sensor based on information avialable in the sensor object or returns None if no information is available.
- pisces.io.response.format_sensor(sensorObj)[source]#
Takes the output from channel.sensor from an ObsPy Inventory-> channel object and formats the available sensor information into a single string description of the instrument.
- Parameters:
- sensorObj: object
Channel.sensor ObsPy object
- Returns
- ——-
- sensor: string
Description of the sensor based on information avialable in the sensor object
- pisces.io.response.get_errors_from_obspy_uncertainties(varType)[source]#
Takes an ObsPy ComplexWithUncertainties or CoefficientWithUncertainties Object and finds the largest uncertainty value or returns 0 if all uncertainties are None. This is specifically to format pazfir files appropriately.
- Parameters:
- varType: object
ComplexWithUncertainties or CoefficientWithUncertainties ObsPy object
- Returns
- ——-
- vErr: complex or float
Maximum complex error if input is ComplexWithUncertainties or float if input is CoefficientWithUncertainties
- pisces.io.response.get_pazfir_data(fileLines, stageStart, stageType)[source]#
get_pazfir_data takes the metadata lists determeined from get_pazfir_metadata and returns lists containing the poles/numerators, zeros/denominators, and sensitivities/decimations of each stage.
While a pole-zero transfer function has the zeros in the numerator and the poles in the denominator, the structure of the pazfir files have the poles listed before the zeros for paz stages and the numerators listed before the denominators for the fir/iir stages. In order to reduce the number of if statements, each stage proceeds in order which is why the poles are in the same list as the numerators and the zeros are in the same list as the denominators.
- Parameters:
- fileLines: list of strings
Output from function get_pazfir_lines where each list element corresponds to one line of the file represented as a string. Elements are in the same order as lines in the file with commented lines not included.
- stageStart: list of integers, output from get_pazfir_metadata()
Index values for lines in fileLines that initiate a new response stage in the order they are found in the file.
- stageType: list of strings, output from get_pazfir_metadata()
Stage types as described above extracted from response stage initiation lines in fileLines found at the index values in the variable stageStart
- Returns:
- poles_nums: list of complex numbers
Each element in the list is a list of the either the poles for a corresponding paz stage, the numerators of a corresponding fir/iir stage, or None for a fap stage
- zeros_denoms: list of complex numbers
Each element in the list is a list of the either the zeros for a corresponding paz stage, the denominators of a corresponding fir/iir stage, or None for a fap stage
- sens_decim: list of floats
Each element in the list is a list of the either the gain/ sensitivity for a corresponding paz stage, the sampling frequency of a corresponding fir/iir stage, or None for a fap stage
Examples
>>> poles_nums, zeros_denoms, sens_decim = get_pazfir_data(fileLines, stageStart, stageType)
- pisces.io.response.get_pazfir_lines(path)[source]#
Takes a file path and read in the file into a list where each element is a line of the file. Commented lines are removed so the output only contains the lines described in the file definition.
- Parameters:
- path: str
Path to the pazfir file to be read.
- Returns:
- linesActual: list of strings
List where each list element corresponds to one line of the file represented as a string. Elements are in the same order as lines in the file with commented lines not included.
Examples
>>> fileLines = get_pazfir_lines('response_file.pazfir')
- pisces.io.response.get_pazfir_metadata(fileLines)[source]#
get_pazfir_metadata takes a list of lines read in from a pazfir type file as read in by pazfir_get_lines. The lines from the file that indicate a new stage are identified and the metadata regarding that stage are extracted into a set of lists.
A line initiating a new response stage in a pazfir file is assumed to take the following form:
theoretical 1 instrument paz
where the first variable is assumed to be “theoretical” or “measured”, the second variable is the sequence number of the response stage, the third is assumed to be “instrument” or “digitizer”, and the fourth is the type of response stage, such as paz, fir, fap, or iir.
For each line initiating a new stage, the above information is extracted and parsed into lists organized by variable type where the index of each list elemnent corresponds to the order that each stage is read in. The lists are then returned by the function.
- Parameters:
- fileLines: list of strings
Output from function get_pazfir_lines where each list element corresponds to one line of the file represented as a string. Elements are in the same order as lines in the file with commented lines not included.
- Returns:
- stageStart: list of integers
Index values for lines in fileLines that initiate a new response stage in the order they are found in the file.
- stageNums: list of integers
Stage numbers extracted from response stage initiation lines in fileLines found at the index values in the variable stageStart
- stageType: list of strings
Stage types as described above extracted from response stage initiation lines in fileLines found at the index values in the variable stageStart
- sourceType: list of strings
Stage source in the insturmentation chain, instrument or digitizer, extracted from response stage initiation lines in fileLines found at the index values in the variable stageStart
- t_v_m: list of strings
Either “theoretical” or “measured” for each stage from response stage initiation lines in fileLines found at the index values in the variable stageStart
Examples
>>> stageStart, stageNums, stageType, sourceType, t_v_m = get_pazfir_metadata(fileLines)
- pisces.io.response.get_source_type_from_units(inType, outType, stageNum)[source]#
Makes an assumption about the source of the stage, whether it’s from a sensor, digitizer, or anti-alias filter based on the input and output units of that stage. It writes this assumption into file with a a correspondint line in the header indicating what assumption was made based on what units.
- Parameters:
- inType: string
One of finite set of ‘DISP’,’VEL’,’ACC’,’PRESSURE’, ‘TESLA’, ‘VOLTS’, and ‘COUNTS’
- outType: string
One of finite set of ‘VOLTS’ and ‘COUNTS’
- stageNum: integer
Number of stage in response sequence
- Returns:
- sourceType: string
One of finite set of ‘instrument’, ‘digitizer’, ‘antialias’, and ‘unknown’
- linesOut: string
Line to be added to the file header
- pisces.io.response.get_stationxml_lines(respStage)[source]#
Extract variables from a response stage to write the contents of that stage to the file header for documentation purposes.
- Parameters:
- respStage: object
Input is ObsPy response object of a finite set of types PolesZerosResponseStage, CoefficientsTypeResponseStage, FIRResponseStage, and ResponseListResponseStage as well as the ResponseStage parent object.
- Returns:
- respStageLines: string
Lines to be added to the header describing the input stage object
- pisces.io.response.read_pazfir(path, input_samp_rate, calib, calper, input_units, nm_to_m=True, calratio=None, calculate_delays=True)[source]#
Read in a pazfir file and output the instrument response in the form of an obspy response object.
- Parameters:
- path: str
- input_sample_rate: float
The sample rate of the instrument for which the response is valid
- calib: float
The scaling variable contained in the calib field of an instrument or wfdisc table
- calper: float
The period at which calib was calculated contained in an instrument or wfdisc table
- input_units: string
Specify whether the input file units are in Displacement (‘DISP’), Velocity (‘VEL’), Acceleration (‘ACC’), or Pressure (‘PRESSURE’). Units of displacement, velocity, or acceleration are assumed to be in nanometers following the KBCore, CSS3.0, and Antelope specifications. Units of pressure are assumed to be in Pascals.
- nm_to_m: boolean
Specify whether the output response object is in units displacement, velocity or acceleration will be in meters or nanometers. Default is in meters and set to true.
- a0f: float
The frequency at which to calculate a0. If calper is provided, that value is converted to frequency and used
- calratio: float
Calibration conversion ratio found in a KBCore/CSSS3.0 sensor table
- calculate_delays: boolean
Calculate group delays of FIR and IIR stages using scipy’s group_delay function. Default is True and group delays are calculated and included in the response object. It is assumed that the data is corrected for the delay by the digitizer so the delay is set in both the delay and correction fields. This may not be true but cannot be evaulated from pazfir files/CSS3-like databases.
- Returns:
- total_resp: obspy.core.inventory.response.Response object
- pisces.io.response.sxml2db(input_xml, schema='kbcore', out_freq=None, dir_path=None, write_tables=True, tab_delim=True)[source]#
Takes a StationXML file or an ObsPy Inventory object and writes out a pazfir style file for every response contained within the file/object and optionally writes network, affiliation site, sitechan, sensor, and instrument flat files. Files are automatically named based on provided network, station, location, channel, and starttime in year and julian day as well as given a file extenstion descriptive of the stage types contained within the file. This is done such that the corresponding file name is not more than 32 characters which is the maximum allowed string length for the dir column in the instrument tables for CSS3.0- like schemas. This function will also return the dictionaries used to create all of the flatfiles.
- Parameters:
- input_xml: string or Inventory object
If a filename is provided, the file will be read in as an Inventory object
- schema: string
Dictates the schema to which a file is written. The options are “KBCORE”, “CSS3.0”, and “ANTELOPE” and capilization is unimportant.
- out_freq: float
Frequency at which to calculate the output sensitivity. If no frequency is provided, the normalization or gain frequency in the first stage of response will be used.
- dir_path: string
Directory in which to output the pazfir and sensor/instrument files. If no directory is provided, the current working directory will be selected.
- write_tables: boolean
Default is True. If True, a sensor table, ‘sensor.txt’, and instrument table,
- ‘instrument.txt’, formatted according to the KBCore spec will be written to the output
directory. If false, no sensor or instrument tables will be written, but the pazfir files will be.
- tab_delim: True or False
False will output a fixed-width formatted file and True will output a tab delimited file
- Returns:
- netDict: dict
Dictionary containing all of the network metadata in the Inventory object as specified by the input Schema.
- affilDict: dict
Dictionary containing all of the affiliates networks and stations in the Inventory object as specified by the input Schema.
- siteDict: dict
Dictionary containing all of the station metadata in the Inventory object as specified by the input Schema.
- sitechanDict: dict
Dictionary containing all of the channel metadata in the Inventory object as specified by the input Schema. Chanid is automatically assigned based on channel in the object
- sensorDict: dict
Dictionary containing all of the sensor metadata in the Inventory object as specified by the input Schema. Chanid and Inid are automatically assigned based on channel and response indices in the object
- instrumentDict: dict
Dictionary containing all of the sensor metadata in Inventory object as specified by the input Schema. Inid is automatically assigned based on the response index within the object and will correspond to the correct chanid in the sensor table
Examples
>>> network, affiliation, site, sitechan, sensor, instrument = sxml2pazfir('stationxml_path', write_tables=False) >>> sxml2db(InventoryObject, schema='CSS3.0', out_freq=1.0, dir_path='path_to_directory')
- pisces.io.response.write_dict_to_flatfile(tableDict, dirPath=None, tab_delim=False, schema='kbcore')[source]#
Takes a dictionary of any of network, affiliation, site, sitechan, sensor, or instrument with all of the output table colunns as keys withlists of values corresponding to the appropriate values from in an inventory object and output a fixed-width formatted or tab delimited flatfile corresponding to that table.
- Parameters:
- tableDict: dict
Network, affiliation, site, sitechan, sensor, or instrument dictionary to be written as a flat file. Must have a “tablename” key indicating which table type and the other keys must correspond to the columns of that table.
- dirPath: string
Directory in which to write the files. If none is provided, the current working directory will be used.
- tab_delim: True or False
False will output a fixed-width formatted file and True will output a tab delimited file
- schema: string
Dictates the schema to which a file is written. The options are “KBCORE”, “CSS3.0”, and “ANTELOPE” and capilization is unimportant.
- Returns:
- Writes file to directory of any of network_table.txt, affiliation_table.txt, site_table.txt,
- sitechan_table.txt, sensor_table.txt, and instrument_table.txt
- pisces.io.response.write_pazfir(response, station, channel, starttime, out_freq=None, dir_path=None, network=None, location=None, endtime=None, sample_rate=None, sensor=None, data_logger=None, pre_amplifier=None, **stationDict)[source]#
Writes a pazfir style file of file name format like
<network>.<station>.<location>.<channel>.<year><julian day>.<extension>
where the extension is some combination of the stages represented in the file (paz, fir, fap, iir) and returns the sensitivity value at which the file is valid, the frequency at which the sensitivity is calculated, and the filename of the written file. The ground motion units of the file are in displacement in nanometers as this is the file spec defined by CSS3.0 like database schemas.
- Parameters:
- response: object
ObsPy Response object to written as a pazfir file
- station: string
Station code associated with the response (required)
- channel: string
Channel code associated with the response (required)
- starttime: object
ObsPy UTCDataTime Object for the starting time at which the response is valid
- out_freq: float
Frequency at which to calculate the output sensitivity. If no frequency is provided, the normalization or gain frequency in the first stage of response will be used.
- dir_path: string
Directory in which to output the pazfir and sensor/instrument files. If no directory is provided, the current working directory will be selected.
- network: string
Network Code associated with the response. Recorded in file header.
- location: string
Location Code associated with the response. Recorded in file header.
- endtime: object
ObsPy UTCDataTime Object for the ending time at which the response is valid. Recorded in file header.
- sample_rate: float
Sampling rate of the channel the response corresponds to. Recorded in header.
- sensor: string
Name of the sensor associated with the response. Recorded in header.
- data_logger: string
Name of the digitizer associated with the response. Recorded in header.
- pre_amplifier: string
Description of the pre-amplifier associated with the response. Recorded in header.
- stationDict: dict
For all inputs labeled as “Recorded in header.” A dictionary of the values with the same input variable names as keys can be used as input instead of assigning each input individually.
- Returns:
- sensitivity: float
The overall instrument sensitivity associated with the response recorded in the file written to the input directory path or current working directory.
- out_freq: float
Frequency at which to calculate the output sensitivity. If out_freq was provided as input, it will be the same, otherwise it will be the normalization or gain frequency in the first stage of response.
- fileName: string
The name of the file the response was written to.