Skip to content

Instantly share code, notes, and snippets.

@plant99
Created September 21, 2019 17:29
Show Gist options
  • Save plant99/4bcc191a9b4797ec11b30b447447d6cb to your computer and use it in GitHub Desktop.
Save plant99/4bcc191a9b4797ec11b30b447447d6cb to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from netCDF4 import Dataset
data = Dataset('20121017_12_ecmwf_forecast.ALTITUDE_LEVELS.EUR_LL015.036.al.nc', mode='r')
lons = data.variables['lon'][:]
lats = data.variables['lat'][:]
a_p = data.variables['air_pressure'][0, :]
a_p = np.mean(a_p, axis=0)
# print(a_p, a_p.shape, data.variables)
# import sys
# sys.exit(0)
# T2M = data.variables['T2M'][:,:,:]
from mpl_toolkits.basemap import Basemap
map = Basemap(resolution='l', projection='eck4', lat_0=0, lon_0=0)
lon, lat = np.meshgrid(lons, lats)
xi, yi = map(lon, lat)
# print(T2M, T2M.shape, np.squeeze(T2M))
# import sys
# sys.exit(0)
cs = map.pcolor(xi,yi,np.squeeze(a_p), vmin=np.min(a_p), vmax=np.max(a_p), cmap=cm.jet)
cs.set_edgecolor('face')
map.drawparallels(np.arange(-90., 90., 15.), labels=[1,0,0,0], fontsize=5)
map.drawmeridians(np.arange(-180., 180., 30.), labels=[0,0,0,1], fontsize=4)
map.drawcoastlines()
map.drawstates()
map.drawcountries()
# Add colorbar:
cbar = map.colorbar(cs, location='bottom', pad="10%")
cbar.set_label('K')
cbar.ax.tick_params(labelsize=10)
# Add title:
plt.title('MERRA-2 2-meter air temperature (2010-01)')
figure = plt.figure(1)
# Save the figures as a PDF:
# figure.savefig('MERRA2_2m_airTemp_TEST.pdf', format='pdf', dpi=360)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment