database

Classes for managing databases and simulating databases.

database.database_manager

Tools for managing a database of template information.

class rt_eqcorrscan.database.database_manager.TemplateBank(base_path='.', path_structure=None, name_structure=None, event_format='quakeml', event_ext='.xml', template_ext='.tgz', executor=None)[source]

A database manager for templates. Based on obsplus EventBank.

Parameters
  • base_path (Union[str, Path, EventBank]) – The path to the directory containing event files. If it does not exist an empty directory will be created.

  • path_structure (Optional[str]) – Define the directory structure used by the event bank. Characters are separated by /, regardless of operating system. The following words can be used in curly braces as data specific variables: year, month, day, julday, hour, minute, second, event_id, event_id_short. If no structure is provided it will be read from the index, if no index exists the default is {year}/{month}/{day}

  • name_structure (str) – The same as path structure but for the event, template and waveform file names. Supports the same variables and a slash cannot be used in a file name on most operating systems. The default extension (.xml, .tgz, .ms) will be added for events, templates and waveforms respectively. The default is {time}_{event_id_short}.

  • event_format – The anticipated format of the event files. Any format supported by the obspy.read_events function is permitted.

  • event_ext – The extension on the event files. Can be used to avoid parsing non-event files.

  • template_ext – The extension on the template files. Can be used to avoid parsing non-template files.

Notes

Supports parallel execution of most methods using concurrent.futures executors. Set the TemplateBank.executor attribute to your required executor.

get_templates(**kwargs)[source]

Get template waveforms from the database

Supports passing an concurrent.futures.Executor using the executor keyword argument for parallel reading.

{get_event_params}

Return type

Tribe

make_templates(catalog, stream=None, client=None, download_data_len=90, save_raw=True, update_index=True, rebuild=False, **kwargs)[source]

Make templates from data or client based on a given catalog.

Templates will be put in the database. Requires either a stream or a suitable client with a get_waveforms method.

Parameters
  • catalog (Catalog) – Catalog of events to generate templates from.

  • stream (Optional[Stream]) – Optional: Stream encompassing the events in the catalog

  • client – Optional: Client with at-least a get_waveforms method, ideally the client should make the data for the events in catalog available.

  • download_data_len (float) – If client is given this is the length of data to download. The raw continuous data will also be saved to disk to allow later processing if save_raw=True

  • save_raw (bool) – Whether to store raw data on disk as well - defaults to True.

  • update_index (bool) – Flag to indicate whether or not to update the event index after writing the new events.

  • rebuild (bool) – Flag to indicate whether templates already existing in the TemplateBank should be re-generated. True will overwrite existing templates.

  • kwargs – Keyword arguments supported by EQcorrscan’s Template.construct method. Requires at least: lowcut, highcut, samp_rate, filt_order, prepick, length, swin

Return type

Tribe of templates

put_templates(templates, update_index=True, write_events=True)[source]

Save templates to the database.

Parameters
  • templates (Union[list, Tribe]) – Templates to put into the database

  • update_index (bool) – Flag to indicate whether or not to update the event index after writing the new events.

  • write_events (bool) – Optionally write out the event file as well as the template.

Return type

None

rt_eqcorrscan.database.database_manager.check_tribe_quality(tribe, seed_ids=None, min_stations=None, lowcut=None, highcut=None, filt_order=None, samp_rate=None, process_len=None, *args, **kwargs)[source]

Check that templates in the tribe have channels all the same length.

Parameters
  • tribe (Tribe) – A Tribe to check the quality of.

  • seed_ids (Optional[set]) – seed-ids of channels to be included in the templates - if None, then all channels will be included

  • min_stations (Optional[int]) – Minimum number of stations for a template to be included.

  • lowcut (Optional[float]) – Desired template processing lowcut in Hz, if None, will not check

  • highcut (Optional[float]) – Desired template processing highcut in Hz, if None, will not check

  • filt_order (Optional[int]) – Desired template filter order, if None, will not check

  • samp_rate (Optional[float]) – Desired template sampling rate in Hz, if None, will not check

  • process_len (Optional[float]) – Desired template processing length in s, if None, will not check

Return type

A filtered tribe.

rt_eqcorrscan.database.database_manager.remove_unreferenced(catalog)[source]

Remove un-referenced arrivals, amplitudes and station_magnitudes.

Return type

Catalog


database.client_emulation

Utilities for emulating obspy clients using local data. Relies on obsplus

class rt_eqcorrscan.database.client_emulation.ClientBank(wave_bank=None, event_bank=None, station_bank=None)[source]

Thin routing wrapper for obsplus Banks to act as a client.

Parameters

Notes

All attributes can be substituted for different (or the same) client.

class rt_eqcorrscan.database.client_emulation.LocalClient(base_path, max_threads=None)[source]

Thin local waveform client.