Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a separate method for setting up cells when initialize RasterLayer #258

Open
SongshGeo opened this issue Nov 1, 2024 · 1 comment
Labels
enhancement Release notes label

Comments

@SongshGeo
Copy link

What's the problem this feature will solve?

Hi, long time no see.

I browsed and tested the source code of Mesa 3.0 and the latest compatible mesa-geo version, and I like the new framework. To provide users with an interface for modification, I hope to create a separate method for setting up cells when refactoring RasterLayer rather than specifying everything in __init__.

Describe the solution you'd like

Specifically, after the Mesa 3.0 version, I tried to directly inherit RasterLayer in my ABSESpy and add my Cell class, but there was no such overridable interface. So I made the following changes to the mesa-geo source code:

    def __init__(
        self, width, height, crs, total_bounds, model, cell_cls: type[Cell] = Cell
    ):
        super().__init__(width, height, crs, total_bounds)
        self.model = model
        self.cell_cls = cell_cls
        self._setup_cells()
        self._attributes = set()
        self._neighborhood_cache = {}

    def _setup_cells(self) -> None:
        self.cells = []
        for x in range(self.width):
            col: list[self.cell_cls] = []
            for y in range(self.height):
                row_idx, col_idx = self.height - y - 1, x
                col.append(self.cell_cls(self.model, pos=(x,y), indices=(row_idx,col_idx)))
            self.cells.append(col)

Additional context

I saw an interesting discussion about refactoring this class in #81. I think it's a good idea, and I will also try to find somewhere to contribute.

@wang-boyu wang-boyu added the enhancement Release notes label label Nov 2, 2024
@wang-boyu
Copy link
Member

Thanks for your interest in this. Would you like to take a look at the PropertyLayer from Mesa, since RasterLayer are essentially the geo versions of PropertyLayer? I have raised #201 for it. Some of its usages are mentioned in projectmesa/mesa#2440.

SongshGeo added a commit to SongshGeo/mesa-geo that referenced this issue Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Release notes label
Projects
None yet
Development

No branches or pull requests

2 participants