Skip to content

Remove implicit use of CRS in code base #1020

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

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

luseverin
Copy link
Collaborator

@luseverin luseverin commented Mar 6, 2025

Changes proposed in this PR:

  • Add a cheap test for functions that must be in epsg:4326 but do take only value as input to catch when input coordinates are not geographic (e.g. in meters)
  • Update functions that assume epsg:4326 without reason to be able to use other crs. (work in progress / requires more information)

This PR treats scrum user story #129 Consistent use of CRS in CLIMADA

Further information:

  • I added a quick test so function that require geographic coordinates (e.g. get_country_geometries or dist_to_coast that are based on naturalearth data) at least test that input data seems geographic. Currently allowed values are -91 < lat < 90 and -181 < lon < 541 and maximum extension of 181 (latitudinal) and 361 (longitudinal) but it is not exactly clear to me where to do the cut-off. For instance, do we want to allow longitudinal extension greater than 360, or longitudinal values smaller than -180 (some tests related to that e.g. test_track_land_params are still failing due to longitudinal extension > 360)?
  • It was specifically mentionned to treat issues in the trop_cyclone module but I was not exactly sure of what to do there. For instance, the get_close_centroids does not check that input centroids and lat and lon from the TC track are geographic; I was not sure if this should be explicitly check or if it can be left as is.
  • It was also supposed to adapt functions to allow use of other crs when possible but I did not find any instances of where this would be worth doing it or could be done without too much trouble. Some inputs on this are welcome!

PR Author Checklist

PR Reviewer Checklist

@luseverin luseverin added conventions Coding conventions or style Code update labels Mar 6, 2025
Copy link
Collaborator

@ValentinGebhart ValentinGebhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the lat lon check function! I think it is very valuable. I am not really sure in which other functions we could add it. What about:
latlon_to_geosph_vector(lat, lon, rad=False, basis=False)
lon_bounds(lon, buffer=0.0)
latlon_bounds(lat, lon, buffer=0.0)
dist_approx()
dist_to_coast_nasa()
These were all I could find in climada.util.coordinates that looked like they would require geographical coordinates. But maybe you thought about it and it does not make sense here?

I only have a few suggestions:

  • describe the error message a bit better so the user has a better idea what could be wrong and what to do about it.
  • change the range to -540 to 540 (apparently there is no convention in CLIMADA, and this seems soft enough as a error range)
  • Could you restructure the PR description a bit? It was unclear what was done and what not. Also, the link to scrum number 129 is a link to issue 129 which I think is different? For the description, e.g.

Changes proposed in this PR:

  • Add a cheap test for functions that must be in epsg:4326 but do take only value as input to catch when input coordinates are not geographic (e.g. in meters)

This PR treats scrum user story #129 Consistent use of CRS in CLIMADA

Further information:
...

Suggestions for future PRs

  • Update functions that assume epsg:4326 without reason to be able to use other crs. (work in progress / requires more information)

Check if latitude and longitude arrays are likely in geographic coordinates,
testing if min/max values are within -90 to 90 for latitude and -180 to 540
for longitude.
Returns True if lat/lon ranges are in the geographic coordinates range, otherwise False.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the numpy-style format for the docstring? See e.g. the next function latlon_to_geosph_vector

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you briefly explain in the docstring why the boundaries -180 (or -540, see comment below) to 540? I think it makes sense, but this choice should be motivated or at least explained for the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the explanation for the 540<> makes sense, let me know if this is not the case.

@@ -1596,6 +1644,12 @@ def get_country_code(lat, lon, gridded=False):
return np.empty((0,), dtype=int)
LOGGER.info("Setting region_id %s points.", str(lat.size))
if gridded:
# first check that input lat lon are geographic
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we only check lat lon if gridded=True?

Copy link
Collaborator Author

@luseverin luseverin Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.. I think it should also test when gridded=False as it then calls get_country_geometries which requires WGS84. I changed it to test regardless of gridded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code update conventions Coding conventions or style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants