Mondaic
This API reference is not for the latest stable Salvus version.

salvus.flow.collections.event_data

The EventData object which is an Event object with waveform data and/or other types of attached data.

Functions

plot_event_data_gathers()

def plot_event_data_gathers(
    event_data_objects: typing.List[EventData],
    receiver_field: str,
    component: str,
    event_data_labels: typing.Optional[
        typing.Union[str, typing.List[str]]
    ] = None,
    sort_by: typing.Optional[typing.Callable] = None,
    filter_by: typing.Optional[typing.Callable[[_Base], bool]] = None,
    select_by: typing.Optional[
        typing.Callable[
            [typing.List[typing.Tuple[_Base, obspy.Stream]], EventData],
            typing.List[typing.Tuple[_Base, obspy.Stream]],
        ]
    ] = None,
    interleave: bool = False,
    colors: typing.Optional[typing.List[typing.Any]] = None,
    alpha: typing.Optional[float] = None,
    plot_using: PlotProperties
    | matplotlib.axes.Axes = PlotProperties(width=11.5, height=6.33, dpi=100),
) -> matplotlib.axes.Axes:
    ...

Plot a custom gather using a list of event_data objects.

Parameters
  • event_data_objects typing.List[EventData] — A list of the event data objects to use.
  • receiver_field str — The receiver field to plot.
  • component str — The component to plot.
  • event_data_labels typing.Optional[typing.Union[str, typing.List[str]]] — Data name or list of data names to plot. This variable will simply be used for the labelling of the data in the event_data_objects list. If not specified, names will be generated from the event_data_objects list.
  • sort_by typing.Optional[typing.Callable] — Callback function called with the receiver objects to determine the sorting. Works like the key callback for the standard Python sorted() method.
  • filter_by typing.Optional[typing.Callable[[_Base], bool]] — Callback function called with the receiver objects in internal Salvus format to determine the filtering. Works like the callback for the standard Python filter() method. For complex filter operations requiring all receivers, defer to the select_by method.
  • select_by typing.Optional[typing.Callable[[typing.List[typing.Tuple[_Base, obspy.Stream]], EventData], typing.List[typing.Tuple[_Base, obspy.Stream]]]] — Callback function called with a list of tuples in the receiver objects in both internal Salvus and ObsPy Stream format, as well as the EventData objects.
  • interleave bool — Whether or not to alternatingly plot data. If false, traces from all data will be plotted on top of each other.
  • colors typing.Optional[typing.List[typing.Any]] — The colors for the individual traces. Must be exactly as many colors as data items. If not given, it will attempt to choose suitable colors.
  • alpha typing.Optional[float] — The opacity of all data, as used in Matplotlib. useful when setting interleave to false.
  • plot_using PlotProperties | matplotlib.axes.Axes — The configuration of the axis to create or reuse. Will default to the standard size as defined in the PlotProperties dataclass.
Returns matplotlib.axes.Axes

Classes

EventData

class EventData(salvus.flow.collections.event.Event):
    def __init__(
        self,
        event: Event,
        data: typing.Union[pathlib.Path, typing.Dict, xr.Dataset],
        data_hash: typing.Optional[str] = None,
        path_to_meta_json: typing.Optional[pathlib.Path] = None,
        path_to_job_info_json: typing.Optional[pathlib.Path] = None,
    ):
        ...

An event object that also contains waveform data.

Parameters
  • event Event — The event object.
  • data typing.Union[pathlib.Path, typing.Dict, xr.Dataset] — Path to the actual waveform data or a dictionary describing the data.
  • data_hash typing.Optional[str] — Uniquely identifying hash of that pieces of data. Might not always be available.
  • path_to_meta_json typing.Optional[pathlib.Path] — Optionally specify the meta.json path of the run. Necessary if you later want to compute adjoint sources.
  • path_to_job_info_json typing.Optional[pathlib.Path] — Optionally specify the job_info.json path of the run.
Attributes
data _Backends

Access the actual data via a proxy that abstracts different file formats.

file_format str

Returns the file format, either "hdf5", "xarray", or "asdf".

is_synthetic bool

Is the data from a Salvus simulation?

job_info_json_contents typing.Optional[typing.Dict]

