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

Map #142

Merged
merged 3 commits into from
Jul 3, 2023
Merged

Map #142

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions cordex/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,60 @@ def guess(self):
self._guess = _guess_domain(self._obj)
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.

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
Cartopy plot projection using tiles.

"""
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):
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ Methods

Dataset.cx.info
Dataset.cx.guess
Dataset.cx.map
Loading