shakelib.rupture.origin

class shakelib.rupture.origin.Origin(event)[source]

Bases: object

The purpose of this class is to read/store event origin information, which is usually derived from an xml file called “event.xml”. There is also a mechanism to overwrite information in event.xml with a file in the input directory called “source.txt”.

Note that this class is generally contained within a Rupture instance.

Event values are:

  • eventsourcecode: the event id.
  • created: file creation time (Unix epoch - seconds since Jan 1, 1970).
  • lat: hypocenter latitude (decimal degrees; -90 to 90).
  • lon: hypocenter longitude (decimal degrees; -180 to 180).
  • depth: hypocenter depth (km, positive down).
  • locstring: a free-form descriptive string of location.
  • mag: earthquake magnitude.
  • year: 4 digit format.
  • month: 1-12.
  • day: 1-31.
  • hour: 0-23.
  • minute: 0-59.
  • second: 0-59.
  • timezone: abbreviation (i.e., GMT, PST, PDT).
  • mech: a string specifying the rupture mechanism; the accepted types are RS, SS, NM, and ALL, for reverse slip, strike slip, normal, and unspecified ruptures, respectively.

For backward-compatibility, we also check for ‘type’. If both ‘mech’ and ‘type’ are missing (or empty strings) then ‘mech’ is set to ALL.

Construct an Origin object.

Parameters:
  • event (dict) – Dictionary of values. See list above for required
  • keys.
Returns:

Origin object.

classmethod fromFile(eventxmlfile, sourcefile=None)[source]

Class method to create a Origin object by specifying an event.xml file, a rupture file, and a source.txt file.

Parameters:
  • eventxmlfile (str) – Event xml file (see read_event_file()).
  • sourcefile (str) – source.txt file (see read_source()).
Returns:

Origin object.

getHypo()[source]
Returns:Hypocenter as OpenQuake Point instance.
setMechanism(mech=None, rake=None, dip=None)[source]

Set the earthquake mechanism manually (overriding any values read in from event.xml or source.txt. If rake and dip are not specified, they will be assigned by mechanism as follows:

Mech Rake Dip
RS 90 40
NM -90 50
SS 0 90
ALL 45 90
Parameters:
  • mech (str) – One of ‘RS’ (reverse), ‘NM’ (normal), ‘SS’ (strike slip), or ‘ALL’ (unknown).
  • rake (float) – Value between -360 and 360 degrees. If set, will override default value for mechanism (see table above).
  • dip (float) – Value betweeen 0 and 90 degrees. If set, will override default value for mechanism (see table above). Value will be converted to range between -180 and 180 degrees.
shakelib.rupture.origin.read_event_file(eventxml)[source]

Read event.xml file from disk, returning a dictionary of attributes. Input XML format looks like this:

<earthquake
    id="2008ryan "
    lat="30.9858"
    lon="103.3639"
    mag="7.9"
    year="2008"
    month="05"
    day="12"
    hour="06"
    minute="28"
    second="01"
    timezone="GMT"
    depth="19.0"
    locstring="EASTERN SICHUAN, CHINA"
    created="1211173621"
    otime="1210573681"
    type=""
/>
Parameters:eventxml (str) – Path to event XML file OR file-like object.
Returns:
Dictionary with keys:
  • eventsourcecode Origin network and origin code (i.e., us2017abcd).
  • eventsource Origin network (“us”).
  • time Origin time as an HistoricTime object.
  • lat Origin latitude
  • lon Origin longitude
  • depth Origin depth
  • mag Origin magnitude
  • created Process time as an HistoricTime object.
  • locstring Location string
  • mechanism Moment mechanism, one of: - ‘RS’ (Reverse) - ‘SS’ (Strike-Slip) - ‘NM’ (Normal) - ‘ALL’ (Undetermined)
Return type:dict
shakelib.rupture.origin.read_source(sourcefile)[source]

Read source.txt file, which has lines like key=value.

Parameters:sourcefile – Path to source.txt file OR file-like object
Returns:Dictionary containing key/value pairs from file.
Return type:dict