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()
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.
event_data_objectstyping.List[EventData] — A list of the event data objects to use.receiver_fieldstr — The receiver field to plot.componentstr — The component to plot.event_data_labelstyping.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_bytyping.Optional[typing.Callable] — Callback function called with the receiver objects to determine the sorting. Works like thekeycallback for the standard Pythonsorted()method.filter_bytyping.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 Pythonfilter()method. For complex filter operations requiring all receivers, defer to theselect_bymethod.select_bytyping.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.interleavebool — Whether or not to alternatingly plot data. If false, traces from all data will be plotted on top of each other.colorstyping.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.alphatyping.Optional[float] — The opacity of all data, as used in Matplotlib. useful when setting interleave to false.plot_usingPlotProperties | matplotlib.axes.Axes — The configuration of the axis to create or reuse. Will default to the standard size as defined in the PlotProperties dataclass.
Classes
EventData
EventDataclass 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.
eventEvent — The event object.datatyping.Union[pathlib.Path, typing.Dict, xr.Dataset] — Path to the actual waveform data or a dictionary describing the data.data_hashtyping.Optional[str] — Uniquely identifying hash of that pieces of data. Might not always be available.path_to_meta_jsontyping.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_jsontyping.Optional[pathlib.Path] — Optionally specify the job_info.json path of the run.
data _Backends
data _BackendsAccess the actual data via a proxy that abstracts different file formats.
file_format str
file_format strReturns the file format, either "hdf5", "xarray", or "asdf".
is_synthetic bool
is_synthetic boolIs the data from a Salvus simulation?
job_info_json_contents typing.Optional[typing.Dict]
job_info_json_contents typing.Optional[typing.Dict]Contents of the job_info.json file.
meta_json_contents typing.Optional[typing.Dict]
meta_json_contents typing.Optional[typing.Dict]Contents of the meta.json file.
receiver_channels List[salvus.flow.collections.receiver_channel.ReceiverChannel]
receiver_channels List[salvus.flow.collections.receiver_channel.ReceiverChannel]The receiver channels for this event.
receiver_name_list List[str]
receiver_name_list List[str]Return a list of receiver names for this event.
receivers List[salvus.flow.simple_config.receiver._Base]
receivers List[salvus.flow.simple_config.receiver._Base]The receivers for this event.
sources List[salvus.flow.simple_config.source._Base]
sources List[salvus.flow.simple_config.source._Base]The sources for this event.
from_output_folder()
from_output_folder()def from_output_folder(output_folder: pathlib.Path) -> "EventData":
...Construct an EventData object from a folder containing Salvus
outputs.
output_folderpathlib.Path — Folder where the output files are stored.
_get_data_cube()
_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.
receiver_fieldstr — Receiver field to retrieve.componenttyping.Union[str, int] — The component to retrieve.sort_bytyping.Optional[typing.Callable[[_Base], int]] — Callback function called with the receiver objects to determine the sorting. Works like thekeycallback for the standard Pythonsorted()method.filter_bytyping.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 Pythonfilter()method. For complex filter operations requiring all receivers, defer to theselect_bymethod.select_bytyping.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.
compute_data_hash()
compute_data_hash()def compute_data_hash(self) -> str:
...Compute a unique hash for the event data.
delete_associated_job_and_data()
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.
download_extra_outputs()
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.
data_types_to_downloadtyping.Union[typing.Collection[typing_extensions.Literal[('volume', 'surface')]], typing_extensions.Literal[('volume', 'surface')]] — The data types to download. Defaults to downloading everything.localpathtyping.Optional[typing.Union[str, pathlib.Path]] — By default, downloads will be stored next to themeta.jsonof 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 themeta.jsonfile’s folder.
expected_components_from_receiver()
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.
receiverUnion[salvus.flow.simple_config.receiver._Base, Dict] — The receiver object or dictionary representation.receiver_fieldstr — The receiver field.
get_associated_salvus_job()
get_associated_salvus_job()def get_associated_salvus_job(self) -> "SalvusJob":
...Get the associated Salvus job, if it still exists.
get_data_cube()
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.
receiver_fieldstr — Receiver field to retrieve.componenttyping.Union[str, int] — The component to retrieve.sort_bytyping.Optional[typing.Callable[[_Base], int]] — Callback function called with the receiver objects to determine the sorting. Works like thekeycallback for the standard Pythonsorted()method.filter_bytyping.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 Pythonfilter()method. For complex filter operations requiring all receivers, defer to theselect_bymethod.select_bytyping.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.
get_receiver()
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.
receiver_namestr — The name of the receiver.
get_receiver_data()
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.
receiver_namestr — The name of the receiverreceiver_fieldstr — The field to get.headertyping.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_weightsbool — 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.
get_remote_extra_output_filenames()
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.
get_time_axis_from_meta_json()
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.
get_wavefield_output()
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.
output_typetyping_extensions.Literal[('volume', 'surface')] — The output type to get,"surface"or"volume".fieldstr — The field to get.time_stepsslice — The time step indices to read expressed as a Python slice object.download_if_not_existsbool — 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_downloadbool — 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.
get_waveform_data()
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.
receiver_namestr — The name of the receiver or receiver channelreceiver_fieldstr — The field to get.headertyping.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_weightsbool — 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.
get_waveform_data_for_receiver_channel()
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.
identifierstr — The name/identifier of the receiver channel.receiver_fieldstr — The field to get.headertyping.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_weightsbool — 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.
has_receiver()
has_receiver()def has_receiver(self, receiver_name: str) -> bool:
...Figure out if the given receiver is available.
receiver_namestr — Name of the receiver.
has_receiver_nsl()
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.
network_codestr — The network code.station_codestr — The station code.location_codestr — The location code.
plot()
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.
plot_typestyping.Iterable[str] — How to plot the data.receiver_fieldstr — The receiver field to plot.componentstr — The component to plot.sort_bytyping.Optional[typing.Callable] — Callback function called with the receiver objects to determine the sorting. Works like thekeycallback for the standard Pythonsorted()method.
register_processing_function()
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: Anobspy.Streamobject 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: Anobspy.Inventoryobject 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.
functiontyping.Optional[typing.Callable] — Function to process data on the fly. OrNoneto unset it.chain_to_existing_functionbool — IfTruethe new function will be chained to a possibly already pre-existing processing function. If this isFalseand there is an already pre-existing function it will raise.
register_temporal_weights_function()
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: Anobspy.Streamobject 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 weightsfunctiontyping.Optional[typing.Callable] — Function to compute windows on the fly. OrNoneto unset it.
set_temporal_interpolation()
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.
start_time_in_secondsfloat — The new start time in seconds. Can be interpreted as a UNIX timestamp if so desired.sampling_rate_in_hertzfloat — The new sampling rate in Hertz.nptsint — The new number of samples.lanczos_window_widthint — The width in samples on either side to use when interpolating onto a new sample.taper_in_samplesint — 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.
shallow_copy()
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.
unset_temporal_interpolation()
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.
PlotProperties
PlotPropertiesclass 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.
widthfloat — The width of the figure in inches. This parameter determines the horizontal size of the plot.heightfloat — The height of the figure in inches. This parameter determines the vertical size of the plot.dpifloat — 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.