obsplus.utils.events module

General utility functions which are not specific to one data type.

obsplus.utils.events.bump_creation_version(obj)[source]

Bump the version in an object’s CreationInfo and add creation time.

Take an obspy object and try to bump creation info. This is done by first creating info if obj.creation_info is None, then addition creation_time and bumping the version by one

obsplus.utils.events.duplicate_events(event, resource_generator=None)[source]

Duplicate an event.

Creates a copy of the event, and assigns new resource IDs to all internal objects (ie picks, station_magnitudes, etc.). Will not assign new resource_id to those representing external resources (eg analyst, velocity models, etc.).

Parameters:
  • event (TypeVar(catalog_or_event, Catalog, Event)) – The event to duplicate.

  • resource_generator (Optional[Callable]) – A callable that can be used to generate resource IDs.

Return type:

TypeVar(catalog_or_event, Catalog, Event)

obsplus.utils.events.get_event_client(events)[source]

Extract an event client from various inputs.

Parameters:

events (Union[Path, str, Catalog, Event, EventClient]) –

Any of the following:
  • A path to an obspy-readable event file

  • A path to a directory of obspy-readable event files

  • An obspy.Catalog instance

  • An instance of EventBank

  • Any other object that has a get_events method

Raises:

TypeError – If an event client cannot be determined from the input.

Return type:

EventClient

obsplus.utils.events.get_preferred(event, what, init_empty=False)[source]

get the preferred object (eg origin, magnitude) from the event.

If not defined use the last in the list. If list is empty init empty object.

Parameters:
  • event (obspy.core.event.Event) – The instance for which the preferred should be sought.

  • what (the preferred item to get) – Can either be “magnitude”, “origin”, or “focal_mechanism”.

  • init_empty – If True, rather than return None when no preferred object is found create an empty object of the appropriate class and return it.

obsplus.utils.events.get_seed_id(obj)[source]

Get the NSLC associated with an station-specific object.

Parameters:

obj (AttribDict) – The object for which to retrieve the seed id. Can be anything that has a waveform_id attribute or refers to an object with a waveform_id attribute.

Returns:

The seed_id in the form of “network.station.location.channel”

Return type:

str

obsplus.utils.events.make_origins(events, inventory, depth=1.0, phase_hints=('P', 'p'))[source]

Iterate a catalog or single events and ensure each has an origin.

If no origins are found for an event, create one with the time set to the earliest pick and the location set to the location of the first hit station. Events are modified in place.

This may be useful for location codes that need a starting location.

Parameters:
  • events (TypeVar(catalog_or_event, Catalog, Event)) – The events to scan and add origins were necessary.

  • inventory (Inventory) – An inventory object which contains all the stations referenced in quakeml elements of events.

  • depth (float) – The default depth for created origins. Should be in meters. See the obspy docs for Origin or the quakeml standard for more details.

  • phase_hints (Optional[Iterable]) – List of acceptable phase hints to use for identifying the earliest pick. By default will only search for “P” or “p” phase hints.

Return type:

Either a Catalog or Event object (same as input).

obsplus.utils.events.prune_events(events)[source]

Remove all the unreferenced rejected objects from an event or catalog.

This function first creates a copy of the event/catalog. Then it looks all objects with rejected evaluation status’, which are not referred to by any un-rejected object, and removes them.

Parameters:

events (TypeVar(catalog_or_event, Catalog, Event)) – The events to iterate and modify

Return type:

A Catalog with the pruned events.

obsplus.utils.events.strip_events(events, reject_evaluation_status='rejected')[source]

Removes all derivative data and rejected objects from an event or catalog

This is a nuclear option for when processing goes horribly wrong. It will only keep picks and amplitudes that are not rejected in addition to the first event description for the event.

Parameters:
  • events (TypeVar(catalog_or_event, Catalog, Event)) – The events to strip

  • reject_evaluation_status (Iterable) – Reject picks and amplitudes that have this as an evaluation status (accepts either a single value or a list)

Return type:

The stripped events