Mondaic

salvus.opt.models.generic_model

salvus.opt.models.generic_model salvus opt models generic_model

A generic model based on a numpy array.

Classes

GenericModel

class GenericModel(salvus.opt.models.base_model.BaseModel):
    def __init__(self, name: str, data: str | pathlib.Path | npt.NDArray): ...

Generic inversion model using a numpy array.

Parameters
  • name str — Name of the model.
  • data str | pathlib.Path | npt.NDArray — Model data.
Attributes
data npt.NDArray

The model data as an arbitrary numpy array.

model npt.NDArray

The model as its actual representation.

name str

Model name.

status ModelStatus

Model status to keep track of whether the model has been modified.

vector npt.NDArray

The model data as a vector.

Returns: vector: The model data flattened to a 1D array.

Methods
from_disk()
def from_disk(parent_folder: pathlib.Path, d: dict) -> GenericModel: ...

Load a model from disk. This will use the dictionary and path provided.

Parameters
  • parent_folder pathlib.Path — Path to store the model.
  • d dict — Dictionary containing meta information of the model.
Returns GenericModel
from_json()
def from_json(d: dict) -> Self: ...

Create a model from a dictionary.

Parameters
  • d dict — Dictionary containing meta information of the model.
Returns Self
compute_inf_norm()
def compute_inf_norm(self) -> float: ...

Infinity norm of the model.

Returns float
compute_norm()
def compute_norm(self) -> float: ...

Return the model norm.

Returns float
copy()
def copy(self, name: str) -> GenericModel: ...

Copy the model.

Parameters
  • name str — Name of the new (copied) model.
Returns GenericModel
dot()
def dot(self, other: GenericModel) -> float: ...

Dot product of the model with another model.

Parameters
  • other GenericModel — The other model.
Returns float — The dot product as a float.
max()
def max(self, other: GenericModel) -> GenericModel: ...

In-place point-wise maximum.

Parameters
  • other GenericModel — Model to compare with.
Returns GenericModel — A reference to the modified input model, i.e., self.
min()
def min(self, other: GenericModel) -> GenericModel: ...

In-place point-wise minimum.

Parameters
  • other GenericModel — Model to compare with.
Returns GenericModel — A reference to the modified input model, i.e., self.
to_disk()
def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...

Serialize the model to JSON (and an associated npy file).

Parameters
  • parent_folder pathlib.Path | str — Parent folder where the JSON + npy files should be stored.
Returns dict
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