salvus.opt.models.block_model
salvus.opt.models.block_model salvus opt models block_model A model using Salvus’ native mesh format.
Classes
BlockModel
BlockModelclass BlockModel(salvus.opt.models.base_model.BaseModel):
def __init__(
self,
name: str,
model: str | pathlib.Path | Mesh | list[DataBlock],
fields: list[str],
compute_auxiliary_data: bool = True,
): ...Salvus mesh inversion model.
namestr — Name of the model.modelstr | pathlib.Path | Mesh | list[DataBlock] — The model either as a list ofDataBlockobjects, aMeshobject, or a path to a serializedBlockModelobject.fieldslist[str] — Names of the elemental fields to use.compute_auxiliary_databool — Whether to compute auxiliary data for the blocks.
model list[DataBlock]
model list[DataBlock]The actual dataset representing the model.
name str
name strModel name.
status ModelStatus
status ModelStatusModel status to keep track of whether the model has been modified.
vector npt.NDArray[np.float64]
vector npt.NDArray[np.float64]The block model as a vector.
The vector is ordered by block, then by field within each block. Does not include fields that are not part of a given block’s material.
from_disk()
from_disk()def from_disk(parent_folder: pathlib.Path, d: dict) -> BlockModel: ...Load a model from disk. This will use the dictionary and path provided.
parent_folderpathlib.Path — Path to store the model.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.
update_notification_count()
update_notification_count()def update_notification_count() -> None: ...Update the notification count in the decorator info.
compute_inf_norm()
compute_inf_norm()def compute_inf_norm(self) -> float: ...Compute the infinity norm of the model.
compute_norm()
compute_norm()def compute_norm(self) -> float: ...Return the model norm.
copy()
copy()def copy(self, name: str) -> BlockModel: ...Copy the model.
Will load the model from disk if necessary, and leave it in memory.
namestr — Name of the new model.
dot()
dot()def dot(self, other: BlockModel) -> float: ...Compute the dot product between this model and another model.
otherBlockModel — The other model to compute the dot product with.
expand_scalar_fields()
expand_scalar_fields()def expand_scalar_fields(self) -> None: ...Expand any scalar fields in the model to full arrays.
This modifies the model in place.
get_block()
get_block()def get_block(self, block_id: int) -> DataBlock | None: ...Get a block by its ID.
block_idint — The ID of the block to retrieve.
get_data_from_block()
get_data_from_block()def get_data_from_block(
self, block: MeshBlock, global_material_fields: set[str]
) -> dict[str, npt.NDArray | types.scalar_]: ...Extract the data from a single mesh block.
If the block has a material defined, the extracted data will only contain the fields that are required for this material. Any missing data will be a scalar zero.
blockMeshBlock — The mesh block to extract the data from.global_material_fieldsset[str] — Set of all material fields defined in the mesh.
max()
max()def max(self, other: BlockModel) -> BlockModel: ...In-place point-wise maximum.
otherBlockModel — Model to compare with.
min()
min()def min(self, other: BlockModel) -> BlockModel: ...In-place point-wise minimum.
otherBlockModel — Model to compare with.
to_disk()
to_disk()def to_disk(self, parent_folder: pathlib.Path | str) -> dict: ...Serialize the model to JSON (and an associated pair of an npy file and a toml file containt some basic information on the blocks).
parent_folderpathlib.Path | str — Parent folder where the JSON + npy files should be stored.
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.
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.