pyrocko.pile

Waveform archive lookup, data loading and caching infrastructure.

Note

This module has been superseded by squirrel but will remain available for backwards compatibility.

Functions

get_cache(cachedir)

Get global TracesFileCache object for given directory.

make_pile([paths, selector, regex, ...])

Create pile from given file and directory names.

Classes

Batch(tmin, tmax, i, n, traces)

Batch of waveforms from window wise data extraction.

MemTracesFile(parent, traces)

This is needed to make traces without an actual disc file to be inserted into a Pile.

Pile()

Waveform archive lookup, data loading and caching infrastructure.

TracesFileCache(cachedir)

Manages trace metainformation cache.

TracesGroup(parent)

Trace container base class.

class TracesFileCache(cachedir)[source]

Bases: object

Manages trace metainformation cache.

For each directory with files containing traces, one cache file is maintained to hold the trace metainformation of all files which are contained in the directory.

get(abspath)[source]

Try to get an item from the cache.

Parameters:

abspath – absolute path of the object to retrieve

Returns:

a stored object is returned or None if nothing could be found.

put(abspath, tfile)[source]

Put an item into the cache.

Parameters:
  • abspath – absolute path of the object to be stored

  • tfile – object to be stored

dump_modified()[source]

Save any modifications to disk.

clean()[source]

Weed out missing files from the disk caches.

get_cache(cachedir)[source]

Get global TracesFileCache object for given directory.

class TracesGroup(parent)[source]

Bases: object

Trace container base class.

Base class for Pile, SubPile, and TracesFile, i.e. anything containing a collection of several traces. A TracesGroup object maintains lookup sets of some of the traces meta-information, as well as a combined time-range of its contents.

add(content)[source]

Add content to traces group and update indices.

Accepts pyrocko.trace.Trace objects and pyrocko.pile.TracesGroup objects.

remove(content)[source]

Remove content to traces group and update indices.

relevant(tmin, tmax, group_selector=None, trace_selector=None)[source]

Return list of pyrocko.trace.Trace objects where given arguments tmin and tmax match.

Parameters:
  • tmin – start time

  • tmax – end time

  • group_selector – lambda expression taking group dict of regex match object as a single argument and which returns true or false to keep or reject a file (default: None)

  • trace_selector – lambda expression taking group dict of regex match object as a single argument and which returns true or false to keep or reject a file (default: None)

class MemTracesFile(parent, traces)[source]

Bases: TracesGroup

This is needed to make traces without an actual disc file to be inserted into a Pile.

class Batch(tmin, tmax, i, n, traces)[source]

Bases: object

Batch of waveforms from window wise data extraction.

Encapsulates state and results yielded for each window in window wise waveform extraction with the Pile.chopper() method (when the style=’batch’ keyword argument set).

Attributes:

tmin

Start of this time window.

tmax

End of this time window.

i

Index of this time window in sequence.

n

Total number of time windows in sequence.

traces

Extracted waveforms for this time window.

class Pile[source]

Bases: TracesGroup

Waveform archive lookup, data loading and caching infrastructure.

chopper(tmin=None, tmax=None, tinc=None, tpad=0.0, group_selector=None, trace_selector=None, want_incomplete=True, degap=True, maxgap=5, maxlap=None, keep_current_files_open=False, accessor_id=None, snap=(<built-in function round>, <built-in function round>), include_last=False, load_data=True, style=None)[source]

Get iterator for shifting window wise data extraction from waveform archive.

Parameters:
  • tmin – start time (default uses start time of available data)

  • tmax – end time (default uses end time of available data)

  • tinc – time increment (window shift time) (default uses tmax-tmin)

  • tpad – padding time appended on either side of the data windows (window overlap is 2*tpad)

  • group_selector – filter callback taking TracesGroup objects

  • trace_selector – filter callback taking pyrocko.trace.Trace objects

  • want_incomplete – if set to False, gappy/incomplete traces are discarded from the results

  • degap – whether to try to connect traces and to remove gaps and overlaps

  • maxgap – maximum gap size in samples which is filled with interpolated samples when degap is True

  • maxlap – maximum overlap size in samples which is removed when degap is True

  • keep_current_files_open – whether to keep cached trace data in memory after the iterator has ended

  • accessor_id – if given, used as a key to identify different points of extraction for the decision of when to release cached trace data (should be used when data is alternately extracted from more than one region / selection)

  • snap – replaces Python’s round() function which is used to determine indices where to start and end the trace data array

  • include_last – whether to include last sample

  • load_data – whether to load the waveform data. If set to False, traces with no data samples, but with correct meta-information are returned

  • style – set to 'batch' to yield waveforms and information about the chopper state as Batch objects. By default lists of pyrocko.trace.Trace objects are yielded.

Returns:

iterator providing extracted waveforms for each extracted window. See style argument for details.

all(*args, **kwargs)[source]

Shortcut to aggregate chopper() output into a single list.

iter_traces(load_data=False, return_abspath=False, group_selector=None, trace_selector=None)[source]

Iterate over all traces in pile.

Parameters:
  • load_data – whether to load the waveform data, by default empty traces are yielded

  • return_abspath – if True yield tuples containing absolute file path and pyrocko.trace.Trace objects

  • group_selector – filter callback taking TracesGroup objects

  • trace_selector – filter callback taking pyrocko.trace.Trace objects

Example; yields only traces, where the station code is ‘HH1’:

test_pile = pile.make_pile('/local/test_trace_directory')
for t in test_pile.iter_traces(
        trace_selector=lambda tr: tr.station=='HH1'):

    print t
snuffle(**kwargs)[source]

Visualize it.

Parameters:
  • stations – list of pyrocko.model.station.Station objects or None

  • events – list of pyrocko.model.event.Event objects or None

  • markers – list of pyrocko.gui.snuffler.marker.Marker objects or None

  • ntracks – float, number of tracks to be shown initially (default: 12)

  • follow – time interval (in seconds) for real time follow mode or None

  • controls – bool, whether to show the main controls (default: True)

  • opengl – bool, whether to use opengl (default: False)

make_pile(paths=None, selector=None, regex=None, fileformat='mseed', cachedirname=None, show_progress=True)[source]

Create pile from given file and directory names.

Parameters:
  • paths – filenames and/or directories to look for traces. If paths is None sys.argv[1:] is used.

  • selector – lambda expression taking group dict of regex match object as a single argument and which returns true or false to keep or reject a file

  • regex – regular expression which filenames have to match

  • fileformat – format of the files (‘mseed’, ‘sac’, ‘kan’, ‘from_extension’, ‘detect’)

  • cachedirname – loader cache is stored under this directory. It is created as neccessary.

  • show_progress – show progress bar and other progress information