salvus.opt.models.structured_model
A structured model class based on xarray.
Classes
StructuredModel
StructuredModelclass StructuredModel(salvus.opt.models.base_model.BaseModel):
def __init__(
self,
name: str,
model: Union[str, pathlib.Path, xarray.core.dataset.Dataset],
fields: List[str],
):
...Structured inversion model based on xarray.
Parameters
namestr — Name of the model.modelUnion[str, pathlib.Path, xarray.core.dataset.Dataset] — xarray datasetfieldsList[str] — Names of the elemental fields to use.
Attributes
model xarray.core.dataset.Dataset
model xarray.core.dataset.DatasetThe actual dataset representing the model.
name str
name strModel name.
status str
status strModel 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. This will use the dictionary and path provided.
Parameters
parent_folderpathlib.Path — Path to store the model.dDict — Dictionary containing meta information of the model.
Returns StructuredModel
from_json()
from_json()def from_json(d: Dict) -> typing_extensions.Self:
...Create a model from a dictionary.
Parameters
dDict — Dictionary containing meta information of the model.
Returns typing_extensions.Self
copy()
copy()def copy(self, name: str) -> StructuredModel:
...Copy the model.
Parameters
namestr — Name of the new model.
Returns StructuredModel
dot()
dot()def dot(self, other: StructuredModel) -> float:
...Compute dot product.
Parameters
otherStructuredModel — Other model to compute the dot product with.
Returns 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.
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.
norm()
norm()def norm(self) -> float:
...Return the model norm.
Returns float
norm_inf()
norm_inf()def norm_inf(self) -> float:
...Infinity norm.
Returns float
to_disk()
to_disk()def to_disk(self, parent_folder: Union[str, pathlib.Path]) -> Dict:
...Serialize the model to JSON (and an associated npy file).
Parameters
parent_folderUnion[str, pathlib.Path] — Parent folder where the JSON + nc files should be stored.
Returns Dict
to_json()
to_json()def to_json(self, external_file_hash: Optional[str] = None) -> Dict:
...Serialize the object to dictionary that can be written to JSON.
Parameters
external_file_hashOptional[str] — 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.
Returns Dict