From 0356b1f5680151cbf10f712bc217a0e3d0a598cd Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Sun, 2 Jul 2023 20:39:04 +0200 Subject: [PATCH 1/3] added accessor map function --- cordex/accessor.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cordex/accessor.py b/cordex/accessor.py index 876fa0b..951ec70 100644 --- a/cordex/accessor.py +++ b/cordex/accessor.py @@ -73,6 +73,44 @@ def guess(self): self._guess = _guess_domain(self._obj) return self._guess + def map(self, projection=None): + """ """ + import cartopy.crs as ccrs + import cartopy.feature as cf + import cartopy.io.img_tiles as cimgt + import matplotlib.pyplot as plt + + obj = self._obj + + mapping = obj.cf["grid_mapping"] + pole = ( + mapping.grid_north_pole_longitude, + mapping.grid_north_pole_latitude, + ) + transform = ccrs.RotatedPole(*pole) + if projection is None: + projection = transform + ax = plt.axes(projection=projection) + # use google maps tiles + request = cimgt.GoogleTiles() + ax.add_image(request, 4) # , interpolation='spline36', regrid_shape=2000) + ax.gridlines( + draw_labels=True, + linewidth=0.5, + color="gray", + xlocs=range(-180, 180, 10), + ylocs=range(-90, 90, 5), + ) + ax.set_extent( + [obj.rlon.min(), obj.rlon.max(), obj.rlat.min(), obj.rlat.max()], + crs=transform, + ) + ax.coastlines(resolution="50m", color="black", linewidth=1) + ax.add_feature(cf.BORDERS, color="black") + + return ax + # ax.set_title(CORDEX_domain) + @xr.register_dataset_accessor("cx") class CordexDatasetAccessor(CordexAccessor): From 6a921d7542c443fd9376d5b7f759733bdd2f9e0c Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Sun, 2 Jul 2023 20:44:57 +0200 Subject: [PATCH 2/3] update api docs --- cordex/accessor.py | 12 +++++++++++- docs/api.rst | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cordex/accessor.py b/cordex/accessor.py index 951ec70..a58a42a 100644 --- a/cordex/accessor.py +++ b/cordex/accessor.py @@ -74,7 +74,17 @@ def guess(self): return self._guess def map(self, projection=None): - """ """ + """Create a simple overview map. + + Creates a simple map overview. By default, the map projection + defaults to the grid mapping attribute. + + Returns + ------- + ax : GeoAxesSubplot + Cartopy plot projection using tiles. + + """ import cartopy.crs as ccrs import cartopy.feature as cf import cartopy.io.img_tiles as cimgt diff --git a/docs/api.rst b/docs/api.rst index f892c88..05fa2d8 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -106,3 +106,4 @@ Methods Dataset.cx.info Dataset.cx.guess + Dataset.cx.map From b0c9e94a1bacbb1dac2ee78cdf658b30d3e1eac5 Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Mon, 3 Jul 2023 08:58:07 +0200 Subject: [PATCH 3/3] update docs --- cordex/accessor.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cordex/accessor.py b/cordex/accessor.py index a58a42a..31403d0 100644 --- a/cordex/accessor.py +++ b/cordex/accessor.py @@ -79,6 +79,12 @@ def map(self, projection=None): Creates a simple map overview. By default, the map projection defaults to the grid mapping attribute. + Parameters + ---------- + projection : cartopy.crs + CRS used for projection. By default, the map projection + defaults to the CRS defined by the grid mapping attribute. + Returns ------- ax : GeoAxesSubplot