SHARE
TWEET

Untitled

a guest Oct 15th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from netCDF4 import Dataset
  2. data = Dataset('MERRA2_300.tavgM_2d_slv_Nx.201001.nc4', mode='r')
  3. lons = data.variables['lon'][:]
  4. lats = data.variables['lat'][:]
  5. T2M = data.variables['T2M'][:,:,:]
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. import matplotlib.cm as cm
  9. from mpl_toolkits.basemap import Basemap
  10. map = Basemap(resolution='l', projection='eck4', lat_0=0, lon_0=0)
  11.  
  12. lon, lat = np.meshgrid(lons, lats)
  13. xi, yi = map(lon, lat)
  14. # print(T2M, T2M.shape, np.squeeze(T2M))
  15. # import sys
  16. # sys.exit(0)
  17. cs = map.pcolor(xi,yi,np.squeeze(T2M), vmin=np.min(T2M), vmax=np.max(T2M), cmap=cm.jet)
  18. cs.set_edgecolor('face')
  19. map.drawparallels(np.arange(-90., 90., 15.), labels=[1,0,0,0], fontsize=5)
  20. map.drawmeridians(np.arange(-180., 180., 30.), labels=[0,0,0,1], fontsize=4)
  21.  
  22. map.drawcoastlines()
  23. map.drawstates()
  24. map.drawcountries()
  25.  
  26.  
  27. # Add colorbar:
  28. cbar = map.colorbar(cs, location='bottom', pad="10%")
  29. cbar.set_label('K')
  30. cbar.ax.tick_params(labelsize=10)
  31.  
  32. # Add title:
  33. plt.title('MERRA-2 2-meter air temperature (2010-01)')
  34.  
  35. figure = plt.figure(1)
  36.  
  37. # Save the figures as a PDF:
  38. # figure.savefig('MERRA2_2m_airTemp_TEST.pdf', format='pdf', dpi=360)
  39. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top