Contents of the job_info.json file.

meta_json_contents typing.Optional[typing.Dict]

Contents of the meta.json file.

receiver_channels List[salvus.flow.collections.receiver_channel.ReceiverChannel]

The receiver channels for this event.

receiver_name_list List[str]

Return a list of receiver names for this event.

receivers List[salvus.flow.simple_config.receiver._Base]

The receivers for this event.

sources List[salvus.flow.simple_config.source._Base]

The sources for this event.

Methods
from_output_folder()
def from_output_folder(output_folder: pathlib.Path) -> "EventData":
    ...

Construct an EventData object from a folder containing Salvus outputs.

Parameters
  • output_folder pathlib.Path — Folder where the output files are stored.
Returns 'EventData'
_get_data_cube()
def _get_data_cube(
    self,
    receiver_field: str,
    component: typing.Union[str, int],
    sort_by: typing.Optional[typing.Callable[[_Base], int]] = None,
    filter_by: typing.Optional[typing.Callable[[_Base], bool]] = None,
    select_by: typing.Optional[
        typing.Callable[
            [typing.List[typing.Tuple[_Base, obspy.Stream]], EventData],
            typing.List[typing.Tuple[_Base, obspy.Stream]],
        ]
    ] = None,
) -> typing.Tuple[np.ndarray, np.ndarray]:
    ...

Get a data cube for a given field and component. Useful for plotting shotgathers and wiggle plots.

Returns a 2-D array with dimensions of (number of receivers, npts). Sorting, filtering, and composed operations are available through sort_by(), filter_by() and select_by(). In absence of these, receivers will be sorted as in the event object, unless sort_by or select_by are altering the sort order.

Parameters
  • receiver_field str — Receiver field to retrieve.
  • component typing.Union[str, int] — The component to retrieve.
  • sort_by typing.Optional[typing.Callable[[_Base], int]] — Callback function called with the receiver objects to determine the sorting. Works like the key callback for the standard Python sorted() method.
  • filter_by typing.Optional[typing.Callable[[_Base], bool]] — Callback function called with the receiver objects in internal Salvus format to determine the filtering. Works like the callback for the standard Python filter() method. For complex filter operations requiring all receivers, defer to the select_by method.
  • select_by typing.Optional[typing.Callable[[typing.List[typing.Tuple[_Base, obspy.Stream]], EventData], typing.List[typing.Tuple[_Base, obspy.Stream]]]] — Callback function called with a list of tuples in the receiver objects in both internal Salvus and ObsPy Stream format, as well as the EventData object.
Returns typing.Tuple[np.ndarray, np.ndarray]
compute_data_hash()
def compute_data_hash(self) -> str:
    ...

Compute a unique hash for the event data.

Returns str
delete_associated_job_and_data()
def delete_associated_job_and_data(self) -> None:
    ...

Delete the associated Salvus job, if it still exists, and any potentially existing remote outputs.

Returns None
download_extra_outputs()
def download_extra_outputs(
    self,
    data_types_to_download: typing.Union[
        typing.Collection[typing_extensions.Literal[("volume", "surface")]],
        typing_extensions.Literal[("volume", "surface")],
    ] = {"volume", "surface"},
    localpath: typing.Optional[typing.Union[str, pathlib.Path]] = None,
) -> None:
    ...

Download extra outputs from the simulation if they don’t locally exist yet.

Parameters
  • data_types_to_download typing.Union[typing.Collection[typing_extensions.Literal[('volume', 'surface')]], typing_extensions.Literal[('volume', 'surface')]] — The data types to download. Defaults to downloading everything.
  • localpath typing.Optional[typing.Union[str, pathlib.Path]] — By default, downloads will be stored next to the meta.json of the EventData object. If this is set to a folder (that must exist) it will instead download to that folder and only put symlinks in the meta.json file’s folder.
Returns None
expected_components_from_receiver()
def expected_components_from_receiver(
    receiver: Union[salvus.flow.simple_config.receiver._Base, Dict],
    receiver_field: str,
) -> List[str]:
    ...

Get the expected components from a receiver object and field name.

Parameters
  • receiver Union[salvus.flow.simple_config.receiver._Base, Dict] — The receiver object or dictionary representation.
  • receiver_field str — The receiver field.
