Utils

copyright:

Lion Krischer (lion.krischer@gmail.com), 2013-2021

license:

BSD 3-Clause (“BSD New” or “BSD Simplified”)

class pyasdf.utils.AuxiliaryDataAccessor(auxiliary_data_type, asdf_data_set)[source]

Helper class to access auxiliary data items.

class pyasdf.utils.AuxiliaryDataGroupAccessor(asdf_data_set)[source]

Helper class to facilitate access to the auxiliary data types.

class pyasdf.utils.FilteredWaveformAccessor(station_name, asdf_data_set, filtered_items)[source]

A version of the waveform accessor returning a limited number of waveforms.

list()[source]

Get a list of all data sets for this station.

class pyasdf.utils.JobQueueHelper(jobs, worker_names)[source]

A simple helper class managing job distribution to workers.

Init with a list of jobs and a list of workers.

Parameters:
  • jobs (List of arguments distributed to the jobs.) – A list of jobs that will be distributed to the workers.

  • workers – A list of usually integers, each denoting a worker.

Type:

list of integers

get_job_for_worker(worker_name)[source]

Get a job for a worker.

Parameters:

worker_name – The name of the worker requesting work.

poison_pill_received()[source]

Increment the point pills received counter.

received_job_from_worker(arguments, result, worker_name)[source]

Call when a worker returned a job.

Parameters:
  • arguments – The arguments the jobs was called with.

  • result – The result of the job

  • worker_name – The name of the worker.

class pyasdf.utils.ProvenanceAccessor(asdf_data_set)[source]

Accessor helper for the provenance records.

get_provenance_document_for_id(provenance_id)[source]

Get the provenance document containing a record with a certain id.

Parameters:

provenance_id – The id of the provenance record whose containing document is searched. Must be given as a qualified name, e.g. '{namespace_uri}id'.

list()[source]

Return a list of available provenance documents.

class pyasdf.utils.ReceivedMessage(data)

Create new instance of ReceivedMessage(data,)

data

Alias for field number 0

class pyasdf.utils.SimpleBuffer(limit=10)[source]

Object that can be used as a cache.

Will never contain more then the specified number of items. If more then then that are used, it will remove the item with the oldest last access time.

class pyasdf.utils.StationAccessor(asdf_data_set)[source]

Helper class to facilitate access to the waveforms and stations.

class pyasdf.utils.StreamBuffer[source]

Very simple key value store for obspy stream object with the additional ability to approximate the size of all stored stream objects.

get_size()[source]

Try to approximate the size of all stores Stream object.

keys() a set-like object providing a view on D's keys[source]
class pyasdf.utils.WaveformAccessor(station_name, asdf_data_set)[source]

Helper class facilitating access to the actual waveforms and stations.

property channel_coordinates

Get coordinates of the station at the channel level if any.

property coordinates

Get coordinates of the station if any.

get_waveform_attributes()[source]

Get a dictionary of the attributes of all waveform data sets.

This works purely on the meta data level and is thus fast. Event, origin, arrival, and focmec ids will be returned as lists as they can be set multiple times per data-set.

get_waveform_tags()[source]

Get all available waveform tags for this station.

list()[source]

Get a list of all data sets for this station.

class pyasdf.utils.Worker(active_jobs, completed_jobs_count)

Create new instance of Worker(active_jobs, completed_jobs_count)

active_jobs

Alias for field number 0

completed_jobs_count

Alias for field number 1

pyasdf.utils.get_all_ids_for_prov_document(document)[source]

Gets a all ids from a prov document as qualified names in the lxml style.

pyasdf.utils.is_list(obj)[source]

True if the returned object is an iterable but not a string.

Parameters:

obj – The object to test.

pyasdf.utils.is_mpi_env()[source]

Returns True if the current environment is an MPI environment.

pyasdf.utils.is_multiprocessing_problematic()[source]

Return True if multiprocessing is known to have issues on the given platform.

Mainly results from the fact that some BLAS/LAPACK implementations cannot deal with forked processing.

pyasdf.utils.label2string(labels)[source]

List of labels to a comma-saperated string.

pyasdf.utils.labelstring2list(labels)[source]

String to a list of labels.

pyasdf.utils.sizeof_fmt(num)[source]

Handy formatting for human readable filesize.

From http://stackoverflow.com/a/1094933/1657047

pyasdf.utils.split_qualified_name(name)[source]

Takes a qualified name and returns a tuple of namespace, localpart.

If namespace is not a valid URL, an error will be raised.

Parameters:

name – The qualified name.

pyasdf.utils.wf_name2seed_codes(tag)[source]

Converts an ASDF waveform name to the corresponding SEED identifiers.

>>> wf_name2seed_codes("BW.ALTM.00.EHE__2012-01-..__2012_01-...__synth")
("BW", "ALTM", "00", "EHE")
pyasdf.utils.wf_name2tag(tag)[source]

Extract the path from an ASDF waveform name.

>>> wf_name2seed_codes("BW.ALTM.00.EHE__2012-01-..__2012_01-...__synth")
"synth"