Mondaic

salvus.opt.data_normalizations

salvus.opt.data_normalizations salvus opt data_normalizations

Data normalizations and their jacobians.

Functions

get_available_data_normalizations()

def get_available_data_normalizations() -> list[str]: ...

Get a list of all available data normalizations.

Returns list[str]

get_data_normalization()

def get_data_normalization(name: str) -> Normalization: ...

Get a built-in data normalization via its name.

Parameters
  • name str — The name of the data normalization.
Returns Normalization

Classes

ForwardNormProtocol

class ForwardNormProtocol(typing.Protocol):
    def __init__(self):
        ...

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...

ForwardTraceNormProtocol

class ForwardTraceNormProtocol(typing.Protocol):
    def __init__(self):
        ...

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...

JacobianNormProtocol

class JacobianNormProtocol(typing.Protocol):
    def __init__(self):
        ...

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...

JacobianTraceNormProtocol

class JacobianTraceNormProtocol(typing.Protocol):
    def __init__(self):
        ...

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...

Normalization

class Normalization(
    salvus.flow.utils.serialization_helpers.SerializationMixin, typing.Generic
):
    def __init__(
        self,
        forward: ForwardNormProtocol | str,
        jacobian: JacobianNormProtocol | str,
        skip_validation: bool = False,
    ): ...

Keeps track of the initial arguments passed to an objects and can later on serialize them to JSON document.

It will only consider whatever is passed in the init.

A per-shot type of data normalization and its jacobian.

Parameters
  • forward ForwardNormProtocol | str — Function implementing the data normalization.
  • jacobian JacobianNormProtocol | str — Function implementing the jacobian of the data normalization.
  • skip_validation bool — By default the forward and jacobian functions will be validated with a gradient test. Set this to True to skip that test.
Methods
from_json()
def from_json(d: builtins.dict) -> Any: ...

Recreate the object from a dictionary serialization of its initialization parameters.

Parameters
  • d builtins.dict — Dictionary containing its init parameters and a few other things.
Returns Any
forward()
def forward(
    self,
    data_array_synthetic: xr.DataArray,
    data_array_observed: T,
    event: Event,
) -> tuple[xr.DataArray, T]: ...

Apply the forward data normalization function.

Returns the normalized synthetic and observed data traces, respectively.

Parameters
  • data_array_synthetic xr.DataArray — The synthetic data traces without normalization.
  • data_array_observed T — The observed data traces without normalization.
  • event Event — The event object.
Returns tuple[xr.DataArray, T]
jacobian()
def jacobian(
    self,
    data_array_adjoint_sources: xr.DataArray,
    data_array_synthetic: xr.DataArray,
    data_array_observed: T,
    event: Event,
) -> xr.DataArray: ...

Apply the jacobian of the forward data normalization function to the adjoint source and return it.

Parameters
  • data_array_adjoint_sources xr.DataArray — The adjoint sources.
  • data_array_synthetic xr.DataArray — The synthetic data traces without normalization.
  • data_array_observed T — The observed data traces without normalization.
  • event Event — The event object.
Returns xr.DataArray
perform_gradient_test()
def perform_gradient_test(self) -> None: ...

Perform a gradient test to validate the jacobian function.

This will test that the jacobian is the correct jacobian for the chosen forward normalization.

Returns None
to_json()
def to_json(
    self,
    external_file_hash: types = None,
    timer: types = None,
    log_to_logger: bool = False,
    comm: types = None,
) -> builtins.dict: ...

Serialize the object to a dictionary that can be written to JSON.

Parameters
  • external_file_hash types — Hash of any external files associated with this object. Can be passed here in which case it will be stored in a centralized location in the JSON file.
  • timer types — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm types — MPI communicator, if any.
Returns builtins.dict

TraceNormalization

class TraceNormalization(
    salvus.flow.utils.serialization_helpers.SerializationMixin, typing.Generic
):
    def __init__(
        self,
        forward: ForwardTraceNormProtocol | str,
        jacobian: JacobianTraceNormProtocol | str,
        skip_validation: bool = False,
    ): ...

Keeps track of the initial arguments passed to an objects and can later on serialize them to JSON document.

It will only consider whatever is passed in the init.

A per-trace type of data normalization and its jacobian.

Parameters
  • forward ForwardTraceNormProtocol | str — Function implementing the data normalization.
  • jacobian JacobianTraceNormProtocol | str — Function implementing the jacobian of the data normalization.
  • skip_validation bool — By default the forward and jacobian functions will be validated with a gradient test. Set this to True to skip that test.
Methods
from_json()
def from_json(d: builtins.dict) -> Any: ...

Recreate the object from a dictionary serialization of its initialization parameters.

Parameters
  • d builtins.dict — Dictionary containing its init parameters and a few other things.
Returns Any
forward()
def forward(
    self,
    data_synthetic: npt.NDArray,
    data_observed: T,
    sampling_rate_in_hertz: float,
) -> tuple[npt.NDArray, T]: ...

Apply the forward data normalization function.

Returns the normalized synthetic and observed data traces, respectively.

Parameters
  • data_synthetic npt.NDArray — The synthetic data trace without normalization.
  • data_observed T — The observed data trace without normalization.
  • sampling_rate_in_hertz float — The sampling rate of both data traces in Hz.
Returns tuple[npt.NDArray, T]
jacobian()
def jacobian(
    self,
    adjoint_source: npt.NDArray,
    data_synthetic: npt.NDArray,
    data_observed: T,
    sampling_rate_in_hertz: float,
) -> npt.NDArray: ...

Apply the jacobian of the forward data normalization function to the adjoint source and return it.

Parameters
  • adjoint_source npt.NDArray — The adjoint source.
  • data_synthetic npt.NDArray — The synthetic data trace without normalization.
  • data_observed T — The observed data trace without normalization.
  • sampling_rate_in_hertz float — The sampling rate of the adjoint source and data in Hz.
Returns npt.NDArray
perform_gradient_test()
def perform_gradient_test(self) -> None: ...

Perform a gradient test to validate the jacobian function.

This will test that the jacobian is the correct jacobian for the chosen forward normalization.

Returns None
to_block_normalization()
def to_block_normalization(self) -> Normalization: ...

Convert the trace wise normalization to a block normalization.

Returns Normalization
to_json()
def to_json(
    self,
    external_file_hash: types = None,
    timer: types = None,
    log_to_logger: bool = False,
    comm: types = None,
) -> builtins.dict: ...

Serialize the object to a dictionary that can be written to JSON.

Parameters
  • external_file_hash types — Hash of any external files associated with this object. Can be passed here in which case it will be stored in a centralized location in the JSON file.
  • timer types — Execution timer.
  • log_to_logger bool — Log timings to the logger.
  • comm types — MPI communicator, if any.
Returns builtins.dict

Submodules