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.affiliation2sachdr(af)[source]#
pisces.io.sac.arrival2sachdr(ar)[source]#
pisces.io.sac.assoc2sachdr(asc)[source]#
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.chan_to_kcmpnm(chan)[source]#
pisces.io.sac.event2sachdr(evt)[source]#
pisces.io.sac.evname_to_kevnm(evname)[source]#
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.ievreg_to_grn(ievreg)[source]#
pisces.io.sac.ievtyp_to_etype(ievtyp)[source]#

Provide the ievtyp(e) integer, get the etype string.

pisces.io.sac.insname_to_kinst(insname)[source]#
pisces.io.sac.instrument2sachdr(ins)[source]#
pisces.io.sac.kcmpnm_to_chan(kcmpnm)[source]#
pisces.io.sac.kevnm_to_evname(kevnm)[source]#
pisces.io.sac.kinst_to_insname(kinst)[source]#
pisces.io.sac.knetwk_to_net(knetwk)[source]#
pisces.io.sac.kstnm_to_sta(kstnm)[source]#
pisces.io.sac.net_to_knetwk(net)[source]#
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.sachdr2affiliation(header)[source]#
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.sachdr2event(header)[source]#
pisces.io.sac.sachdr2instrument(header)[source]#
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’]

  1. sac moment, duration, and user-defined magnitude headers aren’t put into the origin table

  2. 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.sitechan2sachdr(sc)[source]#
pisces.io.sac.sta_to_kstnm(sta)[source]#
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'
pisces.io.sac.swap_if_value(detected_value, return_value)[source]#
pisces.io.sac.tables2sachdr(tables)[source]#

Returns a sac header dictionary, including default values, from current table instances. SAC reference time is, in order of availability, origin time (origin.time), first sample time (wfdisc.time).

pisces.io.sac.truncate_string(N)[source]#
pisces.io.sac.wfdisc2sachdr(wf)[source]#