Version:

salvus.flow.collections.event_misfit

salvus.flow.collections.event_misfit salvus flow collections event_misfit
Misfit and adjoint sources object.

Classes

EventMisfit

Misfit and adjoint sources for a single event.
It is as lazy as possible and will only compute things when absolutely required enabling interactive as well as batch usage.
SIGNATURE
class EventMisfit(builtins.object):
    def __init__(
        self,
        observed_event: EventData | None = None,
        synthetic_event: EventData,
        misfit_function: str | dict[str, str | int] | typing.Callable,
        extra_kwargs_misfit_function: dict | None = None,
        receiver_field: str,
        max_samples_for_misfit_computation: int | None = None,
        normalization: (
            str
            | data_normalizations.Normalization
            | data_normalizations.TraceNormalization
            | None
        ) = None,
    ): ...
ARGUMENTS
Optional
observed_event
Type:EventData | None
Default value:None
Description:
The observed data. Optional because certain types of misfits can be computed without observed data. In that case the misfit function must also not take observed data.
Required
synthetic_event
Type:EventData
Description:
The synthetic data.
Required
misfit_function
Type:str | dict[str, str | int] | typing.Callable
Description:
The misfit function or name of the function. Can be one of three things: 1. The of one of Salvus' built-in misfit functions. In that case the latest available version will be chosen. 2. A dictionary of the form {"misfit_name": "L2", "version": 1} to directly select a specific version of a built-in misfit function. 3. A custom function that computes misfits and adjoint sources.
Optional
extra_kwargs_misfit_function
Type:dict | None
Default value:None
Description:
Extra arguments passed on to the misfit function.
Required
receiver_field
Type:str
Description:
The receiver field to consider for the misfit computation.
Optional
max_samples_for_misfit_computation
Type:int | None
Default value:None
Description:
If given, and if the number of samples in the data for the misfit and adjoint source computation is larger than the given number, synthetic and observed data will be downsampled to the chosen number of samples and the adjoint source will later be upsampled again. Very useful for some expensive to compute misfits with strongly oversampled signals. The adjoint source will be correctly scaled at the end. This does result in the adjoint source no longer being the exact discrete derivative of the misfit but in most cases this should not be a problem.
Optional
normalization
Type:str | data_normalizations.Normalization | data_normalizations.TraceNormalization | None
Default value:None
Description:
If given, normalize the observed and synthetic traces prior to misfit and adjoint source computations. This will be accounted for during the computation of the derivatives to ensure consistency. Useful for some problems but it does make them a bit more non-linear. Available choices: * "l2_energy_per_measurement": Normalize each trace by the L2-norm of the weighted trace.

Properties

  • event_name(str)-Name of the misfit object's events.
  • meta_json_receiver_dict(dict[str, dict])-Cached dictionary mapping receiver names to their contents for the meta json - naturally only exists for synthetic data.
  • misfit_per_receiver_and_component_and_weight_set(xr.DataArray)-Return the misfit per receiver and component and weight set.
  • misfit_per_receiver_and_component_and_weight_set_as_dict(dict)-Return the misfit per receiver and component and weight set.
  • misfit_value(float)-Cumulative misfit for the whole event.
  • receiver_name_list(list[str])-Return a list of receivers for the misfit object. This will always be the receivers of the synthetic data.

Methods

EventMisfit.clear_caches()
Clear all cached misfit and adjoint sources values. Only useful in rare cases if one changes something with an existing EventMisfit object.
SIGNATURE
def clear_caches(self) -> None: ...
EventMisfit.generate_adjoint_simulation_object()
This function is deprecated! Please use create_adjoint_waveform_simulation from the module salvus.flow.simple_config.simulation_generator instead.
Generate the simulation object for the adjoint simulation.
SIGNATURE
def generate_adjoint_simulation_object(
    self, gradient_parameterization: str
) -> Waveform: ...
ARGUMENTS
Required
gradient_parameterization
Type:str
Description:
Desired gradient parameters.
EventMisfit.get_misfit_and_adjoint_source_for_event()
Compute the adjoint source and misfit for the entire event.
SIGNATURE
def get_misfit_and_adjoint_source_for_event(
    self, extra_output: ExtraOutput | None = None
) -> tuple[xr.Dataset, xr.DataArray] | None: ...
ARGUMENTS
Optional
extra_output
Type:ExtraOutput | None
Default value:None
Description:
Optional configuration of extra outputs.
EventMisfit.get_misfit_and_adjoint_source_for_receiver()
Compute the adjoint source and misfit for a single receiver.
Might return None in case no observed data is available or the receiver has been fully deselected via temporal weights.
SIGNATURE
def get_misfit_and_adjoint_source_for_receiver(
    self, receiver_name: str, plot: bool = False
) -> xr.Dataset | None: ...
ARGUMENTS
Required
receiver_name
Type:str
Description:
The name of the receiver or receiver channel.
Optional
plot
Type:bool
Default value:False
Description:
Plot the adjoint source.
EventMisfit.write()
Write the adjoint source to a file.
SIGNATURE
def write(
    self,
    filename: pathlib.Path,
    group_name: str = "adjoint_sources",
    hdf5_file_open_mode: str = "w",
    extra_output: ExtraOutput | None = None,
) -> None: ...
ARGUMENTS
Required
filename
Type:pathlib.Path
Description:
File to write to.
Optional
group_name
Type:str
Default value:'adjoint_sources'
Description:
The group in the HDF5 file in which to create the adjoint sources. This later on needs to be specified when passing the adjoint source to Salvus. The default is fine in most cases, setting the group name enables more advanced use cases.
Optional
hdf5_file_open_mode
Type:str
Default value:'w'
Description:
Mode in which h5py will open the file. Useful for advanced use cases to store different sets of adjoint sources in the HDF5 file.
Optional
extra_output
Type:ExtraOutput | None
Default value:None
Description:
Optional configuration of extra outputs.

Used in tutorials

Functionality from this module is used in the following tutorials.
PAGE CONTENTS