pisces.io.sac#
Conversions between SAC header variables and CSS or KB Core fields.
Converts a SAC header dictionary into a list of table dictionaries and vice-versa.
- pisces.io.sac.cast_to_float(original_func)[source]#
Cast a function’s argument to float before the function operates on it, like:
Examples
>>> @cast_to_float ... def stla_to_lat(stla): ... return stla >>> lat = stla_to_lat(numpy.float32(12.3)) >>> type(lat) float # not numpy.float32
- pisces.io.sac.cast_to_int(original_func)[source]#
Cast a function’s argument to int before the function operates on it, like:
Examples
>>> @cast_to_int ... def nwfid_to_wfid(nwfid): ... return nwfid >>> nwfid_to_wfid(12.3) 12
- pisces.io.sac.get_sac_reftime(header)[source]#
Get SAC header reference time as a UTCDateTime instance from a SAC header dictionary.
If using ObsPy to read the SAC file, use debug_headers=True to get the full header, including nz time headers.
- pisces.io.sac.origin2sachdr(o)[source]#
Accepts a fielded origin table record and produces a dictionary of corresponding sac header field/value pairs.
- pisces.io.sac.sachdr2arraysite(header)[source]#
Provide a SAC header dictionary, get a site table dictionary. This is a slight modification of sachdr2site that handles deast & dnorth being in SAC’s user7 & user8 header fields (a poor but documented standard that is the de facto appoach - see SAC’s BBFK or ARRAYMAP or BRTT’s db2sac in Antelope).
Note that user7 & user8 are expected to be in km (consistent with SAC expectations).
- pisces.io.sac.sachdr2arrival(header, pickmap=None)[source]#
Similar to sachdr2assoc, but produces a list of up to 10 Arrival dictionaries. Same header->phase mapping applies, unless otherwise stated.
- pisces.io.sac.sachdr2assoc(header, pickmap=None)[source]#
Takes a sac header dictionary, and produces a list of up to 10 Assoc instances. Header->phase mappings follow SAC2000, i.e.:
t0: P
t1: Pn
t2: Pg
t3: S
t4: Sn
t5: Sg
t6: Lg
t7: LR
t8: Rg
t9: pP
An alternate mapping for some or all picks can be supplied, however, as a dictionary of strings in the above form.
Note: arid values will not be filled in, so do: >>> for assoc in kbio.tables[‘assoc’]:
assoc.arid = lastarid+1 lastarid += 1
- pisces.io.sac.sachdr2origin(header)[source]#
Provide a sac header dictionary, get a filled origin table dictionary. A few things: 1) If sac reference time isn’t event-based, origin time is unknown 2) magnitude is taken first from hdr[‘mag’], hdr[‘imagtyp’] if defined,
then replaced by hdr[‘user0’],hdr[‘kuser0’]
sac moment, duration, and user-defined magnitude headers aren’t put into the origin table
origin.auth is taken first from hdr[‘imagsrc’], then replaced by hdr[‘kuser1’] if defined. the imagsrc->auth translations are:
INEIC -> ISC:NEIC
IPDE -> PDE
IISC -> ISC
IBRK -> ISC:BERK
IUSGS, ICALTECH, ILLNL, IEVLOC, IJSOP, IUSER, IUNKNOWN -> unchanged
- pisces.io.sac.sachdr2site(header)[source]#
Provide a SAC header dictionary, get a site table dictionary.
- pisces.io.sac.sachdr2sitechan(header)[source]#
Provide a sac header dictionary, get a sitechan table dictionary.
- pisces.io.sac.sachdr2tables(header, tables=None)[source]#
Scrape SAC header dictionary into database table dictionaries.
- Parameters:
- headerdict
SAC header
- tableslist/tuple of strings, optional
Table name strings to return. Default, [‘affiliation’, ‘arrival’, ‘assoc’, ‘event’, ‘instrument’, ‘origin’, ‘site’, ‘sitechan’, ‘wfdisc’]
- Returns:
- dict
Dictionary of lists of table dictionaries. If only default values are found for a table, it is omitted.
Notes
Some things must be checked or filled in before adding to a database: - affiliation.time, endtime - arrival.arid - assoc.orid, arid - event.prefor, evid - instrument.inid, dir, dfile, rsptype - site.ondate - sitechan.ondate, chanid - wfdisc.dir, dfile, foff, datetype, wfid
- pisces.io.sac.sachdr2wfdisc(header)[source]#
Produce wfdisc kbcore table instance from sac header dictionary. Clearly this will be a skeleton instance, as the all-important ‘dir’ and ‘dfile’ and ‘datatype’ must be filled in later.
- pisces.io.sac.site2sachdr(s)[source]#
Accepts a fielded site table row and returns a dictionary of corresponding sac header field/value pairs.
June 13, 2016 - added deast/dnorth output to SAC user7/8 header fields
- pisces.io.sac.strip_string(original_func)[source]#
Strip white space from a function’s argument to float before the function operates on it, like:
Examples
>>> @strip_string ... def kcmpnm_to_chan(kcmpnm): ... return kcmpnm[:6] >>> kclmpnm_to_chan(' my_too_long_component ') 'my_too'