Returns List[str]
get_associated_salvus_job()
def get_associated_salvus_job(self) -> "SalvusJob":
    ...

Get the associated Salvus job, if it still exists.

Returns 'SalvusJob'
get_data_cube()
def get_data_cube(
    self,
    receiver_field: str,
    component: typing.Union[str, int],
    sort_by: typing.Optional[typing.Callable[[_Base], int]] = None,
    filter_by: typing.Optional[typing.Callable[[_Base], bool]] = None,
    select_by: typing.Optional[
        typing.Callable[
            [typing.List[typing.Tuple[_Base, obspy.Stream]], EventData],
            typing.List[typing.Tuple[_Base, obspy.Stream]],
        ]
    ] = None,
) -> typing.Tuple[np.ndarray, np.ndarray]:
    ...

Get a data cube for a given field and component. Useful for plotting shotgathers and wiggle plots.

Returns a 2-D array with dimensions of (number of receivers, npts). Sorting, filtering, and composed operations are available through sort_by(), filter_by() and select_by(). In absence of these, receivers will be sorted as in the event object, unless sort_by or select_by are altering the sort order.

Parameters
  • receiver_field str — Receiver field to retrieve.
  • component typing.Union[str, int] — The component to retrieve.
  • sort_by typing.Optional[typing.Callable[[_Base], int]] — Callback function called with the receiver objects to determine the sorting. Works like the key callback for the standard Python sorted() method.
  • filter_by typing.Optional[typing.Callable[[_Base], bool]] — Callback function called with the receiver objects in internal Salvus format to determine the filtering. Works like the callback for the standard Python filter() method. For complex filter operations requiring all receivers, defer to the select_by method.
  • select_by typing.Optional[typing.Callable[[typing.List[typing.Tuple[_Base, obspy.Stream]], EventData], typing.List[typing.Tuple[_Base, obspy.Stream]]]] — Callback function called with a list of tuples in the receiver objects in both internal Salvus and ObsPy Stream format, as well as the EventData object.
Returns typing.Tuple[np.ndarray, np.ndarray]
get_receiver()
def get_receiver(
    self, receiver_name: str
) -> salvus.flow.simple_config.receiver._Base:
    ...

Returns a receiver object by name.

The receiver name should be NET.STA.LOC - if LOC is omitted it will be assumed to be an empty string.

Parameters
  • receiver_name str — The name of the receiver.
Returns salvus.flow.simple_config.receiver._Base
get_receiver_data()
def get_receiver_data(
    self,
    receiver_name: str,
    receiver_field: str,
    header: typing.Optional[typing.Any] = None,
    _ignore_temporal_weights: bool = False,
) -> obspy.Stream:
    ...

Get the waveform data for a given receiver and field in a consistent manner.

This is the central waveform retrieval function in SalvusProject and thus will return fully usable waveforms - this means fully filtered and selected/windowed waveforms, if so requested.

Might contain multiple traces per component, but only for data with a data selection configuration.

The order of the traces is always in the order of the expected output components.

It uses ObsPy’s Stream/Trace classes as they are just very suitable containers for waveform data.

Parameters
  • receiver_name str — The name of the receiver
  • receiver_field str — The field to get.
  • header typing.Optional[typing.Any] — Manually set the tr.stats.header to that value. Sometimes useful to have access to extra meta data in the processing and data selection functions.
  • _ignore_temporal_weights bool — Ignore temporal weights, even if they are set. Useful mainly for plotting and debugging purposes. Don’t set this if you are not aware of the consequences.
Returns obspy.Stream
get_remote_extra_output_filenames()
def get_remote_extra_output_filenames(
    self,
) -> typing.Dict[typing.Tuple[str, ...], pathlib.Path]:
    ...

Get a dictionary of the remote paths of extra output files.

These files might no longer exist and might already have been transferred to the local site or deleted. These are the paths of the extra output files of the solver.

Returns typing.Dict[typing.Tuple[str, ...], pathlib.Path]
get_time_axis_from_meta_json()
def get_time_axis_from_meta_json(self) -> TimeAxis:
    ...

Return the start time, end time, sampling rate and number of samples by parsing the meta.json file.

