Skip to content

Bases: _LinkNodeCell, BaseModelElement, ActorProtocol

A patch cell of a RasterLayer. Subclassing this class to create a custom cell. When class attribute max_agents is assigned, the agents property will be limited to the number of agents.

Attributes:

Name Type Description
agents _CellAgentsContainer

The agents located at here.

layer PatchModule

The RasterLayer where this PatchCell belongs.

Source code in abses/space/cells.py
def __init__(
    self,
    layer: PatchModule,
    indices: Pos,
    pos: Optional[Pos] = None,
):
    BaseModelElement.__init__(self, model=layer.model)
    _LinkNodeCell.__init__(self)
    self.indices = indices
    self.pos = pos
    self._set_layer(layer=layer)

layer property

layer

RasterLayer where this PatchCell belongs.

agents property

agents

The agents located at here.

coordinate property

coordinate

The position of this cell.

geo_type property

geo_type

Return the geo_type

crs property

crs

The crs of this cell, the same as the layer.

is_empty property

is_empty

Check if the cell is empty.

get

get(attr, target=None, default=None)

Gets the value of an attribute or registered property. Automatically update the value if it is the dynamic variable of the layer.

Parameters:

Name Type Description Default
attr str

The name of attribute to get.

required
target Optional[TargetName]

Optional target name.

None
default Any

Default value if attribute is not found.

None

Returns:

Name Type Description
Any Any

The value of the attribute.

Raises:

Type Description
AttributeError

Attribute value of the associated patch cell.

Source code in abses/space/cells.py
def get(
    self,
    attr: str,
    target: Optional[TargetName] = None,
    default: Any = None,
) -> Any:
    """Gets the value of an attribute or registered property.
    Automatically update the value if it is the dynamic variable of the layer.

    Parameters:
        attr: The name of attribute to get.
        target: Optional target name.
        default: Default value if attribute is not found.

    Returns:
        Any: The value of the attribute.

    Raises:
        AttributeError: Attribute value of the associated patch cell.
    """
    # if attr in self.layer.dynamic_variables:
    #     self.layer.dynamic_var(attr_name=attr)
    return super().get(attr=attr, target=target, default=default)

neighboring

neighboring(
    moore=False,
    radius=1,
    include_center=False,
    annular=False,
)

Get the grid around the patch.

Parameters:

Name Type Description Default
moore bool

Whether to include the Moore neighborhood.

False
radius int

The radius of the neighborhood.

1
include_center bool

Whether to include the center cell.

False
annular bool

Whether to use an annular neighborhood.

False

Returns:

Type Description
ActorsList['PatchCell']

ActorsList[PatchCell]: The neighboring cells.

Source code in abses/space/cells.py
def neighboring(
    self,
    moore: bool = False,
    radius: int = 1,
    include_center: bool = False,
    annular: bool = False,
) -> ActorsList["PatchCell"]:
    """Get the grid around the patch.

    Parameters:
        moore: Whether to include the Moore neighborhood.
        radius: The radius of the neighborhood.
        include_center: Whether to include the center cell.
        annular: Whether to use an annular neighborhood.

    Returns:
        ActorsList[PatchCell]: The neighboring cells.
    """
    return self.layer.get_neighboring_by_indices(
        self.indices,
        moore=moore,
        radius=radius,
        include_center=include_center,
        annular=annular,
    )