cf-xarray icon indicating copy to clipboard operation
cf-xarray copied to clipboard

add `DataArray.cf.get_pyproj_crs()`

Open larsbuntemeyer opened this issue 2 years ago • 10 comments

Woud be nice to have a cf function that generates CRS from grid_mappings that cartopy can understand for plotting. Would be nice to simply work without having to know which mapping is present, e.g., no need to pick the required cartopy CRS by hand.

Continue the dicussions started here:

  • https://github.com/xarray-contrib/cf-xarray/pull/370
  • https://github.com/xarray-contrib/cf-xarray/pull/391#discussion_r1085606126

Related issues:

  • https://github.com/SciTools/cartopy/issues/2099

larsbuntemeyer avatar Jan 24 '23 19:01 larsbuntemeyer

For the cartopy case, this seems to have been an issue for some time now.

  • https://github.com/SciTools/cartopy/issues/813

I am unsure, why this seems to be complicated (also it should not?)...

A possible workaround before going upstream: we could use a couple of mappings that simply map cf grid_mapping_name to the appropriate cartopy CRS (including **kwargs).

larsbuntemeyer avatar Jan 27 '23 11:01 larsbuntemeyer

Those of us developing Iris are equally frustrated around this topic:

  • SciTools/iris#4643
  • SciTools/cartopy#2039

Apologies for my incomplete understanding of this area, I believe the two links I have provided are relevant, although there may be others.

trexfeathers avatar Jan 30 '23 11:01 trexfeathers

@dcherian I have some code that i now use regularly to do transformations based on grid mappings using pyproj:

https://github.com/euro-cordex/py-cordex/blob/90e18d1bf020b3b869d9d2ffcc7039a63a92f176/cordex/transform.py#L77-L175

I also use that to compute boundaries by transforming the linear x, y boundaries according to the grid mapping info. I was wondering if that could have a place here in a kind of mapping class, e.g., as an option in _guess_bounds... also pinging @aulemahal here...

larsbuntemeyer avatar Feb 15 '23 19:02 larsbuntemeyer

I think the transformations should be in rioxarray already?

cc @snowman2

dcherian avatar Feb 15 '23 20:02 dcherian

Ahh, nice! Yes, you mentioned that in the roadmap. I'll check it out.

larsbuntemeyer avatar Feb 15 '23 21:02 larsbuntemeyer

https://pyproj4.github.io/pyproj/stable/build_crs_cf.html

snowman2 avatar Feb 15 '23 22:02 snowman2

https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html

snowman2 avatar Feb 15 '23 22:02 snowman2