mesa-geo
mesa-geo copied to clipboard
Cell aggregation API in raster layer
What's the problem this feature will solve?
Currently if the users would like to find the min/max cell based on certain criteria, they'll have to it manually like this:
min(raster_layer.get_neighboring_cells(pos, ...),
key=lambda cell: cell.attribute)
Describe the solution you'd like
To have a more powerful and fluent API for cell aggregation similar to Pandas, e.g.,
raster_layer.get_neighboring_cells(pos, ...).by("attribute").min()
raster_layer.get_neighboring_cells(pos, ...).by(lambda cell: cell.attribute).min()
raster_layer.get_neighboring_cells(pos, ...).by(["attribute_0", "attribute_1"]).agg(["min", "max"])
raster_layer.get_neighboring_cells(pos, ...).by("attribute").agg(lambda cell_list: random.choice(cell_list))
Additional context
See comments from https://github.com/projectmesa/mesa-geo/pull/75#issuecomment-1174487599.