%matplotlib inline
import matplotlib.pylab as plt

from netCDF4 import Dataset


f = Dataset('http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/air.sig995.2012.nc')

air = f.variables['air']
lat = f.variables['lat'][:]
lon = f.variables['lon'][:]

plt.imshow(air[0,:,:])
plt.colorbar();

air_c = air[:]  - 273.15


plt.imshow(air_c[0,:,:])
plt.colorbar()

"""
Explanation: Simple Plot
https://github.com/koldunovn/python_for_geosciences/blob/master/05%20-%20Graphs%20and%20maps%20(Matplotlib%20and%20Basemap).ipynb
End of explanation
"""


import cartopy
import cartopy.crs as ccrs

#ax = plt.axes(projection=ccrs.PlateCarree())
ax = plt.axes(projection=ccrs.Mollweide())
plt.contourf(air[0,:,:])
ax.coastlines()
plt.colorbar()

"""
Explanation: Plot with cartopy
https://github.com/koldunovn/python_for_geosciences/blob/master/07%20-%20Other%20modules%20for%20geoscientists.ipynb
End of explanation
"""


import iris
import iris.quickplot as qplt

iris.FUTURE.netcdf_promote = True
temperature = iris.load_cube('http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/surface/air.sig995.2012.nc')



qplt.contourf(temperature[0,:,:])
#gca().coastlines()

zonal_mean = temperature.collapsed('latitude', iris.analysis.MEAN)


qplt.contourf(zonal_mean)

#Code is a bit more complicated in order to fix issue with dates formating
fig = plt.figure()
qplt.plot(temperature[:,10,10])
fig.autofmt_xdate()

qplt.plot(temperature[0,:,10])

"""
Explanation: Plot with Cartopy and Iris
End of explanation
"""


