Last active
May 27, 2021 08:38
-
-
Save davidmnielsen/9cbf59f217cd505ed6bc4edc7054acde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env/python | |
import matplotlib.pyplot as plt | |
from matplotlib import cm | |
import cartopy.crs as ccrs | |
import xarray as xr | |
import numpy as np | |
file='/pool/data/MPIOM/GR15/GR15L40_fx.nc' | |
ds=xr.open_dataset(file,decode_times=False) | |
area=ds['area'].values | |
area=np.squeeze(area) | |
lat=ds['lat'].values | |
lon=ds['lon'].values | |
factor=1/1000000 | |
def circlemap(ax): | |
''' | |
This makes the cicular frame for Arctic maps. | |
''' | |
import numpy as np | |
import matplotlib.path as mpath | |
theta = np.linspace(0, 2*np.pi, 100) | |
center, radius = [0.5, 0.5], 0.5 | |
verts = np.vstack([np.sin(theta), np.cos(theta)]).T | |
circle = mpath.Path(verts * radius + center) | |
ax.set_boundary(circle, transform=ax.transAxes) | |
fig = plt.figure(figsize=(14, 10)) | |
ax = fig.add_subplot(111,projection=ccrs.NorthPolarStereo()) | |
ax.set_extent([-180, 180, 63, 90], crs=ccrs.PlateCarree()) | |
ax.coastlines() | |
ps.circlemap(ax) # comment to remove the circular frame | |
mesh = ax.pcolormesh(lon, lat, area*factor, cmap='Blues', transform=ccrs.PlateCarree(), | |
# antialiased=True, edgecolor='k', linewidth=0.3, # Uncomment to show lines for grid-cell boundarie | |
vmin=0, vmax=10000,) | |
cbar=plt.colorbar(mesh, orientation='vertical', shrink=0.75) | |
cbar.set_label('grid-cell area [km$^2$]',fontsize=16) | |
cbar.ax.tick_params(labelsize=14) | |
plt.show() |
Author
davidmnielsen
commented
May 27, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment