############################################################################### # Auteurs : Najda Villefranque # Modif 2017/12/15 : F. Hourdin # Reads z-t files from LES and SCM stored in DATA/ # SMC001.nc, SCM002.nc, ... and same for LES # Calcule les metriques. Plusieurs options a completer # Modif 2018/08/17 : N. Villefranque # Added radiation metrics # Do not call plot_setup # zmax is now an argument of get_metric ############################################################################### library("ncdf4") # to manipulate ncdf # I comment this because I think it is better to keep independent modules # I think zmax should be given as a parameter to get_metric #pltsu<-plot_setup(case_name,plotvar) #zmax=pltsu[3] ############################################################################# # Compute the height of maximum nebulosity ############################################################################# compute_zhneb <- function(zval,neb,zmax,varname) { lm=dim(neb)[2] km=dim(neb)[1] # nebzave, neb2zave, neb4zave # Computes the mean altitude of clouds as the integral on the vertical # of the altitude times a wheight f**np where np is a positive integer # For large values of np, the altitude is that of the maximum cloud fraction if ( ( varname == "nebzave" ) | ( varname == "neb2zave" ) | ( varname == "neb4zave" ) ) { if ( varname == "nebzave" ) {pn=1} else { if (varname == "neb2zave") {pn=2} else {pn=4} } rm=rep(0,lm) hm=rep(0,lm) nebzave=rep(0,lm) # finding for (k in 2:km-1) { if (zval[k+1] eff_ratio*nebmax[l] ) { nebzmin[l]=min(nebzmin[l],zval[k]) nebzmax[l]=max(nebzmax[l],zval[k]) } } } if ( nebzmin[l] == 99999999. ) { nebzmin[l]=0. } if ( nebzmax[l] == -1. ) { nebzmax[l]=0. } } if ( varname == "nebzmin" ) { return(nebzmin) } else { if ( varname == "nebzmax" ) { return(nebzmax) } else { print(c("variable ",varname," non prevue")) } } } } } ############################################################################# # Compute liquid water path ############################################################################# compute_Ay <- function(zval,vvv,zmax,varname) { # Computes the mean altitude of clouds lm=dim(vvv)[2] km=dim(vvv)[1] rm=matrix(0.,lm) hm=matrix(0.,lm) Ay=matrix(0.,lm) evol<-matrix(0.,km,lm) if ( substr(varname,1,5) == "theta" ) { for (l in 1:lm) { for (k in 1:km) { evol[k,l]=min(vvv[k,l]-vvv[k,1],0.) } } } else { for (l in 1:lm) { for (k in 1:km) { evol[k,l]=max(vvv[k,l]-vvv[k,1],0.) } } } # finding for (l in 1:lm) { rm[l]=0. hm[l]=0. for (k in 2:km-1) { if (zval[k+1] zmin ) & (zf[k] d2z_var_max ) { d2z_var_max=d2z_var } } } } return(d2z_var_max) } ############################################################################# # Compute numerical noise = max second derivative of a variable ############################################################################# compute_numerical_noise_discret <- function(zmin,zmax,lmin,lmax,zf,var) { lm=dim(var)[2] km=dim(var)[1] dz_var<-matrix(0.,km-1,lm) d2z_var_max=0. for (l in lmin:lmax) { for (k in 1:km-1) { dz_var[k,l]=(var[k+1,l]-var[k,l]) } for (k in 2:km-1) { if (( zf[k] > zmin ) & (zf[k] d2z_var_max ) { d2z_var_max=d2z_var } } } } return(d2z_var_max) } ############################################################################# # Compute numerical noise = max second derivative of a variable ############################################################################# compute_numerical_noise_up <- function(zmin,zmax,lmin,lmax,zf,var) { lm=dim(var)[2] km=dim(var)[1] dz_var<-matrix(0.,km-1,lm) d2z_var<-matrix(0.,km,lm) d2z_var_ave<-matrix(0.,lm) d2z_var_max=0. for (l in lmin:lmax) { for (k in 1:km-1) { dz_var[k,l]=(var[k+1,l]-var[k,l])/(zval[k+1]-zval[k]) } count<-0. for (k in 2:km-1) { #if (( zf[k] > zmin ) & (zf[k] zmin ) & ( zf[k] < zmax ) ) { #if ( ( zf[k] > zmin ) & ( zf[k] < zmax ) ) { #if ( l==lmin) { print(c(k,zval[k])) } d2z_var_<-2.*(dz_var[k,l]-dz_var[k-1,l])/(zval[k]-zval[k-1]) d2z_var[k,l]=1e12*d2z_var_*d2z_var_ d2z_var_ave[l]<-d2z_var_ave[l]+d2z_var[k,l]*(zval[k]-zval[k-1]) count=count+(zval[k]-zval[k-1]) } } if ( count > 0 ) { d2z_var_ave[l]=d2z_var_ave[l]/count } } return(1000.*max(d2z_var_ave)) }