-
Notifications
You must be signed in to change notification settings - Fork 58
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
remove __geo_interface__ functions #40
Conversation
268fadb
to
3193d28
Compare
Make sense. I'm up for attribute names in projectmesa/mesa to be renamed to |
You should resolve the merge conflict by |
6b6bce8
to
f595397
Compare
Done. (But this rewrites the history and need to force a push.) |
mesa_geo/visualization/MapModule.py
Outdated
feature_collection = {"type": "FeatureCollection", | ||
"features": [ | ||
{"type": "Feature", | ||
"geometry": mapping(transform(model.space.Transformer.transform, agent.shape)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for mapping(transform(model.space.Transformer.transform, agent.shape))
to be wrapped as a method of GeoAgent
, maybe get_geometry
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, although agent.get_geometry()
will probably just return agent.shape
. model.space.Transformer
then transforms agents' coordinates to be consistent with Leaflet's default epsg:4326
crs. (But why does GeoSpace
know the default crs of MapModule
and do the transformation?)
The current crs settings in mesa-geo are a bit convoluted and inconsistent (for example #20). I'll raise an issue regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapping(transform(model.space.Transformer.transform, agent.shape))
is way too long, and so I think it would be helpful to package it in a method. Maybe call it instead agent.get_transformed_geometry
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup this looks better. Added the new function.
This makes me wonder whether agent.shape
should be renamed to agent.geometry
to be consistent with the GeoDataFrame (as mentioned in #37). But we can do this in a separate PR.
Make sure to not make another PR after this one, unless it is for flake8 and Black fixes. Otherwise, the merge conflicts would be nasty. |
@@ -32,19 +31,6 @@ def step(self): | |||
"""Advance one step.""" | |||
pass | |||
|
|||
def __geo_interface__(self): | |||
"""Return a GeoJSON Feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By definition, the output of __geo_interface__
seems to be JSON-serializable. If it is not, then the problem is in the implementation. Are you sure this is not needed elsewhere? You could at least just not use __geo_interface__
in the visualization render()
, without deleting this method. I haven't used Mesa-Geo much to be able to tell which should be the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was used in the MapModule.render()
function, and the GeoSpace.__geo_interface__
function, which was not used and similarly deleted. I guess it's a similar idea from geopandas.GeoDataFrame.__geo_interface__
There're three problems if we implement this method properly:
- By definition all attributes of an agent should be json serialised. Each agent has a
model
attribute, i.e.,agent.model
, which is currently serialised asstr(self.model)
(but why?). Plus, the users need to make sure that all additional fields in their self-definedGeoAgent
are json serialisable. - Not all attributes are necessary for frontend visualisation. This links to Exclude some GeoAgents attributes from visualization #32 and is the motivation of this PR. The necessary properties for visualisation are set by
MapModule.portrayal_method()
which is outsideGeoAgent
. - This method is not used anywhere else apart from
MapModule.render()
.
Options:
- We fix it, and keep it. This might leads to further issues from users (or not).
- We do nothing and keep it. Again this might leads to further issues from users (or not).
- We delete it, bring it back in the future if needed, and fix it then.
Do you have any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.model
is probably a complex beast, and hence why only the str
of it becomes its serialized version.
From reading that geopandas.org documentation, I see that __geo_interface__
is needed for GeoJSON serialization in the future, and hence, not necessarily for visualization. We might want the simulation state (which includes the agents) to be serializable, so that it can be resumed at a different time, on a different machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep this PR small and hopefully mergeable soon, I think we should just do nothing about __geo_interface__
for now. We can delete/fix it in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've added them back.
Codecov Report
@@ Coverage Diff @@
## master #40 +/- ##
=========================================
Coverage ? 49.00%
=========================================
Files ? 5
Lines ? 302
Branches ? 0
=========================================
Hits ? 148
Misses ? 154
Partials ? 0 Continue to review full report at Codecov.
|
OK, the last thing is if you could squash the 4th commit into the 1st commit via the interactive rebase, since they logically are within the same theme. |
bring back __geo_interface__ functions
3c454ab
to
64e1676
Compare
Done! |
model.grid
tomodel.space
for better naming convention, sinceGeoSpace
is not necessarily agrid
.