# THIS IS THE MAIN FILE
from numpy import *
from scipy import *
from pylab import *
import string
import os
import shutil
import sys
# 3D modules
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import param
import read
###############################################################
# PLOTTING ELEMENTAR FUNCTIONS
# ELEMENTAR FUNCTION FOR PLOTTING
def varplot(x,y,var,xlab,ylab,index,lab):
if lab == True:
figura = plot(x,y,markersize=4,marker='d',label= str(index))
else:
figura = plot(x,y,markersize=4,marker='d')
grid(True)
xlabel(xlab, color="k")
ylabel(ylab, color="k")
title("Plot for variable: " + var)
legend()
# ELEMENTAR FUNCTION FOR PLOTTING SEMILOG ON Y AXIS
def varsemilogy(x,y,var,xlab,ylab,index,lab):
if lab == True:
figura = semilogy(x,y,markersize=4,marker='d',label= str(index))
else:
figura = semilogy(x,y,markersize=4,marker='d')
grid(True)
xlabel(xlab, color="k")
ylabel(ylab, color="k")
title("Semilog plot for variable: " + var)
legend()
# ELEMENTAR FUNCTION FOR PLOTTING SEMILOG ON Y AXIS
def varloglog(x,y,var,xlab,ylab,index,lab):
if lab == True:
figura = loglog(x,y,markersize=4,marker='d',label= str(index))
else:
figura = loglog(x,y,markersize=4,marker='d')
grid(True)
xlabel(xlab, color="k")
ylabel(ylab, color="k")
title("Logarithmic plot for variable: " + var)
legend()
# ELEMENTAR FUNCTION FOR 3D PLOTTING
def threedplot(x,y,Z,xlab,ylab,var,path):
#prepare the scene
fig = plt.figure()
ax = Axes3D(fig)
X, Y = meshgrid(x, y)
#create matrix to plot (not a list as surface accepts just that)
vector = zeros((param.nz_tot-1,len(Z[0][:])))
for i in range(param.nz_tot-1):
for k in range(len(Z[0][:])):
vector[i][k] = Z[i][k]
#do the plot
surf = ax.plot_surface(X,Y,vector, rstride=1, cstride=1, cmap=cm.jet, \
linewidth=0, antialiased=False, alpha = 0.6)
#set axis limits
ax.set_xlim3d(0,len(x))
ax.set_ylim3d(0,len(y))
#set x,y,z label
ax.set_xlabel(xlab)
ax.set_ylabel(ylab)
ax.set_zlabel(var)
hold(False)
#set colorbar
fig.colorbar(surf, shrink=0.8, aspect=15)
#save the figure
fig.savefig(path + var, dpi = param.fig_dpi)
# ELEMENTAR FUNCTION FOR CONTOURING
def varcontour(x,y,Z,var,path,orient):
X, Y = meshgrid(x,y)
#define axes
if orient == "vert":
figure(figsize=(9, 2.5))
subplot(111, aspect=(1/(6.28312)))
pcolor(X, Y, Z)
xticks((0, param.nx/2, param.nx), (0, int(param.lx/2), int(param.lx)) )
yticks((0, (param.nz_tot-1)/2, param.nz_tot-1), (0, param.lz/2, param.lz) )
#labels, title, limits
xlabel("x [m]", fontsize=12, color='k')
ylabel("z [m]", fontsize=12, color='k')
title("Contour for variable:" + " " + var, fontsize=12, color='k')
xlim( (0, param.nx) )
ylim( (0, param.nz_tot-1) )
if orient == "horiz":
figure(figsize=(9, 2.5))
subplot(111, aspect=(1/(6.28312)))
figura = pcolor(X, Y, Z)
xticks((0, param.nx/2, param.nx), (0, int(param.lx/2), int(param.lx)) )
yticks((0, param.ny/2, param.ny), (0, param.ly/2, param.ly) )
#labels, title, limits
xlabel("x [m]", fontsize=12, color='k')
ylabel("y [m]", fontsize=12, color='k')
title("Contour for variable:" + " " + var, fontsize=12, color='k')
xlim( (0, param.nx) )
ylim( (0, param.ny) )
if orient == "trasv":
figure(figsize=(8, 6))
subplot(111, aspect=(1))
figura = pcolor(X, Y, Z)
xticks((0, param.ny/2, param.ny), (0, int(param.ly/2), int(param.ly)) )
yticks((0, (param.nz_tot-1)/2, param.nz_tot-1), (0, param.lz/2, param.lz) )
#labels, title, limits
xlabel("y [m]", fontsize=12, color='k')
ylabel("z [m]", fontsize=12, color='k')
title("Contour for variable:" + " " + var, fontsize=12, color='k')
xlim( (0, param.ny) )
ylim( (0, param.nz_tot-1) )
#find min and max for colorbar
maxim = -1000000000.0
minim = +1000000000.0
for i in range(len(Z[1][:])):
if min(Z[:][i]) < minim:
minim = min(Z[:][i])
if max(Z[:][i]) > maxim:
maxim = max(Z[:][i])
colorbar(orientation="vertical", fraction = 0.05, shrink = 0.5, ticks=[minim,(maxim+minim)/2.0,maxim])
#save the figure
savefig(path + var + '.png', dpi=param.fig_dpi)
# ELEMENTAR FUNCTION FOR PLOTTING
def vert_cont(var, values):
#creates the quadrilateral elements for the contour
x = arange(param.nx+1)
y = arange(param.nz_tot)
#defines path and orientation
path = param.cnt_path
orient = "vert"
#read variable and call plotting subroutine
varcontour(x,y,values,var,path,orient)
# ELEMENTAR FUNCTION FOR PLOTTING 3D SPECTRA
def vert_threed(var, values):
#create x and y vectors
x = arange(0, len(values[0][:]))
#create x and y vectors
if(var == "u" or var == "v" or var == "p"):
y = arange(0+1.0/2.0, (param.nz_tot-1.0/2.0), 1.0)
else:
y = arange(0.0, param.nz_tot-1.0, 1.0)
#defines path and orientation
path = param.three_dim_path
#read variable and call plotting subroutine
threedplot(x,y,values,"x [m]","z [m]",var,path)
## ELEMENTAR FUNCTION FOR PLOTTING 3D VERTICAL SPECTRA OF MEAN VALUES
#def fft_threed(var):
##import necessary modules
#from numpy.fft import fft, fftshift
##create x and y vectors
#x = arange(0, nx, 1)
#y = arange(0, nz_tot-1, 1)
##create the variable to plot
#for i in range(nz_tot-1):
#read.list_values[i][:] = fft(read.list_values[i][:])
##defines path and orientation
#path = fft_path
##read variable and call plotting subroutine
#read.read_avg_file(var)
#threedplot(x,y,read.list_values,"k","z [m]",var,path)
# ELEMENTAR FUNCTION FOR PLOTTING 3D AUTOCORRELATION FUNCTION OF MEAN VALUES (makes sense for mean values?)
#def autocorr_threed(var, values):
##create x and y vectors
#x = arange(0, param.nx)
#y = arange(0, param.nz_tot-1)
##create the variable to plot
#for i in range(param.nz_tot-1):
#adim = 0.00000001 #this prevents 0 division for variables such as w at level Nz=0
#for k in range(param.nx):
#adim += (values[i][k])*(values[i][k])
#values[i][:] = convolve(values[i][:],values[i][:],"same")/adim
##defines path and orientation
#path = param.corr3d_path
##read variable and call plotting subroutine
#threedplot(x,y,values,"x [m]","z [m]",var,path)
###############################################################
# PLOTTING ADVANCED FUNCTIONS
# FUNCTION TO PLOT THE AVERAGE SLICE PROFILES
def vert_avg_profiles(var, values):
interv = param.sampl_step
#create x and y vectors
if(var == "u" or var == "v" or var == "p"):
y = arange(0+1.0/2.0, (param.nz_tot-1.0/2.0), 1.0)
else:
y = arange(0.0, param.nz_tot-1.0, 1.0)
y = y/(float(param.nz_tot-1))
for i in range(0,len(values[0][:]),interv):
x = []
for k in range(param.nz_tot-1):
x.append(values[k][i])
hold(True)
if(i == 0):
hold(False)
k = 0
#create theoretical values for the log law for u
if (var == "u"):
x_theo = []
for k in range(len(y)):
x_theo.append((1.0/param.vonk)*log((y[k])/(param.z_0)))
hold(True)
varsemilogy(x,y,var,var,"Nz [m]","Nx = " + str(i),True)
varsemilogy(x_theo,y,var,var,"Nz [m]","xXx",False)
else:
varplot(x,y,var,var,"Nz [m]","Nx = " + str(i),True)
path = param.vp_path
savefig(path + var, dpi=param.