Skip to content

refactor gis cell init to accept kwargs#320

Merged
wang-boyu merged 2 commits intomesa:mainfrom
wang-boyu:gis/cell-init
Feb 18, 2026
Merged

refactor gis cell init to accept kwargs#320
wang-boyu merged 2 commits intomesa:mainfrom
wang-boyu:gis/cell-init

Conversation

@wang-boyu
Copy link
Member

This PR updates constructors of raster cell subclasses, from for example

class LakeCell(mesa_geo.Cell):
    def __init__(self, model, pos=None, indices=None):
        super().__init__(model, pos, indices)
        ...

to

class LakeCell(mesa_geo.Cell):
    def __init__(self, model=None, **kwargs):
        super().__init__(model, **kwargs)
        ...

This is mainly due to changes to raster cell constructor from mesa/mesa-geo#299, where we deprecated cell.indices to cell.rowcol, and added cell.xy. In addition, when we initialize cells when creating a raster layer, this is how cell constructor is called now (link to code):

cell = self.cell_cls(
    model,
    pos=(grid_x, grid_y),
    rowcol=(row_idx, col_idx),
    xy=xy,
)

where cell_cls is the user-defined subclass of raster cell, such as the LakeCell above.

By putting all parameters but model into **kwargs, this PR demonstrates how to subclass mesa-geo's raster cell class in case there are further changes to constructor API in the future.

@wang-boyu wang-boyu requested review from EwoutH and tpike3 February 3, 2026 14:44
@wang-boyu wang-boyu added the gis label Feb 3, 2026
@EwoutH EwoutH requested a review from quaquel February 3, 2026 16:15
@EwoutH
Copy link
Member

EwoutH commented Feb 12, 2026

Thanks for the PR! I fixed another CI issue in 9567bdf, so CI should display the state of the example models again.

It seems to fix the main issue, however, this does expose a new issue:

DeprecationWarning: Cell.pos setter is deprecated and will be read-only in a future release.

Is that also related to this PR?

Further, can we do anything about this change being breaking to user models (see mesa/mesa-geo#299 (comment))?

@wang-boyu
Copy link
Member Author

Yes this warning was introduced in mesa/mesa-geo#299. Since cells don't move, I intend to make their pos attribute to be read-only. Previously both setter and getter are available.

Could you point me to the failed github action / tests?

@EwoutH
Copy link
Member

EwoutH commented Feb 12, 2026

@wang-boyu
Copy link
Member Author

This is interesting. It's probably because there's a deprecation warning from mesa-geo on pos setter, while mesa's base agent class still tries to set agent.pos = None by default.

I can remove the deprecation warning, since it conflicts with base agent class in Mesa. In the future for Mesa-Geo it might be better not to treat cells as agents (that is, not part of AgentSet) but have a dedicated cell container such as CellCollection that behaves like AgentSet, but with no automatically assigned agent id and fixed position.

@EwoutH
Copy link
Member

EwoutH commented Feb 12, 2026

mesa's base agent class still tries to set agent.pos = None by default.

@quaquel can/should we remove this?

@quaquel
Copy link
Member

quaquel commented Feb 12, 2026

@quaquel can/should we remove this?

Not for 3.5 because of semver, but yes in 4 were it will be replaced with the Locatable protocol. No idea how that will work downstream for either agent or cell. We might just have a generic LocatableAgent class.

@wang-boyu wang-boyu merged commit 2a74f29 into mesa:main Feb 18, 2026
4 checks passed
@wang-boyu wang-boyu deleted the gis/cell-init branch February 20, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants