obspy_compat

This module provides basic compatibility between ObsPy and Pyrocko.

The functions defined here can be used to translate back and forth some of the basic objects in Pyrocko and ObsPy. It also provides shortcuts to quickly look at ObsPy waveforms with the Pyrocko’s Snuffler application (snuffle(), fiddle()).

With pyrocko.obspy_compat.plant() several new methods are attached to Pyrocko and ObsPy classes.

Example, visualize ObsPy stream object with Snuffler:

import obspy
from pyrocko import obspy_compat
obspy_compat.plant()

stream = obspy.read()  # returns some example data
stream.snuffle()

With best wishes to the ObsPy Team from the Pyrocko Developers!

Note

This is an experimental module, the interface may still be changed. Feedback and discussion welcome!

to_pyrocko_trace(trace)[source]

Convert ObsPy trace object to Pyrocko trace object.

Parameters:traceobspy.Trace object
Returns:pyrocko.trace.Trace object
to_pyrocko_traces(stream)[source]

Convert ObsPy stream object to list of Pyrocko trace objects.

Parameters:streamobspy.Stream object
Returns:list of pyrocko.trace.Trace objects
to_pyrocko_events(catalog)[source]

Convert ObsPy catalog object to list of Pyrocko event objects.

Parameters:catalogobspy.Catalog object
Returns:list of pyrocko.model.Event objects or None if catalog is None
to_pyrocko_stations(inventory)[source]

Convert ObsPy inventory to list of Pyrocko traces.

Parameters:inventoryobspy.Inventory object
Returns:list of pyrocko.model.Station objects or None if inventory is None
to_obspy_stream(pile)[source]

Convert Pyrocko pile to ObsPy stream.

Parameters:pilepyrocko.pile.Pile object
Returns:obspy.Stream object
to_obspy_trace(trace)[source]

Convert Pyrocko trace to ObsPy trace.

Parameters:tracepyrocko.trace.Trace
snuffle(stream_or_trace, inventory=None, catalog=None, **kwargs)[source]

Explore ObsPy data with Snuffler.

Parameters:
Returns:

(return_tag, markers), where return_tag is the a string to flag how the Snuffler window has been closed and markers is a list of pyrocko.gui.marker.Marker objects.

This function displays an ObsPy stream object in Snuffler. It returns to the caller once the window has been closed. The return_tag returned by the function can be used as a primitive way to communicate a user decision to the calling script. By default it returns the key pressed to close the window (if any), either 'q' or 'x', but the value could be customized when the exit is triggered from within a Snuffling.

See also fiddle() for a variant of this function returning an interactively modified ObsPy stream object.

fiddle(stream_or_trace, inventory=None, catalog=None, **kwargs)[source]

Manipulate ObsPy stream object interactively.

Parameters:
Returns:

obspy.Stream object with changes applied interactively (or obspy.Trace if called with a trace as first argument).

This function displays an ObsPy stream object in Snuffler like snuffle(), but additionally adds a Snuffling panel to apply some basic ObsPy signal processing to the contained traces. The applied changes are handed back to the caller as a modified copy of the stream object.

import obspy
from pyrocko import obspy_compat

obspy_compat.plant()

stream = obspy.read()
stream_filtered = stream.fiddle()  # returns once window has been
                                   # closed
plant()[source]

Add conversion functions as methods to ObsPy and Pyrocko classes.

Methods added to ObsPy classes are:

class methods
obspy.Trace to_pyrocko_trace()
snuffle()
fiddle()
obspy.Stream to_pyrocko_traces()
snuffle()
fiddle()
obspy.Catalog to_pyrocko_events()
obspy.Inventory to_pyrocko_stations()

Methods added to Pyrocko classes are:

class methods
pyrocko.trace.Trace to_obspy_trace()
pyrocko.pile.Pile to_obspy_stream()