pisces.fdsn.catalog#

Convert CSS 3.0 / NNSA KB Core database query results into ObsPy Catalog / QuakeML objects.

The main entry point is catalog, which accepts the flat, redundant result sets produced by the pisces.events.filter_* functions and returns an obspy.core.event.Catalog.

Examples#

>>> from pisces.catalog import catalog
>>> cat = catalog(query, resource_prefix='smi:local', description='my catalog')
class pisces.fdsn.catalog.QMLGenerator(resource_prefix='smi:local')[source]#

Bases: object

Convert CSS/KBCore database results to QuakeML/Obspy event objects.

Examples

>>> q = QMLGenerator(resource_prefix='smi:lanl.gov')
>>> e = q.event(my_database_event_row)
>>> e
Event:      2012-04-04T14:21:42.300000Z | +41.818,  +79.689 | 4.4  mb | manual
       resource_id: ResourceIdentifier(id="smi:lanl.gov/event/evid=1")
            event_type: 'not reported'
         creation_info: CreationInfo(agency_uri=...)
    referred_origin_id: ResourceIdentifier(id=...)
amplitude(row, pick_id=None, waveform_id=None)[source]#

Initialize an obspy.core.event.Amplitude from an Arrival or Amplitude row.

arrival(assoc, pick_id=None)[source]#

Initialize an obspy.core.event.Arrival from a database Assoc row.

catalog(description=None, comments=None)[source]#

Initialize an empty obspy Catalog.

Returns a Catalog with creation info and resource id set, and no events. Events are added by the module-level catalog function.

Parameters:
descriptionstr

Passed directly to obspy.core.event.Catalog during creation.

commentslist of obspy.core.event.Comment

Passed directly to obspy.core.event.Catalog during creation.

Returns:
obspy.core.events.Catalog

An empty catalog.

TODO:
  • focal mechanisms
  • station magnitudes

Examples

>>> qgen = QMLGenerator(resource_prefix='smi:my.institute.edu')
>>> cat = qgen.catalog(description="my catalog")
event(event)[source]#

Return an obspy.core.event.Event from a database Event row.

magnitude(netmag, origin_id=None)[source]#

Initialize an obspy.core.event.Magnitude from a database Netmag row.

origin(origin)[source]#

Return an obspy.core.event.Origin from a database Origin row.

pick(arrival)[source]#

Initialize an obspy.core.event.Pick from a database Arrival row.

stationmagnitude(stamag, origin_id=None, amplitude_id=None)[source]#

Initialize an obspy.core.event.StationMagnitude from a database Stamag row.

pisces.fdsn.catalog.catalog(*queries, resource_prefix='smi:local', description=None, comments=None, preferred_magnitude=('mb', 'mw', 'ms'))[source]#

Build an ObsPy Catalog from one or more CSS/KBCore database result sets.

Query results are flat and redundant: a joined row repeats its parent values once per child, so the same Event appears on every row of its Origins, the same Origin on every row of its Netmags, and so on. This function walks each result set once, converting each distinct database row to its QuakeML counterpart the first time that row is seen and reusing it thereafter, so repeated rows collapse into a single QuakeML object.

Rows are the unit of correspondence: Assoc/Arrival and Netmag/Stamag that arrive together on one row are related to each other, and are linked accordingly.

Multiple queries accumulate into one catalog. A query whose rows reference an Event or Origin already seen in an earlier query merges into that existing QuakeML object rather than duplicating it, so related result sets (events, then arrivals, then magnitudes) can be combined.

Parameters:
queriessqlalchemy.orm.Query instances

One or more queries, output from filter_events, filter_arrivals, or filter_magnitudes, with any of the following structures (tables in any order):

query = session.query(Event, Origin)  # from filter_events
query = session.query(Event, Origin, Netmag)  # from filter_magnitudes

# from filter_magnitudes
query = session.query(Event, Origin, Netmag, Stamag)

# from filter_arrivals
query = session.query(Event, Origin, Assoc, Arrival)

Event and Origin must be present in every query.

resource_prefixstr

The prefix used when creating ResourceIndentifier ids. e.g. ‘smi:lanl.gov’ will result in ‘smi:lanl.gov/event/<evid>’ for events, etc…

description, commentsstr

Passed directly to obspy.core.event.Catalog during creation.

preferred_magnitudetuple of str

Magnitude types in preferred order, case-insensitive. The first matching Netmag on the event’s preferred Origin becomes the QuakeML preferred magnitude. Defaults to ("mb", "mw", "ms"). This marks preferred_magnitude_id but retains all supplied magnitude rows.

Returns:
obspy.core.event.Catalog

Events in the order first encountered. Empty if no queries are provided.

Raises:
ValueError

If a query doesn’t include both an Event and an Origin table.

Notes

Incoming rows look like the following, which is the redundancy this function collapses. Note how parent values repeat down each block:

event1, origin1
event1, origin2
event2, origin3
event2, origin4
...
or
event1, origin1, netmag1
event1, origin1, netmag2
event1, origin1, netmag4
event1, origin2, netmag5
event2, origin3, netmag6
...
or
event1, origin1, netmag1, stamag1
event1, origin1, netmag1, stamag2
event1, origin1, netmag1, stamag3
event1, origin1, netmag2, stamag4
event1, origin1, netmag2, stamag5
...
or
event1, origin1, assoc1/arrival1
event1, origin1, assoc2/arrival2
event1, origin2, assoc3/arrival3
event1, origin2, assoc4/arrival4
event2, origin3, assoc5/arrival5
...
or
event1, origin1, assoc1, arrival1
event1, origin1, assoc2, arrival2
event1, origin2, assoc3, arrival3
event1, origin2, assoc4, arrival4
event2, origin3, assoc5, arrival5
...

Stamag rows always create QuakeML StationMagnitudes. Their same-row Netmag receives a StationMagnitudeContribution only when magdef == 'd'; it has weight=1.0 and maps magres to residual. magdef == 'n' creates no contribution. Any other value emits a warning and creates no contribution. When an Amplitude table is selected, Stamag links to its QuakeML Amplitude by ampid. Otherwise it falls back to the existing Arrival-derived amplitude link by arid.

Examples

>>> cat = catalog(event_query, resource_prefix='smi:lanl.gov', description='my catalog')
>>> cat = catalog(event_query, arrival_query)  # merged into one catalog