In [38]:
%matplotlib inline
In [39]:
import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt
In [40]:
nc.Dataset('air.mon.1981-2010.ltm.nc')
Out[40]:
In [41]:
air = nc.Dataset('air.mon.1981-2010.ltm.nc')
In [42]:
print air
In [43]:
air.variables
Out[43]:
In [44]:
air.variables['lat']
Out[44]:
In [45]:
lat = air.variables['lat'][:]
In [46]:
print lat
In [47]:
air
Out[47]:
In [48]:
air.variables['air']
Out[48]:
In [49]:
lon = air.variables['lon'][:]
In [50]:
lon
Out[50]:
In [51]:
air.variables['time']
Out[51]:
In [52]:
time = air.variables['time'][:]
In [53]:
time
Out[53]:
In [54]:
temperature = air.variables['air'][:]
In [55]:
temperature.shape
Out[55]:
In [56]:
lat
Out[56]:
In [57]:
lat[19]
Out[57]:
In [58]:
temperature[:,:,19,:].shape
Out[58]:
In [59]:
lon
Out[59]:
In [60]:
360 - 73
Out[60]:
In [61]:
done = False
n = 0
while not done:
if (lon[n] == 287.5):
print n
done = True
else:
n += 1
In [62]:
lon[115]
Out[62]:
In [63]:
lon_index_albany = 115
lat_index_albany = 19
In [64]:
temperature[:,:, lat_index_albany, lon_index_albany].shape
Out[64]:
In [65]:
lev = air.variables['level']
In [66]:
lev
Out[66]:
In [67]:
lev = air.variables['level'][:]
In [68]:
lev
Out[68]:
In [69]:
lev[0]
Out[69]:
In [70]:
temperature[:, 0, lat_index_albany, lon_index_albany]
Out[70]:
In [71]:
plt.plot(temperature[:, 0, lat_index_albany, lon_index_albany])
Out[71]:
In [72]:
air.variables['air']
Out[72]:
In [73]:
months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
In [37]:
plt.plot(temperature[:, 0, lat_index_albany, lon_index_albany])
plt.xticks(months)
In [74]:
jan = temperature[0, :, lat_index_albany, lon_index_albany]
In [75]:
print jan
In [76]:
jan.shape
Out[76]:
In [77]:
lev.shape
Out[77]:
In [78]:
lev
Out[78]:
In [79]:
# approximate vertical height axis in km
Z = -8 * np.log(lev/lev[0])
print Z
In [80]:
plt.plot(jan, Z, label='Jan')
plt.legend()
plt.xlabel('Temperature (deg C)')
plt.ylabel('height (km)')
Out[80]:
In [81]:
for n in range(12):
data = temperature[n, :, lat_index_albany, lon_index_albany]
plt.plot(data, Z, label=months[n])
plt.legend()
plt.xlabel('Temperature (deg C)')
plt.ylabel('height (km)')
plt.xlim(-70, 50)
Out[81]:
In [82]:
# plot cross section of zonal and annual average temperature as function of height and latitude
temp_zon = np.mean(temperature, axis=3)
In [83]:
temp_zon.shape
Out[83]:
In [84]:
temp_zon_ann = np.mean(temp_zon, axis=0)
In [85]:
temp_zon_ann.shape
Out[85]:
In [86]:
temp_zon_ann = np.mean(temperature, axis=(0,3))
In [87]:
temp_zon_ann.shape
Out[87]:
In [88]:
cax = plt.contourf(lat, Z, temp_zon_ann)
plt.colorbar(cax)
plt.xlabel('Latitude')
plt.ylabel('height (km)')
plt.title('Annual, zonal average observed air temperature', fontsize=14)
Out[88]:
In [ ]:
In [ ]: