pysep.utils.cap_sac =================== .. py:module:: pysep.utils.cap_sac .. autoapi-nested-parse:: Utils to honor file formats from SAC and CAP For SAC header names and descriptions, see: http://www.adc1.iris.edu/files/sac-manual/manual/file_format.html Attributes ---------- .. autoapisummary:: pysep.utils.cap_sac.SACDICT Functions --------- .. autoapisummary:: pysep.utils.cap_sac.write_cap_weights_files pysep.utils.cap_sac.append_sac_headers pysep.utils.cap_sac._append_sac_headers_trace pysep.utils.cap_sac.append_sac_headers_cartesian pysep.utils.cap_sac._append_sac_headers_cartesian_trace pysep.utils.cap_sac.format_sac_header_w_taup_traveltimes pysep.utils.cap_sac.format_sac_headers_post_rotation pysep.utils.cap_sac.origin_time_from_sac_header Module Contents --------------- .. py:data:: SACDICT .. py:function:: write_cap_weights_files(st, path_out='./', order_by='dist') Write CAP (Cut-and-Paste) moment tensor inversion code weight files, assuming that SAC headers are already present. TODO re-add Ptime setting with event.picks Replaces `write_cap_weights` The weight file has columns corresponding to the following: 0: EVENT_STATION_ID 1: DIST_KM 2: BODY_Z 3: BODY_R 4: SURF_Z 5: SURF_R 6: SURF_T 7: P_ARRIVAL 8: LEGACY (unused) 9: S_ARRIVAL 10: LEGACY (unused) 11: STATIC CORRECTION RAYLEIGH :type st: obspy.core.stream.Stream :param st: input stream to use to write CAP weight files, expected to have SAC header :type path_out: str :param path_out: path to write the weight file, filenames are set by default inside the function :type order_by: str :param order_by: how to order the list of stations that gets written out available options are: * dist: order by smallest to largest source-receiver distance (default) * az: order by smallest to largest azimuth (deg) * code: order alphabetically by station name .. py:function:: append_sac_headers(st, event, inv) Wrapper for trace header appending to get a loop and some logic in :type st: obspy.core.stream.Stream :param st: Stream to append SAC header to :type event: obspy.core.event.Event :param event: Event with metadata for SAC header :type inv: obspy.core.inventory.Inventory :param event: StationXML with metadata for SAC header :rtype: obspy.core.stream.Stream :return: Stream with SAC headers, those that could not be appended to have been removed from the stream .. py:function:: _append_sac_headers_trace(tr, event, inv) Append SAC headers to ObsPy streams given event and station metadata. Also add 'back_azimuth' to Stream stats which can be used for rotation. Rewritten from: `util_write_cap.add_sac_metadata()` TODO Add back in information removed from original function * Add sensor type somewhere, previously stored in KT? (used for picks) .. note:: We explicitely set 'iztype, 'b' and 'e' in the SAC header to tell ObsPy that the trace start is NOT the origin time. Otherwise all the relative timing (e.g., picks) in SAC will be wrong. :type tr: obspy.core.trace.Trace :param tr: Trace to append SAC header to :type event: obspy.core.event.Event :param event: Event with metadata for SAC header :type inv: obspy.core.inventory.Inventory :param inv: StationXML with metadata for SAC header :rtype: obspy.core.trace.Trace :return: Trace with appended SAC header .. py:function:: append_sac_headers_cartesian(st, event, stations) Specfem2D and Specfem3D may have domains defined in a Cartesian coordinate system that do not conform to the geographic coordinate systems that are are baked into ObsPy objects used by PySEP. Because of this, we cannot generate the required intermediate ObsPy objects to use `append_sac_headers`. This function creates a barebones SAC header with the available information and also takes into account the cartesian coordinate system for calculating things like azimuth and distance This is only meant to be used for RecSec to plot record sections. .. note:: RecSec requires SAC header values `kevnm`, `dist`, `az`, `baz`, `stlo`, `stla`, `evlo`, `evla` :type st: obspy.core.stream.Stream :param st: Stream to append SAC header to :type event: obspy.core.event.Event :param event: Event with metadata for SAC header :type inv: obspy.core.inventory.Inventory :param event: StationXML with metadata for SAC header :rtype: obspy.core.stream.Stream :return: Stream with barebones SAC headers to be used for Record Section .. py:function:: _append_sac_headers_cartesian_trace(tr, event, rcv_x, rcv_y) Append a barebones SAC header to a trace for Cartesian files which do not fit into the ObsPy framework of geographical coordinates. :type tr: obspy.core.trace.Trace :param tr: Trace to append SAC header to :type event: obspy.core.event.Event :param event: Event with location metadata for SAC header :type rcv_x: float :param rcv_x: X coordinate of the receiver in units meters :type rcv_y: float :param rcv_y: Y coordinate of the receiver in units meters :rtype: obspy.core.trace.Trace :return: Trace with appended SAC header .. py:function:: format_sac_header_w_taup_traveltimes(st, model='ak135', phase_list=('ttall', )) Add TauP travel times to the SAC headers using information in the SAC header Also get some information from TauP regarding incident angle, takeoff angle Hardcoded to only look at P and S arrivals (both upgoing and downgoing) TODO Probably find better ways to store arrival time and incident angles .. note:: This function expects that the Stream has been formatted with SAC header .. note:: SAC header writing could probably be in a loop, but I think it's more readable to see P and S values getting written separately. :type st: obspy.core.stream.Stream :param st: Stream object with SAC headers which will be written to with new SAC header attributser :type model: str :param model: name of the TauP model to use for arrival times etc. defaults to 'ak135' :type phase_list: list of str :param phase_list: phase names to get ray information from TauP with. Defaults to 'ttall', which is ObsPy's default for getting all phase arrivals. Must match Phases expected by TauP (see ObsPy TauP documentation for acceptable phases). .. py:function:: format_sac_headers_post_rotation(st) SAC headers do not update when rotating so we need to apply manual changes to the azimuth, inclination and naming values TODO is this necessary? Who is using the SAC headers and what info do they need? Or can we just re-run SAC header appending? :type st: obspy.core.stream.Stream :param st: Stream to append SAC headers for .. py:function:: origin_time_from_sac_header(sac_header) Build a UTCDateTime origin time from values in the SAC header appended to an ObsPy trace. :type sac_header: obspy.core.util.attribdict.AttribDict :param sac_header: SAC header built by `append_sac_header()` :rtype: UTCDateTime :return: event origin time built from SAC header