reactor

Reactor module of RT_EQcorrscan

reactor.reactor

Overarching tool for listening to and triggering from FDSN earthquakes.

class rt_eqcorrscan.reactor.reactor.Reactor(client, listener, trigger_func, template_database, config, listener_starttime=None)[source]

A class to listen to a client and start-up a real-time instance.

The real-time instance will be triggered by the listener when set conditions are met. Appropriate templates will be extracted from the template database on disk and used as a Tribe for the real-time detection.

Once triggered, the listener will keep listening, but will not trigger in the same region again while the real-time detector is running. The real-time detector has to be stopped manually, or when rate or maximum-duration conditions are met.

Parameters
  • client – An obspy or obsplus client that supports event and station queries.

  • listener (_Listener) – Listener for checking current earthquake activity

  • trigger_func (Callable) – A function that returns a list of events that exceed some trigger parameters given a catalog. See note below.

  • template_database (TemplateBank) – A template database to be used to generate tribes for real-time matched-filter detection.

  • config (Config) – Configuration for RT-EQcorrscan.

Notes

trigger_func must only take one argument, a catalog of events. To achieve this you should generate a partial function from your trigger function. For example, using the provided rate-and-magnitude triggering function:

>>> from rt_eqcorrscan.event_trigger import magnitude_rate_trigger_func
>>> from functools import partial
>>> trigger_func = partial(
...     magnitude_rate_trigger_func, magnitude_threshold=4,
...     rate_threshold=20, rate_bin=0.5)
check_running_tribes()[source]

Check on the state of running tribes.

Because this process starts subprocesses, they need to be stopped by this process if they “complete”. This is recorded by the real-time-tribe by writing a .stopfile

Return type

None

process_new_events(new_events)[source]

Process any new events in the system.

Check if new events should be in one of the already running tribes and add them. Check all other events for possible triggers and spin-up a detector instance for triggers.

Parameters

new_events (Union[Catalog, List[Event]]) – Catalog of new-events to be assessed.

Return type

None

run(max_run_length=None)[source]

Run all the processes.

Parameters

max_run_length (Optional[float]) – Maximum run length in seconds, if None, will run indefinitely.

Return type

None

spin_up(triggering_event)[source]

Run the reactors response function as a subprocess.

Parameters

triggering_event (Event) – Event that triggered this run - needs to have at-least an origin.

Return type

None

stop(raise_exit=True)[source]

Stop all the processes.

Parameters

raise_exit (bool) – Whether to exit the Python system or not.

Return type

None

stop_tribe(triggering_event_id=None)[source]

Stop a specific tribe.

Parameters

triggering_event_id (Optional[str]) – The id of the triggering event for which a tribe is running.

Return type

None

rt_eqcorrscan.reactor.reactor.estimate_region(event, min_length=50.0, scaling_relation='default', multiplier=1.25)[source]

Estimate the region to find templates within given a triggering event.

Parameters
  • event (Event) – The event that triggered this function

  • min_length (float) – Minimum length in km for diameter of event circle around the triggering event

  • scaling_relation (Union[str, Callable]) – Name of registered scaling-relationship or Callable that takes only the earthquake magnitude as an argument and returns length in km

  • multiplier (float) – Fudge factor to scale the scaling relation up by a constant.

Return type

Dictionary keyed by “latitude”, “longitude” and “maxradius”

Notes

The scaling_relation * multiplier defines the maxradius of the region

reactor.spin_up

Functions for spinning up and running a real-time tribe based on trigger-events

rt_eqcorrscan.reactor.spin_up.get_inventory(client, tribe, triggering_event=None, location=None, starttime=None, max_distance=1000.0, n_stations=10, duration=10, level='channel', channel_list=('EH?', 'HH?'))[source]

Get a suitable inventory for a tribe - selects the most used, closest stations.

Parameters
  • client – Obspy client with a get_stations service.

  • tribe (Union[RealTimeTribe, Tribe]) – Tribe or RealTimeTribe of templates to query for stations.

  • triggering_event (Optional[Event]) – Event with at least an origin to calculate distances from - if not specified will use location

  • location (Optional[dict]) – Dictionary with “latitude” and “longitude” keys - only used if triggering event is not specified.

  • starttime (Optional[UTCDateTime]) – Start-time for station search - only used if triggering_event is not specified.

  • max_distance (float) – Maximum distance from triggering_event.preferred_origin or location to find stations. Units: km

  • n_stations (int) – Maximum number of stations to return

  • duration (float) – Duration stations must be active for. Units: days

  • level (str) – Level for inventory parsable by client.get_stations.

  • channel_list (Union[list, tuple]) – List of channel-codes to be acquired. If None then all channels will be searched.

Return type

Inventory of the most used, closest stations.