Skip to content

Natural Modules

Bases: CompositeModule, _PatchModuleProtocol

The Base Nature Module. Note: Look at this tutorial to understand the model structure. This is NOT a raster layer, but can be seen as a container of different raster layers. Users can create new raster layer (i.e., PatchModule) by new method. By default, an initialized ABSESpy model will init an instance of this BaseNature as nature module.

Attributes:

Name Type Description
major_layer Optional[PatchModule]

The major layer of nature module. By default, it's the first layer that user created.

total_bounds ndarray

The spatial scope of the model's concern. By default, uses the major layer of this model.

Source code in abses/nature.py
def __init__(
    self, model: MainModel[Any, Any], name: str = "nature"
) -> None:
    CompositeModule.__init__(self, model, name=name)
    self._major_layer: Optional[PatchModule] = None
    self._modules: _PatchModuleFactory = _PatchModuleFactory(self)

major_layer property writable

major_layer

The major layer of nature module. By default, it's the first created layer.

total_bounds property

total_bounds

Total bounds. The spatial scope of the model's concern. If None (by default), uses the major layer of this model. Usually, the major layer is the first layer sub-module you created.

crs property

crs

Geo CRS.

create_module

create_module(module_cls=None, how=None, major_layer=False, **kwargs)

Creates a submodule of the raster layer.

Parameters:

Name Type Description Default
module_cls Optional[Type[PatchModule]]

The custom module class.

None
how Optional[HowCreation]

Class method to call when creating the new sub-module (raster layer). So far, there are three options: from_resolution: by selecting shape and resolution. from_file: by input of a geo-tiff dataset. copy_layer: by copying shape, resolution, bounds, crs, and coordinates of an existing submodule. if None (by default), just simply create a sub-module without any custom methods (i.e., use the base class PatchModule).

None
**kwargs Any

Any other arg passed to the creation method. See corresponding method of your how option from PatchModule class methods.

{}

Returns:

Type Description
PatchModule

the created new module.

Source code in abses/nature.py
def create_module(
    self,
    module_cls: Optional[Type[PatchModule]] = None,
    how: Optional[HowCreation] = None,
    major_layer: bool = False,
    **kwargs: Any,
) -> PatchModule:
    """Creates a submodule of the raster layer.

    Parameters:
        module_cls:
            The custom module class.
        how:
            Class method to call when creating the new sub-module (raster layer).
            So far, there are three options:
                `from_resolution`: by selecting shape and resolution.
                `from_file`: by input of a geo-tiff dataset.
                `copy_layer`: by copying shape, resolution, bounds, crs, and coordinates of an existing submodule.
            if None (by default), just simply create a sub-module without any custom methods (i.e., use the base class `PatchModule`).
        **kwargs:
            Any other arg passed to the creation method.
            See corresponding method of your how option from `PatchModule` class methods.

    Returns:
        the created new module.
    """
    if self.modules.is_empty:
        major_layer = True
    module = self.modules.new(how=how, module_class=module_cls, **kwargs)
    # 如果是第一个创建的模块,则将其作为主要的图层
    if major_layer:
        self.major_layer = module
    setattr(self, module.name, module)
    return module