-
Notifications
You must be signed in to change notification settings - Fork 54
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
Refactor RasterLayer to be based on PropertyLayer in Mesa #201
Comments
Agree on this! I don't have time to work on it, but I can provide guidance and review. |
Also need something similar to projectmesa/mesa#2336 for visualization. |
Hi, I'm happy to help with this issue. I've browsed the I don't know if they will be integrated with the |
Thanks for your interest on this! I have to say that I'm not familiar with the experimental One thing to note though is that Mesa-Geo's current Hope I'm not confusing you : ) |
@SongshGeo very cool! We will stabilize the whole cell space, likely in Mesa 3.1. In the long term, we will remove the current spaces. For now, you can regard In my (personal) vision, in the long term Mesa-geo will be integrated more tightly in Mesa. See projectmesa/mesa#2330. So I will support any changes to move in that direction. You should probably also read this issue: Let me know if you have any questions! If you want to chat directly, you can join our Matrix chat room. |
Thanks for your explanation, @EwoutH. Cool. I support the long-term integration of Mesa and Mesa-geo. But for now, I will mainly focus on changes to Mesa-geo. I haven't had much time to examine the visualization part, but I'm happy to open a PR that modifies Mesa-geo using By the way, I joined the Matrix community a long time ago. Instant messaging sometimes causes me some stress, so I prefer to communicate here. Re. the projects/mesa#2431 , I agree with what you said about using "GIS models" to imagine attributes as a "big cake". We can set multiple attributes for the same layer (i.e., a cell can have various attributes); however, agents do not need to move between different layers. We should use ideas similar to the What do you think? |
If I understand you correctly we're thinking in the same direction. I imagine agents still having a single position according to a single CRS, but being able to fetch data from multiple layers (simultaneously), which might or might not have similar CRS. Go ahead and start playing with potential solutions! Feel free to open a draft PR here early. |
Cool, that's exactly what I meant. It is good to know that we're in the same direction. I will do it this week. |
Hi, @wang-boyu and @EwoutH I have made some preliminary refactoring of All previous methods can call the experimental APIs of >>> layer.array_cells
array([[Cell((0, 3), []), Cell((1, 3), []), Cell((2, 3), [])],
[Cell((0, 2), []), Cell((1, 2), []), Cell((2, 2), [])],
[Cell((0, 1), []), Cell((1, 1), []), Cell((2, 1), [])],
[Cell((0, 0), []), Cell((1, 0), []), Cell((2, 0), [])]],
dtype=object) For another example, def add_property(
self,
data: np.ndarray | float | int | bool,
attr_name: str,
add_to_cells: bool = True,
) -> None:
"""Add a property layer to the grid."""
if isinstance(data, np.ndarray):
if data.shape != (self.height, self.width):
raise ValueError(
f"Data shape does not match raster shape. "
f"Expected {(self.height, self.width)}, received {data.shape}."
)
else:
data = np.full((self.height, self.width), data)
property_layer = PropertyLayer(
attr_name,
self.width,
self.height,
default_value=np.nan,
)
# Would be better if `PropertyLayer` had a class method to create directly from array.
property_layer.data = data
self.grid.add_property_layer(property_layer, add_to_cells) I haven't completed all function and test modifications yet; if you agree with this direction, I will continue to work on them. |
Thanks! One of the advantages of the current PropertyLayer is that it’s extremely fast, because almost all operations can be performed vectorized. If I’m correct, you now propose an array of cells. Will that retain the PropertyLayer’s performance? From an API/implementation standpoint, I’m curious what Wang thinks. @quaquel you might also be interested in this. |
Sorry, perhaps my description caused a misunderstanding. I don't think I have stored any additional |
Thanks @SongshGeo! Previously (or currently) RasterLayer is rather slow, because its Conversely Mesa's PropertyLayer is fast because the updates to it are vectorized operation applied directly on the entire layer (i.e., numpy array), e.g., https://github.com/projectmesa/mesa-examples/blob/4c25596df38618dccaa3ab0ac4e560735714c00b/examples/conways_game_of_life_fast/model.py#L30-L47. Vectorization may be a challenge for some users. I think we need to make a decision on which way to go (or both?). Btw rasterio returns numpy arrays when reading raster data: https://github.com/projectmesa/mesa-geo/blob/071724056c7670a80b0454f9ec44e4a5cffa380b/mesa_geo/raster_layers.py#L554C13-L554C36, then Mesa-Geo set it to each cell's attribute. Also the name |
@wang-boyu I support having both. I am a fan of vectorization. But you are right; this may need to be more user-friendly for some users. So, in the initial proposal I put forward, I proposed this approach.
I am quite familiar with reading data from Interesting insight! I have yet to use NetLogo's GIS; I've been looking for a Python solution from the start. I got it! Then I may continue to use the name |
Thanks for tagging me on this conversation. First of all, I am not familiar with MESA-Geo at all, so I won't be able to comment much on that side of things. However, I am rather familiar with the experimental Cell Space stuff and have been looking at how to make property layers work with those. I am also opinionated when it comes to anything that even remotely smells of NetLogo...; let's, for now, keep it at "I am not a fan" 😉. With @EwoutH, I share a desire to maximize the similarity between mesa and mesa-geo with the long-term vision of merging them. I have no idea whether this is desirable or possible, but in the meantime, let's see how far we can get. My most recent thinking on cells and property layers is captured in #2431 and #2059. That is, ideally, discrete spaces / new-style Second, new-style mesa grids entail a fundamental shift in the API. In old-style grids, everything is handled at the level of the grid, and all interactions run through the grid. In new-style grids, the cell is central. Agents interact with and via the cell with their neighborhood. So, we likely need to make a similar distinction for property layers. That is, PropertyLayers are added to grids and defined at the grid level. Cells know and can easily access/view the properties in the layers for their coordinates, and have numpy masks based on their I'll try to take a closer look at the code discussed here. If you have questions or suggestions on the mesa side of things, also please say so. |
@quaquel I appreciate your interest in this topic. I said, "I am a fan of vectorization," because I have used similar designs in I agree with placing the Thank you all for taking the time to look at my code briefly. Currently, please pay attention to how I am calling the experimental API; I have not yet made changes to the CRS part. Next week, I'd love to contribute more. |
Thanks for your work on it, it's appreciated! |
What's the problem this feature will solve?
The current implementation of
RasterLayer
includes copies of some methods frommesa.space.Grid
(see #120), making it difficult to maintain.Describe the solution you'd like
A more related class in Mesa is its recent
PropertyLayer
(projectmesa/mesa#1898).RasterLayer
could inherit fromPropertyLayer
with added geospatial capabilities.Additional context
Might also be beneficial to have part of
GeoSpace
inherit from_PropertyGrid
to manage multiple raster layers.Some related past issues:
The text was updated successfully, but these errors were encountered: