salvus.opt.models.structured_model
salvus.opt.models.structured_model salvus opt models structured_model A structured model class based on xarray Datasets.
Classes
StructuredModel
StructuredModelclass StructuredModel(salvus.opt.models.base_model.BaseModel):
def __init__(
self,
name: str,
model: str | pathlib.Path | xr.Dataset,
fields: list[str],
): ...Structured inversion model based on xarray DataSets.
Parameters
namestr — Name of the model.modelstr | pathlib.Path | xr.Dataset — xarray DataSet.fieldslist[str] — Names of the elemental fields to use.
Attributes
model xr.Dataset
model xr.DatasetThe model as its actual representation.
name str
name strModel name.
status ModelStatus
status ModelStatusModel status to keep track of whether the model has been modified.
Methods
from_disk()
from_disk()def from_disk(parent_folder: pathlib.Path, d: dict) -> StructuredModel: ...Load a model from disk.
Parameters
parent_folderpathlib.Path — Path where the model is stored.ddict — Dictionary containing meta information of the model.
Returns StructuredModel
from_json()
from_json()def from_json(d: dict) -> Self: ...Create a model from a dictionary.
Parameters
ddict — Dictionary containing meta information of the model.
Returns Self
compute_inf_norm()
compute_inf_norm()def compute_inf_norm(self) -> float: ...Infinity norm of the model.
Returns float
compute_norm()
compute_norm()def compute_norm(self) -> float: ...Return the model norm.
Returns float
copy()
copy()def copy(self, name: str) -> StructuredModel: ...Copy the model.
Parameters
namestr — Name of the new (copied) model.
Returns StructuredModel
dot()
dot()def dot(self, other: StructuredModel) -> float: ...Dot product of the model with another model.
Parameters
otherStructuredModel — The other model.
Returns float — The dot product as a float.
max()
max()def max(self, other: StructuredModel) -> StructuredModel: ...In-place point-wise maximum.
Parameters
otherStructuredModel — Model to compare with.
Returns StructuredModel — A reference to the modified input model, i.e.,
self.min()
min()def min(self, other: StructuredModel) -> StructuredModel: ...In-place point-wise minimum.
Parameters
otherStructuredModel — Model to compare with.
Returns StructuredModel — A reference to the modified input model, i.e.,
self.to_disk()
to_disk()def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...Serialize the model to disk. This will use the model name and the path provided. Heavy data are written directly to disk, light data are returned as dictionary.
Parameters
parent_folderpathlib.Path | str — Path to store the model.
Returns dict
to_json()
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_hashtypes — 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.timertypes — Execution timer.log_to_loggerbool — Log timings to the logger.commtypes — MPI communicator, if any.
Returns builtins.dict