Naturally only works for synthetic data.

Returns TimeAxis
get_wavefield_output()
def get_wavefield_output(
    self,
    output_type: typing_extensions.Literal[("volume", "surface")],
    field: str,
    time_steps: slice = slice(None, None, None),
    download_if_not_exists: bool = False,
    delete_remote_data_after_download: bool = False,
) -> "salvus.toolbox.helpers.wavefield_output.WavefieldOutput":
    ...

Get a surface or volume wavefield output object for the given simulation.

This will read the full volume or surface output to memory so please use this with caution.

Parameters
  • output_type typing_extensions.Literal[('volume', 'surface')] — The output type to get, "surface" or "volume".
  • field str — The field to get.
  • time_steps slice — The time step indices to read expressed as a Python slice object.
  • download_if_not_exists bool — The data might not yet exist locally and only on a remote Salvus site. If that is the case, try to automatically download it. It will be stored in the same folder as the meta.json file for the simulation.
  • delete_remote_data_after_download bool — Delete the remote data and associated Salvus job after the download has succeeded. If set, this will delete all remote files for the current event, even if only a subset has been downloaded.
Returns 'salvus.toolbox.helpers.wavefield_output.WavefieldOutput'
get_waveform_data()
def get_waveform_data(
    self,
    receiver_name: str,
    receiver_field: str,
    header: typing.Optional[typing.Any] = None,
    _ignore_temporal_weights: bool = False,
) -> obspy.Stream:
    ...

Get the waveform data for a given receiver and field in a consistent manner. The receiver name can also correspond to a receiver channel.

This is the central waveform retrieval function in SalvusProject and thus will return fully usable waveforms - this means fully filtered and selected/windowed waveforms, if so requested.

Might contain multiple traces per component, but only for data with a data selection configuration.

The order of the traces is always in the order of the expected output components.

It uses ObsPy’s Stream/Trace classes as they are just very suitable containers for waveform data.

Parameters
  • receiver_name str — The name of the receiver or receiver channel
  • receiver_field str — The field to get.
  • header typing.Optional[typing.Any] — Manually set the tr.stats.header to that value. Sometimes useful to have access to extra meta data in the processing and data selection functions.
  • _ignore_temporal_weights bool — Ignore temporal weights, even if they are set. Useful mainly for plotting and debugging purposes. Don’t set this if you are not aware of the consequences.
Returns obspy.Stream
get_waveform_data_for_receiver_channel()
def get_waveform_data_for_receiver_channel(
    self,
    identifier: str,
    receiver_field: str,
    header: typing.Optional[typing.Any] = None,
    _ignore_temporal_weights: bool = False,
) -> obspy.Stream:
    ...

Get waveform data for a specific receiver channel.

Automatically sums up the signals of the individual channels and optionally time-shifts receivers before summation.

Parameters
  • identifier str — The name/identifier of the receiver channel.
  • receiver_field str — The field to get.
  • header typing.Optional[typing.Any] — Manually set the tr.stats.header to that value. Sometimes useful to have access to extra meta data in the processing and data selection functions.
  • _ignore_temporal_weights bool — Ignore temporal weights, even if they are set. Useful mainly for plotting and debugging purposes. Don’t set this if you are not aware of the consequences.
Returns obspy.Stream — st: Obspy stream containing the receiver channel data.
has_receiver()
def has_receiver(self, receiver_name: str) -> bool:
    ...

Figure out if the given receiver is available.

Parameters
  • receiver_name str — Name of the receiver.
Returns bool
has_receiver_nsl()
def has_receiver_nsl(
    self, network_code: str, station_code: str, location_code: str
) -> bool:
    ...

Figure out if the given receiver is available.

Parameters
  • network_code str — The network code.
  • station_code str — The station code.
  • location_code str — The location code.
Returns bool
plot()
def plot(
    self,
    plot_types: typing.Iterable[str] = ("wiggles",),
    receiver_field: str,
    component: str,
    sort_by: typing.Optional[typing.Callable] = None,
) -> None:
    ...

Plot the waveforms.

Parameters
  • plot_types typing.Iterable[str] — How to plot the data.
  • receiver_field str — The receiver field to plot.
  • component str — The component to plot.
  • sort_by typing.Optional[typing.Callable] — Callback function called with the receiver objects to determine the sorting. Works like the key callback for the standard Python sorted() method.
