In [2]:
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import netCDF4
from datetime import datetime, timedelta
In [3]:
datapath = '/net/atmos/data/erainterim/cdf/2011/10/'
start = datetime(2011,10,5,0)
end = datetime(2011,10,10,12)
def interval(start, end, delta):
curr = start
while curr <= end:
yield curr
curr += delta
files = [ datapath + date.strftime('Z%Y%m%d_%H') for date in interval(start, end, timedelta(hours=6))]
In [4]:
files
Out[4]:
In [4]:
pfile = netCDF4.Dataset(datapath + 'pressure_cst')
print pfile.variables.keys()
pressure = pfile.variables['aklay'][:]
print pressure
pfile.close()
In [5]:
ncfile = netCDF4.MFDataset(files)
In [6]:
t = ncfile.variables['T'][:]
q = ncfile.variables['Q'][:]
Simple equation of the potential temperature $\Theta_{e}$: \begin{equation} \Theta_{e} = T \cdot (1000/P)^{0.286} + 3\cdot w \end{equation}
with T, temperature in K, P the pressure in hPa, w, mixing ratio in g kg$^{-1}$.
The mixing ratio (kg kg$^{-1}$) can be expressed as : \begin{equation} w = \frac{1}{\frac{1}{q_{v}}-1} \end{equation} with $q_{v}$, the specific humidity in kg kg $^{-1}$
In [7]:
p = 850.
index = np.where(pressure == p)[0][0]
the = (t[:, index, ...] + 273)*(1000/p)**(0.286) + 3 *1e3 *(1/((1/q[:, index, ...])-1))
In [8]:
m = Basemap(resolution='i', llcrnrlon=-50.,llcrnrlat=20.,urcrnrlon=50.,urcrnrlat=80)
In [9]:
lon = np.arange(-180,181,1)
lat = np.arange(-90,91,1)
lons, lats = np.meshgrid(lon, lat)
In [10]:
m.drawmeridians(np.arange(-180,181,10), labels=[0,0,0,1])
m.drawparallels(np.arange(-90,91,10), labels=[1,0,0,0])
m.drawcoastlines()
m.drawmapboundary()
m.drawcountries()
cf = m.contourf(lons, lats, the[-4, ...], levels = np.arange(285, 335, 5), extend='both', cmap='YlGnBu')
m.colorbar(cf)
Out[10]:
In [11]:
u = ncfile.variables['U'][:]
v = ncfile.variables['V'][:]
In [12]:
qu = q * u
qv = q * v
In [13]:
quin = 100/(9.81) * np.trapz(qu, pressure, axis=1)
qvin = 100/(9.81) * np.trapz(qv, pressure, axis=1)
ivt = np.sqrt(quin**2 + qvin**2)
In [14]:
m.drawmeridians(np.arange(-180,181,10), labels=[0,0,0,1])
m.drawparallels(np.arange(-90,91,10), labels=[1,0,0,0])
m.drawcoastlines()
m.drawmapboundary()
m.drawcountries()
cf = m.contourf(lons, lats, the[-1, ...], levels = np.arange(285, 335, 5), extend='both', cmap='YlGnBu')
m.colorbar(cf)
cf = m.contour(lons, lats, ivt[-1, ...], colors='r', levels=np.arange(0,700,200))
lb = clabel(cf, cf.levels, fmt='%1.0f')