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.
namestr — Name of the model.modelstr | pathlib.Path | xr.Dataset — xarray DataSet.fieldslist[str] — Names of the elemental fields to use.
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.
from_disk()
from_disk()def from_disk(parent_folder: pathlib.Path, d: dict) -> StructuredModel: ...Load a model from disk.
parent_folderpathlib.Path — Path where the model is stored.ddict — Dictionary containing meta information of the model.
from_json()
from_json()def from_json(d: dict) -> Self: ...Create a model from a dictionary.
ddict — Dictionary containing meta information of the model.
copy()
copy()def copy(self, name: str) -> StructuredModel: ...Copy the model.
namestr — Name of the new (copied) model.
dot()
dot()def dot(self, other: StructuredModel) -> float: ...Dot product of the model with another model.
otherStructuredModel — The other model.
get_metric()
get_metric()def get_metric(self) -> dict[str, npt.NDArray]: ...Get the metric for the model.
max()
max()def max(self, other: StructuredModel) -> StructuredModel: ...In-place point-wise maximum.
otherStructuredModel — Model to compare with.
self.min()
min()def min(self, other: StructuredModel) -> StructuredModel: ...In-place point-wise minimum.
otherStructuredModel — Model to compare with.
self.norm()
norm()def norm(self) -> float: ...Return the model norm.
norm_inf()
norm_inf()def norm_inf(self) -> float: ...Infinity norm of the model.
to_dict()
to_dict()def to_dict(self) -> dict[str, dict[str, npt.NDArray]]: ...Convert the model to a dictionary representation.
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.
parent_folderpathlib.Path | str — Path to store the model.
to_json()
to_json()def to_json(
self,
external_file_hash: Optional[str] = None,
timer: Optional[salvus._core.timer.timer.Timer] = None,
log_to_logger: bool = False,
comm: Optional[int] = None,
) -> Dict: ...Serialize the object to a dictionary that can be written to JSON.
external_file_hashOptional[str] =None— 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.timerOptional[salvus._core.timer.timer.Timer] =None— Execution timer.log_to_loggerbool =False— Log timings to the logger.commOptional[int] =None— MPI communicator, if any.
validate_consistency()
validate_consistency()def validate_consistency(
self, other: StructuredModel, description: str = "other model"
) -> None: ...Check that another model has the same parameters and array shapes.
otherStructuredModel — The model to compare to, e.g., a weight or a reference model.descriptionstr ='other model'— Name ofotherin error messages.