# -*- coding: iso-8859-15 -*- ''' Created on 14.09.2012 @author: Jakob ''' from __future__ import print_function # #import matplotlib.cm as cm def plot_matrix(m): import matplotlib.pyplot as plt plt.imshow(m, interpolation='none', cmap = plt.cm.Spectral) # @UndefinedVariable plt.show() def subplot_matrix(m): import matplotlib.pyplot as plt for i in range(m.shape[2]): plt.subplot(m.shape[2]*100 + 11 + i) plt.imshow(m[:,:,i], interpolation='none', cmap = plt.cm.Spectral) # @UndefinedVariable plt.show() def plot_logfit_ensemble(e, cfg): import numpy as np import matplotlib.pyplot as plt # prepare data in lists depth = e.depth z_max = depth * cfg['logheight'] z = [] v = [] for c in e.cells: z.append(depth + c.z_position) v.append(c.velocity.magn2d() if cfg['component'] == 3 else c.velocity[cfg['component']] ) # fitted velocity profile with more points to look nicer z_dense = np.linspace(0, depth) v_dense = (2.5 * np.log(30 * z_dense / e.ks)) * e.v_shear # actual "raw" data plt.plot(v,z) plt.plot(v_dense, z_dense) plt.grid(True) plt.show() def plot_logfit_ensembles(p, cfg, initial_ensemble=100): ''' like plot_logfit_ensemble() but with interactiveness based on: http://matplotlib.org/mpl_examples/widgets/slider_demo.py ''' import matplotlib.pyplot as plt import numpy as np from matplotlib.widgets import Slider from pylab import axes # prepare data in lists depth = p.ensembles[initial_ensemble].depth z_max = depth * cfg['logheight'] z,v = [],[] for c in p.ensembles[initial_ensemble].cells: z.append(depth + c.z_position) v.append(c.velocity.magn2d()() if cfg['component'] == 3 else c.velocity[cfg['component']] ) # fitted velocity profile with more points to look nicer z_dense = np.linspace(0, depth) v_dense = (2.5 * np.log(30 * z_dense / p.ensembles[initial_ensemble].ks)) * p.ensembles[initial_ensemble].v_shear # actual "raw" data p1, = plt.plot(v,z) p2, = plt.plot(v_dense, z_dense) plt.grid(True) # update function. def update(en): en = int(en) if not p.ensembles[en].void: z = [] v = [] for c in p.ensembles[en].cells: z.append(depth + c.z_position) v.append(c.velocity.magn2d() if cfg['component'] == 3 else c.velocity[cfg['component']] ) z_dense = np.linspace(0, depth) v_dense = (2.5 * np.log(30 * z_dense / p.ensembles[en].ks)) * p.ensembles[en].v_shear p1.set_data(v,z) p2.set_data(v_dense, z_dense) ens_slider = Slider(axes([0.25, 0.1, 0.65, 0.03]), label='Ensemble', valmin=0, valmax=len(p.ensembles)-1, valinit=initial_ensemble, valfmt='%1.0f') ens_slider.on_changed(update) plt.show() def plot_logfit_profile(p, cfg): ''' plot some data regarding the estimated roughness kwargs: p ... the profile in question cfg ... config that was used for logfit_profile() ''' import numpy as np import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties data = np.zeros(shape=(len(p.ensembles), 8)) data_mask = np.zeros(shape=(len(p.ensembles), 8)) ''' array indices: 0 ks 1 tau_shear 2 v_shear 3 a a from ln(z) = a*v + b 4 b b from ln(z) = a*v + b 5 r pearson correlation coefficient 6 n numer of cells taken for fitting 7 depth ''' for i in range(len(p.ensembles)): if hasattr(p.ensembles[i], 'ks'): data[i,0] = p.ensembles[i].ks data[i,1] = p.ensembles[i].tau_shear data[i,2] = p.ensembles[i].v_shear data[i,3] = p.ensembles[i].logfit_debug[0] data[i,4] = p.ensembles[i].logfit_debug[1] data[i,5] = p.ensembles[i].logfit_debug[2] data[i,6] = p.ensembles[i].logfit_debug[4] else: data_mask[i,:] = 1 data[i,7] = p.ensembles[i].depth if p.ensembles[i].depth > 0 else 0 data_masked = np.ma.masked_array(data, data_mask) x = list(range(len(p.ensembles))) plt.figure(1) plt.subplot(311) cell_hi = [] cell_lo = [] cell_lg = [] # depth of last cell used for logfit for e in p.ensembles: if not e.void: temp = [-i.z_position for i in e.cells] cell_hi.append(min(temp)) # topmost cells cell_lo.append(max(temp)) # lowest cells z_max = e.depth * (1 - cfg['logheight'] ) cell_lg.append(max([z if z