pyissm.model.classes.class_registry
Class registry management for ISSM classes.
Functions
|
Create an instance of a registered class by its type string. |
|
Map legacy class types to modern hierarchical class names for backwards compatibility. |
|
Register a class in the global class registry for ISSM classes. |
Classes
|
Base class providing state management and inheritance capabilities for ISSM classes. |
- pyissm.model.classes.class_registry.create_instance(classtype)
Create an instance of a registered class by its type string.
This function looks up a class in the CLASS_REGISTRY using the provided classtype string and instantiates it. It handles legacy class name mapping and provides error handling for unknown class types.
This is the primary interface for dynamic class instantiation in the ISSM classes system, used for loading saved models and creating class instances from string identifiers.
- Parameters:
classtype (
str) – The class type string identifying which class to instantiate. Can be either legacy or modern naming convention.- Returns:
An instance of the requested class, or None if the class type is unknown.
- Return type:
objectorNone
Notes
The function performs the following steps:
Maps legacy class types to modern equivalents using map_classtype()
Looks up the class in CLASS_REGISTRY
Instantiates the class with no arguments
Returns None (with warning) if class type is unknown
Examples
>>> instance = create_instance('smb.default') >>> type(instance).__name__ 'default' >>> instance = create_instance('unknown.class') ⚠️ Unknown classtype unknown.class. Skipping... >>> instance is None True
- class pyissm.model.classes.class_registry.manage_state(other=None)
Bases:
objectBase class providing state management and inheritance capabilities for ISSM classes.
This class serves as the foundation for all ISSM classes, providing automatic field inheritance, state serialization for save/load operations, and field comparison utilities. It enables the “other” parameter pattern used throughout ISSM for class initialization and configuration inheritance.
Notes
The inheritance mechanism works by:
Comparing each attribute of the current instance with the “other” instance
If the attribute exists in both and the values differ, the “other” value is used
This allows default values to be overridden selectively
Field equality comparison handles:
NaN values (considered equal to other NaN values)
NumPy arrays (using np.array_equal)
Regular Python objects (using == operator)
Examples
>>> class Example(manage_state): ... def __init__(self, other=None): ... self.value1 = 10 ... self.value2 = np.nan ... super().__init__(other) >>> base = Example() >>> base.value1 = 20 >>> inherited = Example(other=base) >>> inherited.value1 20
- classmethod issm_enum_string()
Default ISSM C++ enum string used during marshalling.
Historical behavior for outputdefinition was to capitalize the Python class name (e.g., ‘surfacesquare’ -> ‘Surfacesquare’). Subclasses can override this when ISSM expects a different enum string (e.g., ‘Cfsurfacesquare’).
- pyissm.model.classes.class_registry.map_classtype(classtype)
Map legacy class types to modern hierarchical class names for backwards compatibility.
This function provides a mapping from old/MATLAB ISSM class naming conventions to the new Python modular naming scheme. It ensures that legacy model files can still work with the updated class structure.
- Parameters:
classtype (
str) – The legacy class type string to be mapped.- Returns:
str – The modern class type string, or the original if no mapping exists.
- Return type:
str
Notes
The mapping covers major ISSM component categories:
basalforcings: Various basal forcing models (default, pico, linear, etc.)
calving: Ice calving models (default, crevassedepth, levermann, etc.)
friction: Basal friction laws (default, coulomb, weertman, etc.)
smb: Surface mass balance models (default, arma, pdd, etc.)
hydrology: Subglacial hydrology models (glads, shreve, pism, etc.)
And many more…
When a legacy class type is mapped, an informational message is printed.
Examples
>>> map_classtype('SMBforcing.SMBforcing') "ℹ️ Legacy classtype 'SMBforcing.SMBforcing' mapped to 'smb.default'" >>> map_classtype('friction.weertman') # Already modern 'friction.weertman'
- pyissm.model.classes.class_registry.register_class(cls)
Register a class in the global class registry for ISSM classes.
This decorator function automatically registers classes in the global CLASS_REGISTRY dictionary using a hierarchical naming scheme based on the module structure. It extracts the module path and creates a key for dynamic class instantiation.
- Parameters:
cls (
type) – The class to be registered in the registry.- Returns:
type – The same class that was passed in (decorator pattern).
- Return type:
type
Notes
The registration key is constructed as:
If “classes” is in the module path: uses parts after “classes” + class name
Otherwise: uses last 2 module parts + class name
Example module path: pyissm.model.classes.smb -> key: “smb.default” (for class ‘default’)
Examples
# To register a class, simply decorate it with @register_class @register_class class default(manage_state): pass # Registers as 'smb.default' if in pyissm.model.classes.smb module