Model Module¶
This module provides utility functions for loading, updating, and normalizing model
specifications. Typically, an application should use only load_model() to load files, but the
other functions are also exposed.
Unless stated otherwise, all functions here modify the passed model directly and only return it for convenience.
This submodule may also be called (e.g. with python3 -m ablinfer.model) to update and normalize
model specification files.
-
ablinfer.model.load_model(f: Union[str, IO], fp: bool = True, normalize: bool = True) → Tuple[Mapping[KT, VT_co], bool][source]¶ Load a model.
Parameters: - f – The file or string to load from.
- fp – Whether f is a file-like object or a string.
- normalize – Whether or not to normalize the result.
Returns: The updated model and a boolean indicating whether an update was performed.
-
ablinfer.model.normalize_model(model: Mapping[KT, VT_co], processing: bool = False) → Mapping[KT, VT_co][source]¶ Normalize the given model.
Also validates what fields it can on the model.
Parameters: - model – The model to normalize.
- processing – Whether or not to parse in detail the processing operations.
-
ablinfer.model.update_model(model: Dict[KT, VT], updated: bool = False) → Tuple[Dict[KT, VT], bool][source]¶ Update a model to the newest version.
Note that no verification of fields not affected by the updates is conducted.
Returns: The updated model and a boolean indicating whether an update was performed.
-
ablinfer.model.update_normalize_model(model: Mapping[KT, VT_co]) → Tuple[Mapping[KT, VT_co], bool][source]¶ Update and normalize a model.
Parameters: model – The model to fix. Returns: The updated model and a boolean indicating whether an update was performed.
-
ablinfer.model.normalize_model_config(model: Mapping[KT, VT_co], model_config: Mapping[KT, VT_co]) → Mapping[KT, VT_co][source]¶ Normalizes the given model config against the given model.
The model is assumed to be normalized.
Note that for processing configuration to be normalized properly, the processing functions must be imported before running this function; e.g.
ablinfer.slicer.processingrequires dependencies not usually found outside 3DSlicer and so is not imported automatically.Parameters: - model – The model.
- model_config – The model configuration to normalize; this will modify it.
Returns: The modified model config, for convenience.