Skip to content

Commit

Permalink
added ccrs module
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbuntemeyer committed Feb 25, 2024
1 parent ed2b045 commit 45bfdf0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cordex/ccrs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from cartopy import crs as ccrs

crs_map = {
"rotated_latitude_longitude": {
"crs": ccrs.RotatedPole,
"kwargs": {
"pole_longitude": "grid_north_pole_longitude",
"pole_latitude": "grid_north_pole_latitude",
"central_rotated_longitude": 0.0,
},
}
}


def _ccrs_from_cf(mapping):
crs = crs_map.get(mapping.grid_mapping_name)
kwargs = {kw: (mapping.attrs.get(v) or v) for kw, v in crs["kwargs"].items()}
return crs["crs"](**kwargs)


def get_ccrs(ds):
mapping = ds.cf["grid_mapping"]
return _ccrs_from_cf(mapping)

0 comments on commit 45bfdf0

Please sign in to comment.