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

salvus.flow.collections.event_misfit

Misfit and adjoint sources object.

Classes

EventMisfit

class EventMisfit(builtins.object):
    def __init__(
        self,
        observed_event: Optional[
            salvus.flow.collections.event_data.EventData
        ] = None,
        synthetic_event: salvus.flow.collections.event_data.EventData,
        misfit_function: Union[str, Dict[str, Union[str, int]], Callable],
        extra_kwargs_misfit_function: Optional[Dict] = None,
        receiver_field: str,
        max_samples_for_misfit_computation: Optional[int] = None,
        normalization: Optional[str] = None,
    ):
        ...

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.

Parameters
  • observed_event Optional[salvus.flow.collections.event_data.EventData] — 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.
  • synthetic_event salvus.flow.collections.event_data.EventData — The synthetic data.
  • misfit_function Union[str, Dict[str, Union[str, int]], Callable] — 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.
  • extra_kwargs_misfit_function Optional[Dict] — Extra arguments passed on to the misfit function.
  • receiver_field str — The receiver field to consider for the misfit computation.
  • max_samples_for_misfit_computation Optional[int] — 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.
  • normalization Optional[str] — 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.
Attributes
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 Dict[str, Dict[str, List]]

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
clear_caches()
def clear_caches(self) -> None:
    ...

Clear all cached misfit and adjoint sources values. Only useful in rare cases if one changes something with an existing EventMisfit object.

Returns None
generate_adjoint_simulation_object()
def generate_adjoint_simulation_object(
    self, gradient_parameterization: str
) -> salvus.flow.simple_config.simulation.waveform.Waveform:
    ...

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.

Parameters
  • gradient_parameterization str — Desired gradient parameters.
Returns salvus.flow.simple_config.simulation.waveform.Waveform
get_misfit_and_adjoint_source_for_receiver()
def get_misfit_and_adjoint_source_for_receiver(
    self, receiver_name: str, plot: bool = False
) -> Optional[Dict]:
    ...

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.

Parameters
  • receiver_name str — The name of the receiver.
  • plot bool — Plot the adjoint source.
Returns Optional[Dict]
write()
def write(
    self,
    filename: pathlib.Path,
    group_name: str = "adjoint_sources",
    hdf5_file_open_mode: str = "w",
) -> None:
    ...

Write the adjoint source to a file.

Parameters
  • filename pathlib.Path — File to write to.
  • group_name str — 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.
  • hdf5_file_open_mode str — Mode in which h5py will open the file. Useful for advanced use cases to store different sets of adjoint sources in the HDF5 file.
Returns None