pyrocko.squirrel.client.fdsn¶
Squirrel client to access FDSN web services for seismic waveforms and metadata.
Functions
|
Convert codes patterns and a time span to an FDSN-style selection. |
|
Merge adjacent NSLC-plus-time-span entries into contiguous ones. |
|
Check if two files differ in size or content. |
|
Create progress indicator task (see |
|
Replace a file with a freshly downloaded temporary one, unless their contents are identical. |
|
Get sort key for a |
|
Convert waveform orders to an FDSN dataselect-style selection. |
Classes
|
Summary of several |
|
Single waveform download error occurrence. |
|
Log of waveform download errors encountered by |
|
Squirrel data-source to transparently get data from FDSN web services. |
Exceptions
Raised internally to abort an in-progress waveform download, e.g. when unexpectedly much data is being received. |
- make_task(*args)[source]¶
Create progress indicator task (see
pyrocko.progress), logging to this module’s logger.
- move_or_keep(fn_temp, fn)[source]¶
Replace a file with a freshly downloaded temporary one, unless their contents are identical.
- combine_selections(selection)[source]¶
Merge adjacent NSLC-plus-time-span entries into contiguous ones.
- orders_sort_key(order)[source]¶
Get sort key for a
WaveformOrder, for sorting by codes, then start time.
- orders_to_selection(orders, pad=1.0)[source]¶
Convert waveform orders to an FDSN dataselect-style selection.
- Parameters:
orders (iterable of
WaveformOrderobjects) – Orders to be converted.pad (float) – Number of samples of padding to add at each end of the requested time spans.
- Returns:
Combined (see
combine_selections()), padded selection entries of the form(net, sta, loc, cha, tmin, tmax).- Return type:
- codes_to_selection(codes_list, tmin, tmax)[source]¶
Convert codes patterns and a time span to an FDSN-style selection.
- Parameters:
codes_list (
listofCodesNSLCEobjects, orNone) – Codes patterns to be converted, orNone.tmin (
get_time_float()) – Start time to be used for all entries.tmax (
get_time_float()) – End time to be used for all entries.
- Returns:
Selection entries of the form
(net, sta, loc, cha, tmin, tmax), orNoneifcodes_listisNone.- Return type:
- class ErrorEntry(**kwargs)[source]¶
Bases:
ObjectSingle waveform download error occurrence.
- ♦ time¶
pyrocko.util.get_time_float (
pyrocko.guts.Timestamp)Time at which the error occurred.
- ♦ order¶
pyrocko.squirrel.model.WaveformOrderWaveform order which caused the error.
- ♦ kind¶
strError category, e.g.
'empty result','invalid waveform','http error','aborted'or'partial result'.
- ♦ details¶
str, optionalAdditional free-form details about the error.
- class ErrorAggregate(**kwargs)[source]¶
Bases:
ObjectSummary of several
ErrorEntryoccurrences sharing the samekind/details, seeErrorLog.iter_aggregates().- ♦ site¶
strFDSN site url or alias name the errors occurred at.
- ♦ kind¶
strCommon error category of the aggregated entries, see
ErrorEntry.kind.
- ♦ details¶
strCommon details of the aggregated entries, see
ErrorEntry.details.
- ♦ entries¶
listofErrorEntryobjects, default:[]Aggregated error entries.
- ♦ codes¶
listofpyrocko.model.codes.CodesNSLCEobjects, default:[]Channel codes affected by the aggregated errors.
- ♦ time_spans¶
listoftupleof 2 pyrocko.util.get_time_float (pyrocko.guts.Timestamp) objects objects, default:[]Distinct
(tmin, tmax)time spans affected by the aggregated errors.
- class ErrorLog(**kwargs)[source]¶
Bases:
ObjectLog of waveform download errors encountered by
FDSNSource.- ♦ site¶
strFDSN site url or alias name the errors occurred at.
- ♦ entries¶
listofErrorEntryobjects, default:[]Logged error entries, in chronological order.
- ♦ checkpoints¶
listofintobjects, default:[]Entry-count marks recorded by
append_checkpoint(), used to delimit “recent” entries forsummarize_recent().
- append_checkpoint()[source]¶
Mark current end of log, for later use by
summarize_recent().
- append(time, order, kind, details='')[source]¶
Append an error entry to the log.
- Parameters:
time (
get_time_float()) – Time at which the error occurred.order (
WaveformOrder) – Waveform order which caused the error.kind (str) – Error category, see
ErrorEntry.kind.details (str) – Additional free-form details about the error.
- iter_aggregates()[source]¶
Iterate over
ErrorAggregatesummaries, grouping logged entries by(kind, details).- Yields:
ErrorAggregateobjects.
- summarize_recent()[source]¶
Get one-line summary of errors logged since the last checkpoint (see
append_checkpoint()), or of all entries if no checkpoint was set.- Return type:
- exception Aborted[source]¶
Bases:
SquirrelErrorRaised internally to abort an in-progress waveform download, e.g. when unexpectedly much data is being received.
- class FDSNSource(site, query_args=None, codes=None, **kwargs)[source]¶
Bases:
SourceSquirrel data-source to transparently get data from FDSN web services.
Attaching an
FDSNSourceobject to aSquirrelallows the latter to download station and waveform data from an FDSN web service should the data not already happen to be available locally.- ♦ site¶
strFDSN site url or alias name (see
pyrocko.client.fdsn).
- ♦ query_args¶
dictofstrobjects, optionalCommon query arguments, which are appended to all queries.
- ♦ codes¶
listofpyrocko.model.codes.CodesNSLCEobjects, optionalList of codes patterns to query via POST parameters.
- ♦ expires¶
float(pyrocko.guts.Duration), optionalExpiration time [s]. Information older than this will be refreshed. This only applies to station-metadata. Waveforms do not expire. If set to
Noneneither type of data expires.
- ♦ anxious¶
float(pyrocko.guts.Duration), default:600.0Anxiety period [s]. Missing waveforms will not be treated as permanently missing for orders spanning into times later than (current time - anxious). Default: 600.
- ♦ cache_path¶
str(pyrocko.has_paths.Path), optionalDirectory path where any downloaded waveforms and station meta-data are to be kept. By default the Squirrel environment’s cache directory is used.
bool, default:FalseIf
True, waveforms are shared with other FDSN sources in the same Squirrel environment. IfFalse, they are kept separate.
- ♦ storage_path¶
str(pyrocko.has_paths.Path), optionalIf set, manage waveforms in the given directory rather than in the Squirrel cache.
- ♦ storage_scheme¶
str(pyrocko.squirrel.storage.StorageSchemeChoice), default:'default'Set layout of waveform storage. Available:
'default','rug-store-10','rug-store-100','rug-store-1000','sds'. Default:'default'.
- ♦ user_credentials¶
tupleof 2strobjects, optionalUser and password for FDSN servers requiring password authentication
- ♦ auth_token¶
str, optionalAuthentication token to be presented to the FDSN server.
- ♦ auth_token_path¶
str(pyrocko.has_paths.Path), optionalPath to file containing the authentication token to be presented to the FDSN server.
- ♦ hotfix_module_path¶
str(pyrocko.has_paths.Path), optionalPath to Python module to locally patch metadata errors.
- make_hash()[source]¶
Compute hash identifying this source’s configuration.
Used to distinguish between differently-configured
FDSNSourceinstances pointing at the samesitewhen choosing on-disk cache locations, so e.g. anonymous and authenticated access to the same site are cached separately.- Return type:
- get_hash()[source]¶
Get hash identifying this source’s configuration (see
make_hash()).- Return type:
- get_auth_token()[source]¶
Get authentication token, reading it from
auth_token_pathifauth_tokenis not set directly.- Return type:
- Raises:
FileLoadError – If
auth_token_pathcannot be read.
- setup(squirrel, check=True, upgrade=False)[source]¶
Set up cache directories and add already-downloaded local content (waveforms, channel and response meta-data) to the squirrel.
See
setup()for the parameters. IfupgradeisTrue, any waveform archive found using the old (pre-v2) on-disk storage layout is migrated in place; otherwise it is added as-is and a warning is logged.
- update_channel_inventory(squirrel, constraint=None)[source]¶
Query and cache channel/station meta-data for a given constraint, unless already cached and not yet expired (see
expires).- Parameters:
squirrel (
Squirrel) – Squirrel instance the source is attached to.constraint (
Constraint) – Selection of times or areas to be brought up to date. If not given, an unconstrained (global) query is made.
- update_waveform_promises(squirrel, constraint)[source]¶
Add waveform promises for channels with cached meta-data but missing (or gappy) local waveform coverage, for a given constraint.
- Parameters:
squirrel (
Squirrel) – Squirrel instance the source is attached to.constraint (
Constraint) – Selection of times or areas to promise waveforms for.
- remove_waveform_promises(squirrel, from_database='selection')[source]¶
Remove waveform promises from live selection or global database.
- Parameters:
from_database – Remove from live selection
'selection'or global database'global'.
- download_waveforms(orders, success, error_permanent, error_temporary, aborted)[source]¶
Execute a batch of waveform download orders.
- Parameters:
orders (
listofWaveformOrderobjects) – Waveform orders to be downloaded.success (callable) – Callback
success(order, traces), called for each successfully (or partially) downloaded order.error_permanent (callable) – Callback
error_permanent(order), called for orders which failed in a way not expected to be resolved by retrying later.error_temporary (callable) – Callback
error_temporary(order), called for near-real-time orders (seeis_near_real_time()) which failed but may succeed if retried later.aborted (callable) – Callback
aborted(), returningTrueif downloading should be aborted before processing further orders.
Downloaded waveforms are not saved automatically;
successis expected to do so, e.g. viasave_waveforms(). Download errors are logged to an internalErrorLog, aggregated summaries of which are logged as warnings.
- update_response_inventory(squirrel, constraint)[source]¶
Query and cache instrument responses for channels matching a given constraint’s codes, unless already cached and not yet expired (see
expires).- Parameters:
squirrel (
Squirrel) – Squirrel instance the source is attached to.constraint (
Constraint) – Selection of codes to update responses for. Onlycodesis used; responses are queried for the channels’ entire available time span.