-
Notifications
You must be signed in to change notification settings - Fork 65
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
add layers into geospace #67
Conversation
2140fac
to
7c3e649
Compare
Codecov Report
@@ Coverage Diff @@
## master #67 +/- ##
=========================================
Coverage ? 78.23%
=========================================
Files ? 5
Lines ? 363
Branches ? 0
=========================================
Hits ? 284
Misses ? 79
Partials ? 0 Continue to review full report at Codecov.
|
hmm let me look into the dependency issue in python 3.10 |
|
7c3e649
to
6f3cb72
Compare
Thanks for the reply! My concern with setting Instead, the point of having it to be |
For the |
That is exactly my point. There is no alternative to converting the crs, so why require the extra step of doing a) or b) ? |
Yes, there is no alternative to converting the crs to the same one. The question is, should the users be notified about any crs inconsistency and conversion? If space = GeoSpace()
space.add_layer(a_raster_layer_of_epsg_4326)
space.add_layer(a_geodataframe_of_epsg_4326)
space.add_agents(some_agents_of_epsg_4326)
# Surprise! Everything is in epsg:3857 now. |
Yes it shouldn't happen silently as a side effect, it should be a feature! That is, the function of add_agents is to add agents to the GeoSpace by converting their CRS to the crs of the GeoSpace. If we add to this to the docstring and also mention it again in the tutorial that should be sufficient information imho |
Very good! My apologies but I can't stop myself from thinking about this meme Ok, so in summary, we have two options:
@Corvince prefers Option 1 and I'm leaning towards Option 2. @rht @tpike3 What do you think? Please feel free to come up with more options : ) |
I am on vacation and mobile so I cannot verify this, but have you tested the original idea of raising just a warning? Because from how I understand it after reading about issuing warnings, they should actually only display once!? So the main concern about hundreds of warnings could be dismissed. This could be option 3) https://docs.python.domainunion.de/3/library/warnings.html#the-warnings-filter |
This is very interesting to know, and you're right! By default -
so there are not repeated warnings for GeoAgents. I tried it just now and it indeed worked like this. In this case the parameter probably won't be named as Option 3: Always automatically convert layers/agents to the crs of GeoSpace if they're different. Have a Option 3 is my favorite now : ) |
Voting for option 3. Didn't know that you could make it display only once. |
6f3cb72
to
dc0e706
Compare
Implemented Option 3. Ready for review now. |
Great! Could you just make the warning option a kwarg? If we then add more options to GeoSpace later it won't be API breaking (without warning being always the second argument) |
In the last commit, I didn't see any code that would result in the warning being printed only once. It seems that users will have to manually do this:
This is not ideal. There is another way to display the warning only once. Define an attribute |
Let me try to explain this. For the following code (which is the default behavior): 1 for _ in range(10):
2 warnings.warn("This is a warning.")
3
4 for _ in range(10):
5 warnings.warn("This is a warning.") we will end up with two warnings instead of 20, one from line 2, the other one from line 5. If we change from default to "once": 1 warnings.filterwarnings("once")
2
3 for _ in range(10):
4 warnings.warn("This is a warning.")
5
6 for _ in range(10):
7 warnings.warn("This is a warning.") There is going to be only one warning, since the messages from line 4 and line 7 are the same. In our case, I think the default behavior is good enough - one warning for hundreds of agents. |
dc0e706
to
014b8c8
Compare
Not sure if I've done it correctly, but I put |
OK, that's fine then. |
Is there anything else that I should change for this PR...? |
mesa_geo/geospace.py
Outdated
|
||
from mesa_geo.geoagent import GeoAgent | ||
|
||
|
||
class GeoSpace: | ||
def __init__(self, crs="epsg:3857"): | ||
def __init__(self, crs="epsg:3857", **kwargs): |
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.
Why is this **kwargs
instead of just explicitly adding warn_crs_conversion
?
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.
I think this comment means just a single keyword argument.
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.
@Corvince Would you like to clarify? I'm a bit confused whether it's a single keyword argument or kwargs
here.
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.
I get it! warn_crs_conversion
is now a keyword-only argument with default value of True
.
014b8c8
to
cdf4e0e
Compare
cdf4e0e
to
597c988
Compare
597c988
to
03fc861
Compare
a52759d
to
96fc4d3
Compare
Is there any more changes that are needed in order to merge this PR? |
LGTM from my end. If @Corvince doesn't merge this within a day, I will do it. |
I don't have the time atm to do a proper review, so I'll just merge this with just a quick look. Bit I am really excited about this one, because I was always quite clueless how to combine raster and vector data |
Thanks a lot for the help guys! Appreciate the comments. I will keep working on raster layers for the next PR, and will need your feedback too : ) |
This PR attempts to add Raster and Vector (GeoDataFrame) layers into GeoSpace. The component diagram looks like below:
Before it is ready to merge, the main issue is, there is a
auto_convert_crs
parameter in theGeoSpace.add_layer()
method, similar toGeoSpace.add_agents()
, which is really annoying. Image the users have sources of data with different crs from the GeoSpace. To avoid errors, they will have to:But we still need this parameter, due to the same reason as GeoAgents. Shall we do something like this instead -
Or is there any other better way?