In [18]:
%pylab inline
rcParams['figure.figsize'] = (10,6)
from scipy import interpolate
from lagranto import Tra
from mpl_toolkits.axes_grid1 import AxesGrid
import matplotlib.gridspec as gridspec
from mpl_toolkits.basemap import Basemap
from matplotlib.collections import LineCollection
In [2]:
filename = 'data/lsl_20070119_12_ana_48'
trajs = Tra(filename)
print trajs
print trajs.shape
In [3]:
ilevels = np.arange(200,1000,50)
nlev = len(ilevels)
In [4]:
def interp(pvalue, intvalue):
interpfield = interpolate.interp1d(pvalue[::-1], intvalue[::-1], bounds_error=False)
return interpfield(ilevels)
In [5]:
ntrajs = {}
variables = ['Q', 'RH', 'TH', 'PV']
for var in variables:
ntrajs[var] = np.zeros((trajs.ntra, nlev))
for i, traj in enumerate(trajs):
for var in variables:
ntrajs[var][i, :] = interp(traj['P'], traj[var])
In [19]:
ax = subplot(111)
mean = np.nanmean(ntrajs['PV'], axis=0)
std = np.nanstd(ntrajs['PV'], axis=0)
pstd = mean + std
mstd = mean - std
_ = fill_between(ilevels, pstd, mstd, alpha=0.5, label='+/- standar deviation')
_ = plot(ilevels, np.nanmean(ntrajs['PV'], axis=0), 'r', label='mean')
_ = xticks(ilevels)
ax.invert_xaxis()
legend()
Out[19]:
In [7]:
def plot_mean_std(pos, var):
ax = subplot(pos)
mean = np.nanmean(ntrajs[var], axis=0)
std = np.nanstd(ntrajs[var], axis=0)
pstd = mean + std
mstd = mean - std
mins = np.nanmin(mstd)
maxs = np.nanmax(pstd)
ax.set_title(var)
_ = ax.fill_between(ilevels, pstd, mstd, alpha=0.5, label='+/- standar deviation')
_ = ax.plot(ilevels, np.nanmean(ntrajs[var], axis=0), 'r', label='mean')
_ = ax.set_xticks(ilevels)
ax.invert_xaxis()
legend()
In [8]:
fig = figure(figsize=(20,20))
grid = gridspec.GridSpec(2,2, wspace=0.1, hspace=0.1)
for box, var in zip(grid, variables):
plot_mean_std(box, var)
In [20]:
scatter(trajs['Q'], trajs['PV'], c=trajs['P'])
colorbar()
Out[20]:
In [21]:
ax = subplot(111)
bplot = boxplot(ntrajs['TH'], sym='')
for line in bplot['medians']:
line.set_color('k')
ax.set_xticklabels([str(level) for level in ilevels])
ax.invert_xaxis()
In [11]:
lllon,urlon = trajs['lon'].min(), trajs['lon'].max()
lllat,urlat = trajs['lat'].min(), trajs['lat'].max()
mapf = Basemap(llcrnrlon=lllon,llcrnrlat=lllat, urcrnrlon=urlon, urcrnrlat=urlat, resolution='i')
In [22]:
mapf.drawcoastlines()
mapf.plot(trajs['lon'].T, trajs['lat'].T, latlon=True, color='k')
title('Trajectories')
Out[22]:
In [23]:
mapf.drawcoastlines()
for traj in trajs:
points = np.array([traj['lon'], traj['lat']]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
lc = LineCollection(segments, cmap=plt.get_cmap('Spectral'))
lc.set_array(traj['P'])
plt.gca().add_collection(lc)
colorbar(lc)
Out[23]:
In [ ]: