Skip to content

Commit

Permalink
refactor(api): ♻️ Create a separate method for setting up cells when …
Browse files Browse the repository at this point in the history
…initialize RasterLayer

projectmesa#258
  • Loading branch information
SongshGeo committed Nov 8, 2024
1 parent 0717240 commit 631dc59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,5 @@ pip-log.txt
mesa_geo/visualization/templates/css/*
mesa_geo/visualization/templates/js/*
!mesa_geo/visualization/templates/js/MapModule.js

playground.ipynb
2 changes: 1 addition & 1 deletion mesa_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]

__title__ = "Mesa-Geo"
__version__ = "0.9.0a1"
__version__ = "0.9.0rc1"
__license__ = "Apache 2.0"
_this_year = datetime.datetime.now(tz=datetime.timezone.utc).date().year
__copyright__ = f"Copyright {_this_year} Project Mesa Team"
21 changes: 14 additions & 7 deletions mesa_geo/raster_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ class RasterLayer(RasterBase):
whereas it is `self.cells: List[List[Cell]]` here in `RasterLayer`.
"""

cells: list[list[Cell]]
_neighborhood_cache: dict[Any, list[Coordinate]]
_attributes: set[str]

Expand All @@ -224,16 +223,24 @@ def __init__(
super().__init__(width, height, crs, total_bounds)
self.model = model
self.cell_cls = cell_cls
self.cells = []
self._setup_cells()
self._attributes = set()
self._neighborhood_cache = {}

def _setup_cells(self):
self._cells = []
for x in range(self.width):
col: list[cell_cls] = []
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(model, pos=(x, y), indices=(row_idx, col_idx)))
self.cells.append(col)
col.append(
self.cell_cls(self.model, pos=(x, y), indices=(row_idx, col_idx))
)
self._cells.append(col)

self._attributes = set()
self._neighborhood_cache = {}
@property
def cells(self) -> list[list[Cell]]:
return self._cells

@property
def attributes(self) -> set[str]:
Expand Down

0 comments on commit 631dc59

Please sign in to comment.