Skip to content

Refactor RasterLayer: replace _initialize_cells() with NumPy-backed storage #329

Description

@Tejasv-Singh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions