Problem
RasterLayer._initialize_cells() runs an O(N×M) nested loop that
instantiates one Python Cell object per pixel at startup. A 1000×1000
raster means one million object instantiations, gigabytes of memory overhead,
and minutes of initialization time before a simulation can run.
Proposed Change
- Delete
_initialize_cells() and all O(N×M) loops
- Store each band as a raw NumPy array in a plain dict:
self._data: dict[str, np.ndarray] = {}
- Implement
create_band(), add_band(), remove_band()
- Rewrite
apply_raster() and get_raster() to operate directly on these
arrays
Implementation Notes
- Internal dict named
_data: private, not part of the public API
apply_raster() must handle CRS alignment via np.flip(..., axis=0).T
when mapping rasterio GeoTIFF data (origin top-left) to geographic CRS
(origin bottom-left). Getting this wrong produces a silently mirrored raster
with no error thrown.
Reference
cc @wang-boyu @jackiekazil
Problem
RasterLayer._initialize_cells()runs an O(N×M) nested loop thatinstantiates one Python
Cellobject per pixel at startup. A 1000×1000raster means one million object instantiations, gigabytes of memory overhead,
and minutes of initialization time before a simulation can run.
Proposed Change
_initialize_cells()and all O(N×M) loopscreate_band(),add_band(),remove_band()apply_raster()andget_raster()to operate directly on thesearrays
Implementation Notes
_data: private, not part of the public APIapply_raster()must handle CRS alignment vianp.flip(..., axis=0).Twhen mapping rasterio GeoTIFF data (origin top-left) to geographic CRS
(origin bottom-left). Getting this wrong produces a silently mirrored raster
with no error thrown.
Reference
cc @wang-boyu @jackiekazil