Skip to content
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

Plotting hazards with inapt crs #865

Open
emanuel-schmid opened this issue Mar 27, 2024 · 5 comments
Open

Plotting hazards with inapt crs #865

emanuel-schmid opened this issue Mar 27, 2024 · 5 comments
Labels
accepting pull request Contribute by raising a pull request to resolve this issue! enhancement user-friendliness

Comments

@emanuel-schmid
Copy link
Collaborator

emanuel-schmid commented Mar 27, 2024

Starting from climada 5.0, the crs of a Centroids object is bound to its GeoDataFrame (centroids.gdf).

It is possible though to create a Centroids object with an inapt crs by using Centroids.from_meta and a crs like, e.g.:

<Engineering CRS: LOCAL_CS["unnamed",UNIT["unknown",1],AXIS["Easting ...>
 Name: unnamed
 Axis Info [cartesian]:
 - [east]: Easting (unknown)
 - [north]: Northing (unknown)
 Area of Use:
 - undefined
 Datum: undefined
 - Ellipsoid: undefined
 - Prime Meridian: undefined)

This can happen if the hazard object is read from a shp file. (e.g., climada_petals.hazard.landslide.Landslide.from_prob).

Any hazard object based on this will behave normally, in general, but plotting (plot_intensity) raises an error as well as to_crs.
The only remedy to fix the crs is by directly overwriting it:

haz.centroids.gdf.crs = apt_crs

I think we should possibly fix this in from_meta, but at least allow replacing a broken crs with a good one in to_crs.

@emanuel-schmid emanuel-schmid added enhancement user-friendliness accepting pull request Contribute by raising a pull request to resolve this issue! labels Mar 27, 2024
@chahank
Copy link
Member

chahank commented Mar 27, 2024

hmmm, is the crs not written into the centroids when using the Hazard.from_raster method (if not explicitly given, it uses the default one)?

@emanuel-schmid
Copy link
Collaborator Author

Why? Yes. I suppose the problem arises just because the crs is explicitly given but not suitable for plotting (or other meaningful crs handling).

@chahank
Copy link
Member

chahank commented Mar 28, 2024

Aaa sorry, I get it know. It is that the crs is not readable by cartopy.

But then the fix should be in setting the correct crs when reading the data no?

@emanuel-schmid
Copy link
Collaborator Author

I agree.

However:

  • it is obviously possible to mess up and assign a faulty crs to a GeoDataFrame
  • the GeoDataFrame cannot be set fixed by to_crs, but only by direct assignment

Therefore I think that our (the Centroids') to_crs should actually catch that error and fix it, because we don't want anybody to have to touch the gdf.

@chahank
Copy link
Member

chahank commented Mar 28, 2024

aaa good point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting pull request Contribute by raising a pull request to resolve this issue! enhancement user-friendliness
Projects
None yet
Development

No branches or pull requests

2 participants