Returns None
register_processing_function()
def register_processing_function(
    self,
    function: typing.Optional[typing.Callable],
    chain_to_existing_function: bool = False,
) -> None:
    ...

Register a function to process data on the fly.

The function must take the following arguments:

  • st: An obspy.Stream object with the data.
  • receiver: The receiver object for the receiver.
  • sources: All sources for the event.

In the case of ASDF data it can also optionally take:

  • inv: An obspy.Inventory object for the station in case it is stored in an ASDF file. Might be None.

The function must return the processed obspy.Stream object which must contain exactly the same number of traces.

Parameters
  • function typing.Optional[typing.Callable] — Function to process data on the fly. Or None to unset it.
  • chain_to_existing_function bool — If True the new function will be chained to a possibly already pre-existing processing function. If this is False and there is an already pre-existing function it will raise.
Returns None
register_temporal_weights_function()
def register_temporal_weights_function(
    self, function: typing.Optional[typing.Callable]
) -> None:
    ...

Register a function to weight data on the fly.

The function must take three arguments:

  • st: An obspy.Stream object with the data.
  • receiver: The receiver object for the receiver.
  • sources: All sources for the event.

It furthermore must return a dictionary with a list of dictionaries for each component, e.g.

def compute_temporal_weights(
    st: obspy.Stream,
    receiver: simple_config.receiver._Base,
    sources: typing.List[simple_config.source._Base],
) -> typing.Dict[str, typing.List[typing.Dict]]:
    ...
    # Omit components which you want to ignore for the adjoint source
    # computation.
    weights = {
        "X": [
            {"values": np.array([...]), "misfit_weight": 0.5},
            {"values": np.array([...]), "misfit_weight": 0.5},
        ],
        "Y": [
            # If no "misfit_weight" is given, it defaults to 1.0.
            {"values": np.array([...])},
        ]}
    return weights
Parameters
  • function typing.Optional[typing.Callable] — Function to compute windows on the fly. Or None to unset it.
Returns None
set_temporal_interpolation()
def set_temporal_interpolation(
    self,
    start_time_in_seconds: float,
    sampling_rate_in_hertz: float,
    npts: int,
    lanczos_window_width: int = 12,
    taper_in_samples: int = 5,
) -> None:
    ...

Set the desired temporal interpolation. Once this is set, all returned waveform data will be resampled in time using a sinc based Lanczos interpolator.

The interpolation will taper and pad with zeros if necessary. It will raise if it would result in more than 50 % of padded new samples.

Parameters
  • start_time_in_seconds float — The new start time in seconds. Can be interpreted as a UNIX timestamp if so desired.
  • sampling_rate_in_hertz float — The new sampling rate in Hertz.
  • npts int — The new number of samples.
  • lanczos_window_width int — The width in samples on either side to use when interpolating onto a new sample.
  • taper_in_samples int — In case padding with zeros is necessary each traces will be tapered to zero using this many samples at each end it is being padded at. Necessary to avoid introducing unresolved frequencies.
Returns None
shallow_copy()
def shallow_copy(self) -> "EventData":
    ...

Create a shallow copy of the object - things like data and sources and receivers are just references. Useful to have multiple versions of an event data object.

Returns 'EventData'
unset_temporal_interpolation()
def unset_temporal_interpolation(self) -> None:
    ...

Unsets any temporal interpolation and data will from now on be returned with the original sampling.

Returns None

PlotProperties

class PlotProperties(builtins.object):
    def __init__(
        self, width: float = 11.5, height: float = 6.33, dpi: float = 100
    ) -> None:
        ...

Properties to use of an internally generated plot. This dataclass configures a Matplotlib axes object used in the internal plotting routine. It allows you to customize the dimensions and DPI of the resulting plot.

Parameters
  • width float — The width of the figure in inches. This parameter determines the horizontal size of the plot.
  • height float — The height of the figure in inches. This parameter determines the vertical size of the plot.
  • dpi float — Dots per inch (DPI) for the figure. DPI is a measure of the resolution or quality of the plot. Higher DPI values result in smoother and more detailed output.