Created
September 27, 2019 09:55
-
-
Save plant99/53bce5dc889ef97486efe5f5b77551ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from netCDF4 import Dataset | |
data = Dataset('MERRA2_300.tavgM_2d_slv_Nx.201001.nc4', mode='r') | |
lons = data.variables['lon'][:] | |
lats = data.variables['lat'][:] | |
T2M = data.variables['T2M'][:,:,:] | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.cm as cm | |
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(T2M), vmin=np.min(T2M), vmax=np.max(T2M), 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