diff --git a/data/Bomex_area_gmean.npy b/data/Bomex_area_gmean.npy new file mode 100644 index 0000000..3331678 Binary files /dev/null and b/data/Bomex_area_gmean.npy differ diff --git a/data/Bomex_areaz.npy b/data/Bomex_areaz.npy new file mode 100644 index 0000000..23bbafe Binary files /dev/null and b/data/Bomex_areaz.npy differ diff --git a/data/Bomex_cp.npy b/data/Bomex_cp.npy new file mode 100644 index 0000000..c3ca9d9 Binary files /dev/null and b/data/Bomex_cp.npy differ diff --git a/data/Bomex_cv.npy b/data/Bomex_cv.npy new file mode 100644 index 0000000..98759e6 Binary files /dev/null and b/data/Bomex_cv.npy differ diff --git a/data/Bomex_ht.npy b/data/Bomex_ht.npy new file mode 100644 index 0000000..d7a07e0 Binary files /dev/null and b/data/Bomex_ht.npy differ diff --git a/data/Bomex_hull.npy b/data/Bomex_hull.npy new file mode 100644 index 0000000..a8692a3 Binary files /dev/null and b/data/Bomex_hull.npy differ diff --git a/data/Bomex_overlap_ratio.npy b/data/Bomex_overlap_ratio.npy new file mode 100644 index 0000000..5253aed Binary files /dev/null and b/data/Bomex_overlap_ratio.npy differ diff --git a/data/Bomex_shear.npy b/data/Bomex_shear.npy new file mode 100644 index 0000000..deac75e Binary files /dev/null and b/data/Bomex_shear.npy differ diff --git a/data/Bomex_shearTB.npy b/data/Bomex_shearTB.npy new file mode 100644 index 0000000..ffc5a0c Binary files /dev/null and b/data/Bomex_shearTB.npy differ diff --git a/data/Bomex_shear_sum.npy b/data/Bomex_shear_sum.npy new file mode 100644 index 0000000..36d2f98 Binary files /dev/null and b/data/Bomex_shear_sum.npy differ diff --git a/data/Bomex_sheara_vel.npy b/data/Bomex_sheara_vel.npy new file mode 100644 index 0000000..cb56ab8 Binary files /dev/null and b/data/Bomex_sheara_vel.npy differ diff --git a/data/Bomex_shearh_vel.npy b/data/Bomex_shearh_vel.npy new file mode 100644 index 0000000..8fbc472 Binary files /dev/null and b/data/Bomex_shearh_vel.npy differ diff --git a/data/Bomex_shift_avg.npy b/data/Bomex_shift_avg.npy new file mode 100644 index 0000000..63e466f Binary files /dev/null and b/data/Bomex_shift_avg.npy differ diff --git a/data/Bomex_shift_distance.npy b/data/Bomex_shift_distance.npy new file mode 100644 index 0000000..35383b6 Binary files /dev/null and b/data/Bomex_shift_distance.npy differ diff --git a/data/Bomex_shift_max.npy b/data/Bomex_shift_max.npy new file mode 100644 index 0000000..8f3c34b Binary files /dev/null and b/data/Bomex_shift_max.npy differ diff --git a/data/Bomex_shift_min.npy b/data/Bomex_shift_min.npy new file mode 100644 index 0000000..72b012c Binary files /dev/null and b/data/Bomex_shift_min.npy differ diff --git a/data/Bomex_wavg.npy b/data/Bomex_wavg.npy new file mode 100644 index 0000000..0f56990 Binary files /dev/null and b/data/Bomex_wavg.npy differ diff --git a/data/Bomex_wz_cb.npy b/data/Bomex_wz_cb.npy new file mode 100644 index 0000000..87546d9 Binary files /dev/null and b/data/Bomex_wz_cb.npy differ diff --git a/data/Bomex_wz_max.npy b/data/Bomex_wz_max.npy new file mode 100644 index 0000000..09a91ab Binary files /dev/null and b/data/Bomex_wz_max.npy differ diff --git a/data/Cloud_Cover1.py b/data/Cloud_Cover1.py new file mode 100644 index 0000000..0487d49 --- /dev/null +++ b/data/Cloud_Cover1.py @@ -0,0 +1,390 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon May 13 10:37:38 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +import matplotlib.colors as colors +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + +####################################################### + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + + +################################################ +start=time.time() + + + +### rico828 +""" +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_rico82800.npy') +shearTB = np.load('shearTB_rico82800.npy') +shear_sum = np.load('shear_sum_rico82800.npy') +""" +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +wavg1 = np.load('wavg1_rico201600.npy') +shearTB = np.load('shearTB_rico201600.npy') +shear_sum = np.load('shear_sum_rico201600.npy') +""" + +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +""" +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" +""" +### arm28800 + +height=np.load('height_no_shear_arm28800.npy') +volume=np.load('volume_no_shear_arm28800.npy') +projar=np.load('projarea_no_shear_arm28800.npy') +overlap=np.load('overlap_no_shear_arm28800.npy') +areaz=np.load('area_z_ratio_arm28800.npy') +overlap_convex=np.load('overlap_convex_arm28800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm28800.npy') +shearTB = np.load('shearTB_vel_arm28800.npy') +shear_sum = np.load('shear_sum_arm28800.npy') +""" + +### arm41400 + +height=np.load('height_no_shear_arm41400.npy') +volume=np.load('volume_no_shear_arm41400.npy') +projar=np.load('projarea_no_shear_arm41400.npy') +overlap=np.load('overlap_no_shear_arm41400.npy') +areaz=np.load('area_z_ratio_arm41400.npy') +overlap_convex=np.load('overlap_convex_arm41400.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm41400.npy') +shearTB = np.load('shearTB_vel_arm41400.npy') +shear_sum = np.load('shear_sum_arm41400.npy') + +### Bomex_All is Below + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = Afilenames[10:11] +Bfilenames = Afilenames[17:18] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + """ + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + """ + l=cv**0.5 + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + """ + ### upper bound to turb + lam = np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + keep=np.argwhere(fractalf >1.5*lam-1) + fractalf[np.array(keep)]=1.5*lam-1 + """ + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + + #f_t=f_turb(ht,175); f_t[ht<=100]=0 + #f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + #f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_total = f_t + f_s + f_a +1 + + cv_sorted=np.sort(cv) + cv_arg=np.argsort(cv) + r_sorted=np.zeros(cv.size) + act_sorted=np.zeros(cv.size) + count=-1 + for i in cv_arg: + count= count+1 + r_sorted[count]=r_total[i] + act_sorted[count]=1/overlap_ratio[i] + """ + plt.figure() + plt.plot(cv,r_total,'o') + plt.ylim([0,12]) + #plt.fill(cv,r_total,'b') + plt.figure() + plt.plot(cv,1/overlap_ratio,'o') + plt.ylim([0,12]) + """ + """ + horizontal= cv + vertical= 1/overlap_ratio + + + bins=1*dz; + + plt.figure(); + HIST2dA=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis'); #norm=colors.LogNorm() + + plt.title('Cloud Cover'); + + + plt.xlabel('C_v') + plt.ylabel('Actual Overlap') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + p_act=(sum(HIST2dA[1]*HIST2dA[2])) + + ##### + horizontal= cv + vertical= r_total + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis'); #norm=colors.LogNorm() + + plt.title('Cloud Cover'); + + + plt.xlabel('C_v') + plt.ylabel('Calculated Overlap') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + p_tot=(sum(HIST2dC[1]*HIST2dC[2])) + + + print('Calculated:', p_tot, 'Actual:',p_act) + + #per_err= (abs(p_tot - p_act) / p_act)*100 + #print(per_err) + + perr=(p_tot / p_act) *100 + print(perr) + """ + ######## + #p_tot_trap=np.trapz(r_sorted,cv_sorted) + #p_act_trap=np.trapz(act_sorted,cv_sorted) + #print('Calculated:', p_tot_trap, 'Actual:',p_act_trap) + #### total cld cover + p_tot_num=sum(r_total*cv) + p_act_num=sum(1/overlap_ratio * cv) + print('Calculated:', p_tot_num, 'Actual:',p_act_num) + + + + #per_err= (abs(p_tot_trap - p_act_trap) / p_act_trap)*100 + #print(per_err) + + #perr=(p_tot_trap / p_act_trap) *100 + #print(perr) + + #per_err= (abs(p_tot_num - p_act_num) / p_act_num)*100 + #print(per_err) + + perr=(p_tot_num / p_act_num) *100 + print('percent of cld cover explained: ',perr) + """ + plt.figure() + horizontal= ht + vertical= r_total*cv + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis',norm=colors.LogNorm()); #norm=colors.LogNorm() + + plt.title('Cloud Cover'); + + + plt.xlabel('Cloud Height') + plt.ylabel('Cloud Cover') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + #plt.clim(0,200) + """ + + + plt.figure() + horizontal= r_total*cv + vertical= cp + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis',norm=colors.LogNorm()); #norm=colors.LogNorm() + plt.plot(horizontal,horizontal,'k', linewidth=3) + plt.title('Cloud Cover'); + + + plt.xlabel('Calculated Cloud Cover') + plt.ylabel('Actual Cloud Cover') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + #plt.clim(0,200) + + #plt.savefig('arm41400_cloud_cover_061119.eps', dpi=300, bbox_inches='tight') + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) diff --git a/data/Keeptrack_tdr_rico2016.npy b/data/Keeptrack_tdr_rico2016.npy new file mode 100644 index 0000000..be0adb8 Binary files /dev/null and b/data/Keeptrack_tdr_rico2016.npy differ diff --git a/data/Keeptrack_tdr_rico828.npy b/data/Keeptrack_tdr_rico828.npy new file mode 100644 index 0000000..30d4c36 Binary files /dev/null and b/data/Keeptrack_tdr_rico828.npy differ diff --git a/data/Total_dr_rico2016.npy b/data/Total_dr_rico2016.npy new file mode 100644 index 0000000..bd074a1 Binary files /dev/null and b/data/Total_dr_rico2016.npy differ diff --git a/data/Total_dr_rico828.npy b/data/Total_dr_rico828.npy new file mode 100644 index 0000000..0f82235 Binary files /dev/null and b/data/Total_dr_rico828.npy differ diff --git a/data/area_z_ratio_arm28800.npy b/data/area_z_ratio_arm28800.npy new file mode 100644 index 0000000..2bfc39e Binary files /dev/null and b/data/area_z_ratio_arm28800.npy differ diff --git a/data/area_z_ratio_arm41400.npy b/data/area_z_ratio_arm41400.npy new file mode 100644 index 0000000..68298aa Binary files /dev/null and b/data/area_z_ratio_arm41400.npy differ diff --git a/data/area_z_ratio_bomex10800.npy b/data/area_z_ratio_bomex10800.npy new file mode 100644 index 0000000..ac6663c Binary files /dev/null and b/data/area_z_ratio_bomex10800.npy differ diff --git a/data/area_z_ratio_bomex12600.npy b/data/area_z_ratio_bomex12600.npy new file mode 100644 index 0000000..0ae0833 Binary files /dev/null and b/data/area_z_ratio_bomex12600.npy differ diff --git a/data/area_z_ratio_bomex14400.npy b/data/area_z_ratio_bomex14400.npy new file mode 100644 index 0000000..8f655c1 Binary files /dev/null and b/data/area_z_ratio_bomex14400.npy differ diff --git a/data/area_z_ratio_bomex16200.npy b/data/area_z_ratio_bomex16200.npy new file mode 100644 index 0000000..3204fb9 Binary files /dev/null and b/data/area_z_ratio_bomex16200.npy differ diff --git a/data/area_z_ratio_bomex18000.npy b/data/area_z_ratio_bomex18000.npy new file mode 100644 index 0000000..99059f3 Binary files /dev/null and b/data/area_z_ratio_bomex18000.npy differ diff --git a/data/area_z_ratio_bomex19800.npy b/data/area_z_ratio_bomex19800.npy new file mode 100644 index 0000000..2497744 Binary files /dev/null and b/data/area_z_ratio_bomex19800.npy differ diff --git a/data/area_z_ratio_bomex21600.npy b/data/area_z_ratio_bomex21600.npy new file mode 100644 index 0000000..072ea61 Binary files /dev/null and b/data/area_z_ratio_bomex21600.npy differ diff --git a/data/area_z_ratio_bomex23400.npy b/data/area_z_ratio_bomex23400.npy new file mode 100644 index 0000000..ddc1464 Binary files /dev/null and b/data/area_z_ratio_bomex23400.npy differ diff --git a/data/area_z_ratio_bomex25200.npy b/data/area_z_ratio_bomex25200.npy new file mode 100644 index 0000000..7e8c559 Binary files /dev/null and b/data/area_z_ratio_bomex25200.npy differ diff --git a/data/area_z_ratio_bomex27000.npy b/data/area_z_ratio_bomex27000.npy new file mode 100644 index 0000000..3cdd0bb Binary files /dev/null and b/data/area_z_ratio_bomex27000.npy differ diff --git a/data/area_z_ratio_bomex28800.npy b/data/area_z_ratio_bomex28800.npy new file mode 100644 index 0000000..c2d2368 Binary files /dev/null and b/data/area_z_ratio_bomex28800.npy differ diff --git a/data/area_z_ratio_bomex30600.npy b/data/area_z_ratio_bomex30600.npy new file mode 100644 index 0000000..aa5f219 Binary files /dev/null and b/data/area_z_ratio_bomex30600.npy differ diff --git a/data/area_z_ratio_bomex32400.npy b/data/area_z_ratio_bomex32400.npy new file mode 100644 index 0000000..0b17f9c Binary files /dev/null and b/data/area_z_ratio_bomex32400.npy differ diff --git a/data/area_z_ratio_bomex34200.npy b/data/area_z_ratio_bomex34200.npy new file mode 100644 index 0000000..27d4935 Binary files /dev/null and b/data/area_z_ratio_bomex34200.npy differ diff --git a/data/area_z_ratio_bomex360.npy b/data/area_z_ratio_bomex360.npy new file mode 100644 index 0000000..b5e9394 Binary files /dev/null and b/data/area_z_ratio_bomex360.npy differ diff --git a/data/area_z_ratio_bomex36000.npy b/data/area_z_ratio_bomex36000.npy new file mode 100644 index 0000000..b5e9394 Binary files /dev/null and b/data/area_z_ratio_bomex36000.npy differ diff --git a/data/area_z_ratio_exclude1_no_shear_rico2016.npy b/data/area_z_ratio_exclude1_no_shear_rico2016.npy new file mode 100644 index 0000000..09513b7 Binary files /dev/null and b/data/area_z_ratio_exclude1_no_shear_rico2016.npy differ diff --git a/data/area_z_ratio_exclude1_no_shear_rico828.npy b/data/area_z_ratio_exclude1_no_shear_rico828.npy new file mode 100644 index 0000000..c6e9c64 Binary files /dev/null and b/data/area_z_ratio_exclude1_no_shear_rico828.npy differ diff --git a/data/area_z_ratio_lasso306.npy b/data/area_z_ratio_lasso306.npy new file mode 100644 index 0000000..24029e8 Binary files /dev/null and b/data/area_z_ratio_lasso306.npy differ diff --git a/data/area_z_ratio_rico2016.npy b/data/area_z_ratio_rico2016.npy new file mode 100644 index 0000000..c6356ed Binary files /dev/null and b/data/area_z_ratio_rico2016.npy differ diff --git a/data/area_z_ratio_rico828.npy b/data/area_z_ratio_rico828.npy new file mode 100644 index 0000000..8a04e79 Binary files /dev/null and b/data/area_z_ratio_rico828.npy differ diff --git a/data/areaz_with_median1.py b/data/areaz_with_median1.py new file mode 100644 index 0000000..aa58e74 --- /dev/null +++ b/data/areaz_with_median1.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu May 9 12:24:46 2019 + +@author: anthonys +""" + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + +################################################ +start=time.time() + + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +begin=5 +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] + +file1numb=begin-1 + + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + alpha=np.arange(1,0,-1) # just 1 + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + m=-1 + for e1 in cloud_numb: + m=m+1 + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + base=np.amin(location[0]);top=np.amax(location[0]); + layers=(top - base + 1) # layers of cloud along z + cross_area_z=np.zeros(int(layers)) + + + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + + + area_z_ratio[m]= gmean(cross_area_z) / np.amax(cross_area_z) + + step=1800 # 30*60 + time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/bomex_area_gmean" + #step=3600 # 60*60 + #time_array= np.arange(10800,216000+step,step) + #npyfilespath ="/home/anthonys/Documents/rico_area_gmean" + ### becarful here + #np.save(npyfilespath+str(time_array[file1_numb])+'.npy',area_z_ratio) + + #np.save(npyfilespath+str(time_array[20])+'.npy',area_z_ratio) + ### need to fix time_array and saving + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + diff --git a/data/bomex_area_gmean10800.npy b/data/bomex_area_gmean10800.npy new file mode 100644 index 0000000..a5d6ea4 Binary files /dev/null and b/data/bomex_area_gmean10800.npy differ diff --git a/data/bomex_area_gmean12600.npy b/data/bomex_area_gmean12600.npy new file mode 100644 index 0000000..f48e5fc Binary files /dev/null and b/data/bomex_area_gmean12600.npy differ diff --git a/data/bomex_area_gmean14400.npy b/data/bomex_area_gmean14400.npy new file mode 100644 index 0000000..fdf2c9b Binary files /dev/null and b/data/bomex_area_gmean14400.npy differ diff --git a/data/bomex_area_gmean16200.npy b/data/bomex_area_gmean16200.npy new file mode 100644 index 0000000..35e3d75 Binary files /dev/null and b/data/bomex_area_gmean16200.npy differ diff --git a/data/bomex_area_gmean18000.npy b/data/bomex_area_gmean18000.npy new file mode 100644 index 0000000..1698ede Binary files /dev/null and b/data/bomex_area_gmean18000.npy differ diff --git a/data/bomex_area_gmean19800.npy b/data/bomex_area_gmean19800.npy new file mode 100644 index 0000000..e0703c7 Binary files /dev/null and b/data/bomex_area_gmean19800.npy differ diff --git a/data/bomex_area_gmean21600.npy b/data/bomex_area_gmean21600.npy new file mode 100644 index 0000000..ceb570c Binary files /dev/null and b/data/bomex_area_gmean21600.npy differ diff --git a/data/bomex_area_gmean23400.npy b/data/bomex_area_gmean23400.npy new file mode 100644 index 0000000..87047e8 Binary files /dev/null and b/data/bomex_area_gmean23400.npy differ diff --git a/data/bomex_area_gmean25200.npy b/data/bomex_area_gmean25200.npy new file mode 100644 index 0000000..7c991c0 Binary files /dev/null and b/data/bomex_area_gmean25200.npy differ diff --git a/data/bomex_area_gmean27000.npy b/data/bomex_area_gmean27000.npy new file mode 100644 index 0000000..c509adc Binary files /dev/null and b/data/bomex_area_gmean27000.npy differ diff --git a/data/bomex_area_gmean28800.npy b/data/bomex_area_gmean28800.npy new file mode 100644 index 0000000..a7fb782 Binary files /dev/null and b/data/bomex_area_gmean28800.npy differ diff --git a/data/bomex_area_gmean30600.npy b/data/bomex_area_gmean30600.npy new file mode 100644 index 0000000..9cccb77 Binary files /dev/null and b/data/bomex_area_gmean30600.npy differ diff --git a/data/bomex_area_gmean32400.npy b/data/bomex_area_gmean32400.npy new file mode 100644 index 0000000..3d33371 Binary files /dev/null and b/data/bomex_area_gmean32400.npy differ diff --git a/data/bomex_area_gmean34200.npy b/data/bomex_area_gmean34200.npy new file mode 100644 index 0000000..683117b Binary files /dev/null and b/data/bomex_area_gmean34200.npy differ diff --git a/data/bomex_area_gmean36000.npy b/data/bomex_area_gmean36000.npy new file mode 100644 index 0000000..421bd36 Binary files /dev/null and b/data/bomex_area_gmean36000.npy differ diff --git a/data/bomex_overlap_convex10800.npy b/data/bomex_overlap_convex10800.npy new file mode 100644 index 0000000..d79cf1c Binary files /dev/null and b/data/bomex_overlap_convex10800.npy differ diff --git a/data/bomex_overlap_convex12600.npy b/data/bomex_overlap_convex12600.npy new file mode 100644 index 0000000..ef4c62d Binary files /dev/null and b/data/bomex_overlap_convex12600.npy differ diff --git a/data/bomex_overlap_convex14400.npy b/data/bomex_overlap_convex14400.npy new file mode 100644 index 0000000..93866b4 Binary files /dev/null and b/data/bomex_overlap_convex14400.npy differ diff --git a/data/bomex_overlap_convex16200.npy b/data/bomex_overlap_convex16200.npy new file mode 100644 index 0000000..f5652fe Binary files /dev/null and b/data/bomex_overlap_convex16200.npy differ diff --git a/data/bomex_overlap_convex18000.npy b/data/bomex_overlap_convex18000.npy new file mode 100644 index 0000000..9ec3ba6 Binary files /dev/null and b/data/bomex_overlap_convex18000.npy differ diff --git a/data/bomex_overlap_convex19800.npy b/data/bomex_overlap_convex19800.npy new file mode 100644 index 0000000..019ba00 Binary files /dev/null and b/data/bomex_overlap_convex19800.npy differ diff --git a/data/bomex_overlap_convex21600.npy b/data/bomex_overlap_convex21600.npy new file mode 100644 index 0000000..029cf71 Binary files /dev/null and b/data/bomex_overlap_convex21600.npy differ diff --git a/data/bomex_overlap_convex23400.npy b/data/bomex_overlap_convex23400.npy new file mode 100644 index 0000000..364a25f Binary files /dev/null and b/data/bomex_overlap_convex23400.npy differ diff --git a/data/bomex_overlap_convex25200.npy b/data/bomex_overlap_convex25200.npy new file mode 100644 index 0000000..d478994 Binary files /dev/null and b/data/bomex_overlap_convex25200.npy differ diff --git a/data/bomex_overlap_convex27000.npy b/data/bomex_overlap_convex27000.npy new file mode 100644 index 0000000..ad66c0d Binary files /dev/null and b/data/bomex_overlap_convex27000.npy differ diff --git a/data/bomex_overlap_convex30600.npy b/data/bomex_overlap_convex30600.npy new file mode 100644 index 0000000..43d4761 Binary files /dev/null and b/data/bomex_overlap_convex30600.npy differ diff --git a/data/bomex_overlap_convex32400.npy b/data/bomex_overlap_convex32400.npy new file mode 100644 index 0000000..b0dd7bf Binary files /dev/null and b/data/bomex_overlap_convex32400.npy differ diff --git a/data/bomex_overlap_convex34200.npy b/data/bomex_overlap_convex34200.npy new file mode 100644 index 0000000..87c46d4 Binary files /dev/null and b/data/bomex_overlap_convex34200.npy differ diff --git a/data/bomex_overlap_convex36000.npy b/data/bomex_overlap_convex36000.npy new file mode 100644 index 0000000..fda1293 Binary files /dev/null and b/data/bomex_overlap_convex36000.npy differ diff --git a/data/cal_factors2.py b/data/cal_factors2.py new file mode 100644 index 0000000..bf779ef --- /dev/null +++ b/data/cal_factors2.py @@ -0,0 +1,688 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Apr 29 16:40:13 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + + +import plotly.plotly as py +import plotly.graph_objs as go + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +#ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + +lassotrack306 = Dataset('/data/lasso/sims/20160611_micro/l.0030600.track.nc','r') + +""" +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] +""" +########################################################################### +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 +################################################################################# + +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack360] +armfilenames=[armtrack522] +lassofilenames=[lassotrack306] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + + +""" +### rico828 + +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_rico82800.npy') +shearTB = np.load('shearTB_rico82800.npy') +shear_sum = np.load('shear_sum_rico82800.npy') +wz_max = np.load('wz_max_rico82800.npy') +wz_cb = np.load('wz_cb_rico82800.npy') +shift_distance = np.load('shift_distancerico82800.npy') +""" +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +wavg1 = np.load('wavg1_rico201600.npy') +shearTB = np.load('shearTB_rico201600.npy') +shear_sum = np.load('shear_sum_rico201600.npy') +shift_distance = np.load('shift_distancerico201600.npy') +""" +""" +### bomex 342 +height342=np.load('height_no_shear_bomex34200.npy') +volume342=np.load('volume_no_shear_bomex34200.npy') +projar342=np.load('projarea_no_shear_bomex34200.npy') +overlap342=np.load('overlap_no_shear_bomex34200.npy') +areaz342=np.load('area_z_ratio_bomex34200.npy') + +### bomex 360 +height=np.load('height_no_shear_bomex36000.npy') +volume=np.load('volume_no_shear_bomex36000.npy') +projar=np.load('projarea_no_shear_bomex36000.npy') +overlap=np.load('overlap_no_shear_bomex36000.npy') +areaz=np.load('area_z_ratio_bomex36000.npy') + +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" + +### arm28800 + +height=np.load('height_no_shear_arm28800.npy') +volume=np.load('volume_no_shear_arm28800.npy') +projar=np.load('projarea_no_shear_arm28800.npy') +overlap=np.load('overlap_no_shear_arm28800.npy') +areaz=np.load('area_z_ratio_arm28800.npy') +overlap_convex=np.load('overlap_convex_arm28800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm28800.npy') +shearTB = np.load('shearTB_vel_arm28800.npy') +shear_sum = np.load('shear_sum_arm28800.npy') +shift_distance = np.load('shift_distancearm28800.npy') + +""" +### arm41400 + +height=np.load('height_no_shear_arm41400.npy') +volume=np.load('volume_no_shear_arm41400.npy') +projar=np.load('projarea_no_shear_arm41400.npy') +overlap=np.load('overlap_no_shear_arm41400.npy') +areaz=np.load('area_z_ratio_arm41400.npy') +overlap_convex=np.load('overlap_convex_arm41400.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm41400.npy') +shearTB = np.load('shearTB_vel_arm41400.npy') +shear_sum = np.load('shear_sum_arm41400.npy') +shift_distance = np.load('shift_distancearm41400.npy') +""" +### Bomex_All is Below + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +Bfilenames = Afilenames[10:11] +#Bfilenames = Afilenames[17:18] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + """ + ### Bomex_All + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + overlap_convex=np.load('Bomex_hull.npy') + #shearh_vel = np.load('Bomex_shearh_vel.npy') + #sheara_vel = np.load('Bomex_sheara_vel.npy') + #wavg = np.load('Bomex_wavg.npy') + shearTB = np.load('Bomex_shearTB.npy') + shear_sum = np.load('Bomex_shear_sum.npy') + wz_max = np.load('Bomex_wz_max.npy') + wz_cb = np.load('Bomex_wz_cb.npy') + shift_distance = np.load('Bomex_shift_distance.npy') + print('Bomex') + """ + + + + binsize=100 + condition_vec= np.arange(binsize,max(ht)+binsize,binsize) #, 500, 100, 50] # to go through multiple conditions quickly + h_shear = np.zeros(condition_vec.size) + h_shape = np.zeros(condition_vec.size) + h_turb = np.zeros(condition_vec.size) + h_ACT = np.zeros(condition_vec.size) + h_RES = np.zeros(condition_vec.size) + h_total = np.zeros(condition_vec.size) + m=-1 + + + ##### loop over bin hts + for conditional_height in condition_vec: + + m=m+1 + #conditional_height=1500 + index=np.where( (conditional_height-binsize < ht) & (ht <= conditional_height) ) # indices of where condition holds true in ht vector + index_size=index[0].size + ht_sel=ht[index[0]] # taking the ht values according to indices above + overlap_ratio_sel=overlap_ratio[index[0]]; + #area_proj_sel=area_proj[index[0]] + + + """ + print('Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_size) + """ + ######################################## + + #areaz=areazg + + + ############################################################ + ###### calculating overlap due to contributors + l=cv**0.5 + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + #shear = abs(shear) + shear[shear<0]=0 + + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + + + FF = f_turb(ht,200);FF[ht<=100]=0; + shear_sum = abs(shear_sum) + shift_d = np.zeros(ht.size) + shift_d[ht>50] = shift_distance + + shift_d = shift_d + shape*cp**0.5/2 ### draw the picture + updraft = (shear_sum*ht)/shift_d + FS = (shear_sum*ht)/(updraft*cp**0.5) + FS[updraft<0.1] = 0 + #FS[updraft<0.01] = 0 + + #shear = FS ; fractalf = FF + + #r_shear= 1/overlap_ratio[index[0]] - 1/overlap[index[0]] # index variables with index_greater[0] + #r_shear[r_shear<0]=0 + r_shear=shear[index[0]] + r_area=1/areaz[index[0]] -1 + #r_turb= (np.ones(index_size)*fractal) -1 + r_turb = fractalf[index[0]] + actual = 1/overlap_ratio[index[0]] + + #r_total = ( r_shear + r_area + r_turb ) +1 + + ######## + + #### empirical model + #f_t=f_turb(ht,200); f_t[ht<=100]=0 + #f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + #f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_shear=f_s[index[0]] + #r_area=f_a[index[0]] + #r_turb=f_t[index[0]] + + + r_total = ( r_shear + r_area + r_turb ) +1 + + + ######## + + residual = actual - r_total + #residual[residual<0]=0 + ####### binning data + """ + S=((r_shear-1)/r_total) + A=((r_area-1)/r_total) + T=((r_turb-1)/r_total) + """ + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + ACT_avg=np.mean(actual) + ACT_std=np.std(actual) + RES_avg=np.mean(residual) + RES_std=np.std(residual) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + h_shear[m]=S3_avg + h_shape[m]=A3_avg + h_turb[m]=T3_avg + h_ACT[m]=ACT_avg + h_RES[m]=RES_avg + h_total[m] = r3_avg + """ + print('average r is %.2f' % r3_avg, ', r std is %.2f' % r3_std) + print('average r_shear is %.2f' % S3_avg, ', r_shear std is %.2f' % S3_std) + print('average r_area percentage is %.2f' % A3_avg, ', r_area std is %.2f' % A3_std) + print('average r_turbulence percentage is %.2f' % T3_avg, ', r_turbulence std is %.2f' % T3_std) + """ + + + ###################################################### + + + + + + + +""" +h_shear=np.nan_to_num(h_shear) +h_shape=np.nan_to_num(h_shape) +h_turb=np.nan_to_num(h_turb) +h_ACT=np.nan_to_num(h_ACT) +h_RES=np.nan_to_num(h_RES) +""" +h_ACT=h_ACT -1 +h_ACT[h_ACT<0]=0 +########################################################################################## +###### stacked bar graph +#h_turb=f_turb(ht_bin,opt_t) +## change variable +h_total = h_shape + h_shear +h_turb + + +N= int(condition_vec.size) + +#N=np.count_nonzero(~np.isnan(h_shear)) + +ind = np.arange(N) # the x locations for the groups +width = 0.8 #1/N # the width of the bars: can also be len(x) sequence +width = 90 +ind=ind*100 +100 +arg_nan=np.argwhere(np.isnan(h_shape)) +#ind=ind[~np.isnan(h_shear)] +#N=ind.size +ind = ind.astype('float') +ind[arg_nan] = np.nan +""" +ind=ind[~np.isnan(ind)] +h_shear=h_shear[~np.isnan(h_shear)] +h_shape=h_shape[~np.isnan(h_shape)] +h_turb=h_turb[~np.isnan(h_turb)] +h_ACT = h_ACT[~np.isnan(h_ACT)] +""" +bottom2=np.zeros(ind.size) +bottom3=np.zeros(ind.size) +for i in range(ind.size): + #i = int(i/100 - 1) + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +#ind=ind[~np.isnan(ind)] +#h_shear=h_shear[~np.isnan(h_shear)] +#h_shape=h_shape[~np.isnan(h_shape)] +#h_turb=h_turb[~np.isnan(h_turb)] + +""" +mystring = [] +for digit in ind: + mystring.append(digit) +ind = np.arange(100,100*ind.size+100,100) +""" +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Height') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind,mystring) +#plt.xticks(ind[0:1],condition_vec[0:1]) +#plt.xticks([0 , 9 , 19 ], ('100', '1000', '2000' ) ) +plt.yticks(np.arange(0, 20, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) + + +pa=plt.plot(ind,h_ACT,'ko',linewidth=2) + +plt.legend((p1[0], p2[0],p3[0],pa[0]), ('Turbulence','Shear', 'Area Variability','Actual Overlap'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +#plt.savefig('arm28800_factor_average1_emp1_061719.eps', dpi=300, bbox_inches='tight') + + +############################################################ +#### makes table of fraction of factor, put it in matrix form +print('Area', '\t', 'Shear', '\t' ,'Turbulence') +h_1=h_shape/h_total +h_2=h_shear/h_total +h_3=h_turb/h_total + +for j in range(h_ACT.size): + print( '%.3f' %h_1[j],'\t', '%.3f '%h_2[j], '\t', '%.3f' %h_3[j] ) + +print('average percentages (%.3f , %.3f , %.3f)' %(np.nanmean(h_1), np.nanmean(h_2), np.nanmean(h_3))) + +h_matrix = np.array([[h_1],[h_2],[h_3]]) +h_matrix2 = np.zeros((h_1.size,4)) +h_matrix2[:,0] = np.round(ind,3) +h_matrix2[:,1] = np.round(h_1,3) +h_matrix2[:,2] = np.round(h_2,3) +h_matrix2[:,3] = np.round(h_3,3) +################################################################################### +################################################################################## +#### curve fit for turbulence + +ht_bin=ind*100 +100 +""" +Z=np.where(h_turb == 0) +h_turb=np.delete(h_turb,Z) +ht_bin=np.delete(ht_bin,Z) + + +opt_t, cov_t = curve_fit(f_turb , ht_bin[1:], h_turb[1:]) + +c=opt_t +model_turb=f_turb(ht,c) + + +bins=1*dz; + +plt.figure(); +plt.hist2d(ht,model_turb,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) + + +plt.title('Effect of Turbulence'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); + +plt.xlabel('ht') +plt.ylabel('Cal Overlap') +#plt.xlabel('Cloud Overlap') +#plt.ylabel('Cloud Height') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') + +########################################################## +""" + + + +""" +###################################################### +##replot stacked hist +plt.figure() +ht_bin=ind*100 +100 +h_turb=f_turb(ht_bin,c) + + +bottom2=np.zeros(N) +bottom3=np.zeros(N) +for i in range(N): + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Height') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind, '%' %[condition_vec]) +plt.xticks([0 , 9 , 19 ], ('100', '1000', '2000' ) ) +plt.yticks(np.arange(0, 8, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) +plt.legend((p1[0], p2[0],p3[0]), ('Turbulence','Shear', 'Area Variability'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +plt.plot(h_ACT,'ko-',linewidth=2) + +######################################################################################## +""" + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/cal_factors2_shear.py b/data/cal_factors2_shear.py new file mode 100644 index 0000000..ec181e0 --- /dev/null +++ b/data/cal_factors2_shear.py @@ -0,0 +1,475 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu May 23 16:47:58 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + +#################################### + +# script + +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + + + +### rico828 + +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') + +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +""" + +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +""" +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + l=cv**0.5 + + binsize=0.5 + condition_vec= np.arange(binsize,max(ht/l)+binsize,binsize) #, 500, 100, 50] # to go through multiple conditions quickly + h_shear = np.zeros(condition_vec.size) + h_shape = np.zeros(condition_vec.size) + h_turb = np.zeros(condition_vec.size) + h_ACT = np.zeros(condition_vec.size) + h_RES = np.zeros(condition_vec.size) + m=-1 + + + for conditional_height in condition_vec: + + m=m+1 + #conditional_height=1500 + index=np.where( (conditional_height-binsize < ht/l) & (ht/l <= conditional_height) ) # indices of where condition holds true in ht vector + index_size=index[0].size + ht_sel=ht[index[0]] # taking the ht values according to indices above + overlap_ratio_sel=overlap_ratio[index[0]]; + #area_proj_sel=area_proj[index[0]] + + + """ + print('Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_size) + """ + ######################################## + + #areaz=areazg + + + ############################################################ + + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + #fractalf = np.minimum(((3*np.pi) / 4)*np.ones(overlap_ratio.size),1/overlap_ratio) + + #fractalf = np.minimum( (3*np.pi /4)*np.ones(overlap_ratio.size), 1/overlap_ratio ) + #fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) + + + r_shear= 1/overlap_ratio[index[0]] - 1/overlap[index[0]] # index variables with index_greater[0] + r_shear[r_shear<0]=0 + r_area=1/areaz[index[0]] -1 + #r_turb= (np.ones(index_size)*fractal) -1 + r_turb = fractalf[index[0]] + actual = 1/overlap_ratio[index[0]] + + r_total = ( r_shear + r_area + r_turb ) +1 # correction: need to add 1 + + residual = actual - r_total + #residual[residual<0]=0 + + """ + S=((r_shear-1)/r_total) + A=((r_area-1)/r_total) + T=((r_turb-1)/r_total) + """ + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + ACT_avg=np.mean(actual) + ACT_std=np.std(actual) + RES_avg=np.mean(residual) + RES_std=np.std(residual) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + h_shear[m]=S3_avg + h_shape[m]=A3_avg + h_turb[m]=T3_avg + h_ACT[m]=ACT_avg + h_RES[m]=RES_avg + """ + print('average r is %.2f' % r3_avg, ', r std is %.2f' % r3_std) + print('average r_shear is %.2f' % S3_avg, ', r_shear std is %.2f' % S3_std) + print('average r_area percentage is %.2f' % A3_avg, ', r_area std is %.2f' % A3_std) + print('average r_turbulence percentage is %.2f' % T3_avg, ', r_turbulence std is %.2f' % T3_std) + """ + + + ###################################################### + + + + + + + + +h_shear=np.nan_to_num(h_shear) +h_shape=np.nan_to_num(h_shape) +h_turb=np.nan_to_num(h_turb) +h_ACT=np.nan_to_num(h_ACT) +h_RES=np.nan_to_num(h_RES) + +h_ACT=h_ACT -1 +h_ACT[h_ACT<0]=0 +########################################################################################## + + + +""" +h_shape= ( np.load('h_shape_rico828.npy') + np.load('h_shape_rico2016.npy') ) /2 +h_shear= ( np.load('h_shear_rico828.npy') + np.load('h_shear_rico2016.npy') ) /2 +h_turb= ( np.load('h_turb_rico828.npy') + np.load('h_turb_rico2016.npy') ) /2 +""" + +N= int(condition_vec.size) + +ind = np.arange(N) # the x locations for the groups +width = 0.8 #1/N # the width of the bars: can also be len(x) sequence + +bottom2=np.zeros(N) +bottom3=np.zeros(N) +for i in range(N): + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Aspect Ratio') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind, '%' %[condition_vec]) +plt.xticks([0 , 9 , 19 ], ('0.5', '5', '10' ) ) +plt.yticks(np.arange(0, 10, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) +plt.legend((p1[0], p2[0],p3[0]), ('Turbulence','Shear', 'Area Variability'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +plt.plot(h_ACT,'ko-',linewidth=2) + + +#plt.savefig('bomexAll_factor_average1_052219.eps', dpi=300, bbox_inches='tight') + +#ht_bin=ind*100 +100 +ht_bin=ind*0.5 +0.5 + +################################################################################### +################################################################################## +#### curve fit for shear + + +""" +Z=np.where(h_shear == 0) +h_shear=np.delete(h_shear,Z) +ht_bin=np.delete(ht_bin,Z) + + +opt_s, cov_s = curve_fit(f_shear , ht_bin[2:], h_shear[2:]) + +c=opt_s +model_shear=f_shear(ht/l,c) + + +bins=1*dz; + +plt.figure(); +plt.hist2d(ht/l,model_shear,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) + + +plt.title('Effect of Shear'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); + +plt.xlabel('aspect ratio') +plt.ylabel('Cal Overlap') +#plt.xlabel('Cloud Overlap') +#plt.ylabel('Cloud Height') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') +""" +########################################################## +################################################################################## +#### curve fit for area + + + +Z=np.where(h_shape == 0) +h_shape=np.delete(h_shape,Z) +ht_bin=np.delete(ht_bin,Z) + + +opt_a, cov_a = curve_fit(f_area , ht_bin[2:], h_shape[2:]) + +c=opt_a +model_shape=f_area(ht/l,c) + + +bins=1*dz; + +plt.figure(); +plt.hist2d(ht/l,model_shape,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) + + +plt.title('Effect of Area'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); + +plt.xlabel('aspect ratio') +plt.ylabel('Cal Overlap') +#plt.xlabel('Cloud Overlap') +#plt.ylabel('Cloud Height') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') + +########################################################## + + + +###################################################### +##replot stacked hist +plt.figure() +#ht_bin=ind*100 +100 +ht_bin=ind*0.5 +0.5 + +h_shape=f_area(ht_bin,c) +#h_shear=f_shear(ht_bin,c) + +bottom2=np.zeros(N) +bottom3=np.zeros(N) +for i in range(N): + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Aspect Ratio') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind, '%' %[condition_vec]) +plt.xticks([0 , 9 , 19 ], ('0.5', '5', '10' ) ) +plt.yticks(np.arange(0, 10, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) +plt.legend((p1[0], p2[0],p3[0]), ('Turbulence','Shear', 'Area Variability'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +plt.plot(h_ACT,'ko-',linewidth=2) + +######################################################################################## + + + + + + + + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + diff --git a/data/calculating_contributions1.py b/data/calculating_contributions1.py new file mode 100644 index 0000000..2633dfe --- /dev/null +++ b/data/calculating_contributions1.py @@ -0,0 +1,400 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Apr 15 18:22:28 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files +""" +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') +""" + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +#ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + +""" +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] +""" +########################################################################### + +#################################### + +# script +filenames=[ricod] +ricofilenames=[ricotrack2016] +#bomexfilenames=[bomextrack36] +armfilenames=[armtrack522] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + +for file in filenames: + file_numb = file_numb+1 + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + file1_numb = file1_numb+1 + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + + + condition_vec=[1000]#, 500, 100, 50] # to go through multiple conditions quickly + + for conditional_height in condition_vec: + + #conditional_height=1500 + index_greater=np.where(ht >= conditional_height) # indices of where condition holds true in ht vector + index_greater_size=index_greater[0].size + ht_anvil=ht[index_greater[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_greater[0]]; + area_proj_anvil=area_proj[index_greater[0]] + + + print('Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_greater_size) + + ######################################## + + + + ### rico828 + """ + height=np.load('height_no_shear_rico828.npy') + volume=np.load('volume_no_shear_rico828.npy') + projar=np.load('projarea_no_shear_rico828.npy') + overlap=np.load('overlap_no_shear_rico828.npy') + areaz=np.load('area_z_ratio_rico828.npy') + """ + ### rico2016 + height=np.load('height_no_shear_rico2016.npy') + volume=np.load('volume_no_shear_rico2016.npy') + projar=np.load('projarea_no_shear_rico2016.npy') + overlap=np.load('overlap_no_shear_rico2016.npy') + areaz=np.load('area_z_ratio_rico2016.npy') + model=np.load('model_rico2016.npy') + + ############################################################ + + fractal= (6*np.sqrt(3)) / (5*np.pi) + + r_shear= 1/overlap_ratio[index_greater[0]] - 1/overlap[index_greater[0]] # index variables with index_greater[0] + r_shear[r_shear<0]=0 + r_area=1/areaz[index_greater[0]] -1 + r_turb= 1/(np.ones(index_greater_size)*fractal) -1 + + r_total = ( r_shear + r_area + r_turb ) +1 # correction: need to add 1 + + + """ + S=((r_shear-1)/r_total) + A=((r_area-1)/r_total) + T=((r_turb-1)/r_total) + """ + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + print('average r is %.2f' % r3_avg, ', r std is %.2f' % r3_std) + print('average r_shear is %.2f' % S3_avg, ', r_shear std is %.2f' % S3_std) + print('average r_area percentage is %.2f' % A3_avg, ', r_area std is %.2f' % A3_std) + print('average r_turbulence percentage is %.2f' % T3_avg, ', r_turbulence std is %.2f' % T3_std) + + + + ###################################################### + + print('----------------------------------------------------------------------------------') + conditional_height=100 + index_less=np.where(ht <= conditional_height) # indices of where condition holds true in ht vector + index_less_size=index_less[0].size + ht_anvil=ht[index_less[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_less[0]]; + area_proj_anvil=area_proj[index_less[0]] + print('Clouds with height less than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_less_size) + + + + + fractal= (6*np.sqrt(3)) / (5*np.pi) + + r_shear= 1/overlap_ratio[index_less[0]] - 1/overlap[index_less[0]] # index variables with index_less[0] + r_shear[r_shear<0]=0 + r_area=1/areaz[index_less[0]] -1 + r_turb= 1/(np.ones(index_less_size)*fractal) -1 + + r_total = ( r_shear + r_area + r_turb ) +1 + + + + S1=r_shear + A1=r_area + T1=r_turb + R1=r_total + r1_avg=np.mean(r_total) + r1_std=np.std(r_total) + + S1_avg=np.mean(S1)#*100 + A1_avg=np.mean(A1)#*100 + T1_avg=np.mean(T1)#*100 + S1_std=np.std(S1) + A1_std=np.std(A1) + T1_std=np.std(T1) + + print('average r is %.2f' % r1_avg, ', r std is %.2f' % r1_std) + print('average r_shear is %.2f' % S1_avg, ', r_shear std is %.2f' % S1_std) + print('average r_area percentage is %.2f' % A1_avg, ', r_area std is %.2f' % A1_std) + print('average r_turbulence percentage is %.2f' % T1_avg, ', r_turbulence std is %.2f' % T1_std) + + print('----------------------------------------------------------------------------------') + + + +############################################# + +print('----------------------------------------------------------------------------------') +#conditional_height=1500 +index_middle=np.where( (100 < ht) & (ht < 500)) # indices of where condition holds true in ht vector +index_middle_size=index_middle[0].size +ht_anvil=ht[index_middle[0]] # taking the ht values according to indices above +overlap_ratio_anvil=overlap_ratio[index_middle[0]]; +area_proj_anvil=area_proj[index_middle[0]] +print('Clouds with height between 100 and 1000 meters') +print('Clouds that satisfy the given condition: ',index_middle_size) + + + + +fractal= (6*np.sqrt(3)) / (5*np.pi) + +r_shear= 1/overlap_ratio[index_middle[0]] - 1/overlap[index_middle[0]] # index variables with index_middle[0] +r_shear[r_shear<0]=0 +r_area=1/areaz[index_middle[0]] -1 +r_turb= 1/(np.ones(index_middle_size)*fractal) -1 + +r_total = ( r_shear + r_area + r_turb ) +1 # correction: need to subtract 1 from each + + + +S2=r_shear +A2=r_area +T2=r_turb + +r2_avg=np.mean(r_total) +r2_std=np.std(r_total) + +S2_avg=np.mean(S2)#*100 +A2_avg=np.mean(A2)#*100 +T2_avg=np.mean(T2)#*100 +S2_std=np.std(S2) +A2_std=np.std(A2) +T2_std=np.std(T2) + +print('average r is %.2f' % r2_avg, ', r std is %.2f' % r2_std) +print('average r_shear is %.2f' % S2_avg, ', r_shear std is %.2f' % S2_std) +print('average r_area percentage is %.2f' % A2_avg, ', r_area std is %.2f' % A2_std) +print('average r_turbulence percentage is %.2f' % T2_avg, ', r_turbulence std is %.2f' % T2_std) + +print('----------------------------------------------------------------------------------') + + + + + +################################################################ + +N = 3 +""" +h_shear = ( 7.67, 54.94 , 71.41) +h_shape = ( 5.17, 27.77 , 19.46) +h_turb = (87.19, 17.29,9.13) +""" + +h_shear = ( S1_avg, S2_avg , S3_avg) +h_shape = ( A1_avg, A2_avg , A3_avg) +h_turb = (T1_avg, T2_avg, T3_avg) +ind = np.arange(N) # the x locations for the groups +width = 1/N # the width of the bars: can also be len(x) sequence + +p1 = plt.bar(ind, h_shear, width, color='blue') +p2 = plt.bar(ind, h_shape, width, bottom=h_shear, color='purple' ) +p3=plt.bar(ind,h_turb,width,bottom=(h_shape[0] + h_shear[0] , h_shape[1] + h_shear[1], h_shape[2]+h_shear[2]) , color='pink') + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +plt.xticks(ind, ( 'H < 100m' , '100m < H < 1000m', 'H > 1000m')) +plt.yticks(np.arange(0, 6, 1)) +plt.legend((p1[0], p2[0],p3[0]), ('Shear', 'Area','Turbulence'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) + + + +#plt.savefig('rico2016_factor_average_042319.eps', dpi=300, bbox_inches='tight') + + + + + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) diff --git a/data/check1.py b/data/check1.py new file mode 100644 index 0000000..afec457 --- /dev/null +++ b/data/check1.py @@ -0,0 +1,319 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Apr 16 10:36:00 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack360] +armfilenames=[armtrack522] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + +for file in filenames: + file_numb = file_numb+1 + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + file1_numb = file1_numb+1 + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + + + condition_vec=[100]#, 500, 100, 50] # to go through multiple conditions quickly + + for conditional_height in condition_vec: + + #conditional_height=1500 + index_greater=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index_greater_size=index_greater[0].size + ht_anvil=ht[index_greater[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_greater[0]]; + area_proj_anvil=area_proj[index_greater[0]] + + print('Total Number of Clouds in dataset is %.0f' % nr.size) + print('Condition: Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_greater_size) + + + + +""" +### combines npy files into one +### only use once, affect will be compounded, delete combined npy file then run again +fpath ="path_Of_my_final_Big_File" +npyfilespath ="/home/anthonys/Documents/Temp1" +os.chdir(npyfilespath) +npfiles= glob.glob("*.npy") +npfiles.sort() +all_arrays = [] +for i, npfile in enumerate(npfiles): + all_arrays.append(np.load(os.path.join(npyfilespath, npfile))) +np.save(fpath, np.concatenate(all_arrays,axis=0)) +""" +###### + +""" +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[5:] +for f in Bfilenames: + print(f) + + data = Dataset(f,'r') +step=1800 # 30*60 +time_array= np.arange(10800,36000+step,step) +""" +""" +###################################################### +### Concatenate data +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[5:] +arrays1=[];arrays2=[];arrays3=[] +for f in Bfilenames: + print(f) + + data = Dataset(f,'r') + #overlap_ratio=data.variables['chr'][:] + #arrays1.append(overlap_ratio) + #ht=data.variables['ht'][:] + #arrays2.append(ht) + cp=data.variables['cp'][:] + arrays3.append(cp) + +#Bomex_overlap_ratio=np.concatenate(arrays1,axis=0) +#Bomex_ht=np.concatenate(arrays2,axis=0) +Bomex_cp=np.concatenate(arrays3,axis=0) +""" +######## +""" +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/overlap_no_shear_bomex*.npy')) +#Bfilenames = Afilenames[5:] +Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_shear=np.concatenate(arrays,axis=0) + +####### + +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/area_z_ratio_bomex*.npy')) +#Bfilenames = Afilenames[5:] +Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_areaz=np.concatenate(arrays,axis=0) +""" +""" +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/bomex_overlap_convex*.npy')) +#Bfilenames = Afilenames[5:] +#Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +Bfilenames = Afilenames +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_overlap_convex=np.concatenate(arrays,axis=0) +""" + +""" +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/shift_avg_bomex*.npy')) +Bfilenames = Afilenames[5:] +#Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +Bfilenames = Afilenames +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_shift_avg=np.concatenate(arrays,axis=0) +""" +#### need to save concatenated data +####### +######################################################################## + + +############################## +#################################################### +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) diff --git a/data/convexhull1.py b/data/convexhull1.py new file mode 100644 index 0000000..5182f7e --- /dev/null +++ b/data/convexhull1.py @@ -0,0 +1,208 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Apr 2 10:18:45 2019 + +@author: anthonys +""" + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +conditional_height=100 + +file1_numb=-1 + +### accessing multiple datasets easily +begin=5 +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] + +file1numb=begin-1 + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + #cloud_numb=np.array([575]) # ricotrack828 + + + height_convex=np.zeros(cloud_numb.size) + vol_convex=np.zeros(cloud_numb.size) + projarea_convex=np.zeros(cloud_numb.size) + overlap_convex=np.zeros(cloud_numb.size) + ######################################################## convex hull + + m=0; + for e1 in cloud_numb: # may take a while to run + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] + location_matrix[:,1]=location[1] + location_matrix[:,2]=location[2] + hull_3d=ConvexHull(location_matrix, qhull_options='QJ') + height_convex[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + vol_convex[m]=dx*dy*dz*hull_3d.volume + bd_pts=hull_3d.points[hull_3d.vertices] + hull_2d=ConvexHull(bd_pts[:,1:], qhull_options='QJ') + projarea_convex[m]=dx*dy*hull_2d.volume # volume and area are named base in 3d, so the 2d volume is indeed area + overlap_convex[m]= vol_convex[m] / (height_convex[m]*projarea_convex[m]) + m=m+1 + + overlap_contra=1/overlap_ratio - 1/overlap_convex + + step=1800 # 30*60 + time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/bomex_overlap_convex" + #np.save(npyfilespath+str(time_array[file1_numb])+'.npy',overlap_convex) + + ### plotting in convex hull in 3d and 2d + """ + fig=plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*bd_pts[:,2], dy*bd_pts[:,1],dz*bd_pts[:,0], color='green'); + #ax.scatter3D(dx*location_matrix[:,2], dy*location_matrix[:,1],dz*location_matrix[:,0], color='blue'); + #ax.plot_trisurf(dx*bd_pts[:,2], dy*bd_pts[:,1],dz*bd_pts[:,0], color='grey'); + for simplex in hull_3d.simplices: + #fig=plt.figure() + #ax = plt.axes(projection='3d') + + ax.plot3D(dx*location_matrix[simplex,2], dy*location_matrix[simplex,1],dz*location_matrix[simplex,0], color='black'); + #ax.plot_trisurf(dx*location_matrix[simplex,2], dy*location_matrix[simplex,1],dz*location_matrix[simplex,0], color='grey'); + #plt.plot(points[simplex, 0], points[simplex, 1], 'k-') + + plt.title('3d Convex Hull') + plt.figure() + plt.plot(dx*bd_pts[:,2], dy*bd_pts[:,1], 'o') + for simplex in hull_2d.simplices: + plt.plot(dx*bd_pts[simplex, 2], dy*bd_pts[simplex, 1], 'k-') + plt.title('2d Convex Hull') + """ + + """ + ########################################################## + ### plot overlap + bins=dz + + plt.figure() + plt.hist2d(overlap_convex,height_convex,bins=bins,cmin=0.5) + plt.title('Height vs. Convex Hull Overlap ') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + colorbar.set_label('counts in bin') + + + plt.figure() + plt.hist2d(overlap_ratio,ht,bins=bins,cmin=0.5) + plt.title('Height vs. Actual Overlap') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + diff --git a/data/generate_data1.py b/data/generate_data1.py new file mode 100644 index 0000000..860ec69 --- /dev/null +++ b/data/generate_data1.py @@ -0,0 +1,643 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed May 22 14:46:53 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################### +conditional_height=0 +epsilon1=50 ##### helps find clds that are split by grid box +#arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +#file1_numb=-1 + +""" +datau = Dataset('/data/rico/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/rico/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/rico/w.nc','r') +time_t = datau.variables['time'][:] +step=3600;time_array= np.arange(step,216000+step,step) +case='rico' +""" +""" +datau = Dataset('/data/bomex/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/bomex/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/bomex/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(step,36000+step,step) +case='bomex' +""" +""" +datau = Dataset('/data/lasso/sims/20160830/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/lasso/sims/20160830/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/lasso/sims/20160830/w.nc','r') +""" +datau = Dataset('/data/arm/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/arm/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/arm/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(10800,52200+step,step) +case='arm' + +#begin=5 +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:8] +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[1:] +#Bfilenames = [Afilenames[22], Afilenames[55]] +#Afilenames = sorted(glob.glob('/data/lasso/sims/20160830/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = [Afilenames[23], Afilenames[41]] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:2] +Bfilenames = [Afilenames[10], Afilenames[17]] + +#file1_numb=begin-1 ## python: arrays start at index 0 +file2_numb = -1 +file3_numb = [10,17] + +################################ + + + +############################# +#### loop over trackfiles +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file2_numb = file2_numb+1 + file1_numb = file3_numb[file2_numb] + + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + ###################################################################### + #### wind and udraft calculations + + ### + access = np.where(time_t == time_array[file1_numb])[0][0] + u=datau.variables['u'][access,:,:,:] + xh=datau.variables['xh'][:] + v=datav.variables['v'][access,:,:,:] + yh=datav.variables['yh'][:] + w=dataw.variables['w'][access,:,:,:] + zh=dataw.variables['zh'][:] + ### + + uint=interp1d(xh,u,axis=2,fill_value='extrapolate') + vint=interp1d(yh,v,axis=1,fill_value='extrapolate') + wint=interp1d(zh,w,axis=0,fill_value='extrapolate') + + ut=uint(xt) + vt=vint(yt) + wt=wint(zt) + + #w=interp1d(zh,w,axis=0,fill_value='extrapolate') + #ut=u;vt=v;#wt=w; + + + ut1=np.sum(np.sum(ut,axis=1),axis=1)/(nx*ny) + vt1=np.sum(np.sum(vt,axis=1),axis=1)/(nx*ny) + #ut1=np.mean(np.mean(ut,axis=1),axis=1) + #vt1=np.mean(np.mean(vt,axis=1),axis=1) + #wt1=np.mean(np.mean(wt,axis=1),axis=1) + + + uz=ut1 + vz=vt1 + #wz=wt1 + + #uz=np.mean(u,axis=0) # avg among diff times + #vz=np.mean(v,axis=0) # avg among diff times + shear_calu=np.zeros(cb.size) + shear_calv=np.zeros(cb.size) + """ + for i in range(cb.size): + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + """ + + + #shear_cal = np.sqrt( shear_calu**2 + shear_calv**2 ) + + #shear_cal = abs(shear_calu + shear_calv) / 2 + + + + ####### + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + + + #s_u=abs(duz);s_v=abs(dvz) + s_u=duz;s_v=dvz; + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2;#Amean=abs(Amean) + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v);#Hmean=abs(Hmean) + #pyth= (s_u**2 + s_v**2)**0.5 + + shear0=np.zeros(cb.size) + shear00=np.zeros(cb.size) + for i in range(cb.size): ##### calculating shear + + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) + shear00[i] = sum(Amean[cb[i]:ct[i]+1]) + + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + + + shear_cal = abs(shear_calu + shear_calv) / 2 + + ########################################################################### + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + + ### not chopping so just set alpha=1 + alpha=np.arange(1,0,-1) # just 1 + + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + + + height_convex=np.zeros(cloud_numb.size) + vol_convex=np.zeros(cloud_numb.size) + projarea_convex=np.zeros(cloud_numb.size) + overlap_convex=np.zeros(cloud_numb.size) + + w_avg = np.zeros(index1_size) + wz_max = np.zeros(index1_size) + wz_cb = np.zeros(index1_size) + wz_ct = np.zeros(index1_size) + wz_avg = np.zeros(index1_size) + wz_min = np.zeros(index1_size) + + shift_max=np.zeros(cloud_numb.size) + shift_min=np.zeros(cloud_numb.size) + shift_avg=np.zeros(cloud_numb.size) + shift_distance=np.zeros(cloud_numb.size) + + m=-1; #m=0; + + #### loop over clds + for e1 in cloud_numb: # may take a while to run + + m = m+1 + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + #layers=height/dz + ### + + base=np.amin(location[0]);top=np.amax(location[0]); + #levels=range(base,top+1,1) + + #### test to find clds that are split by the grid box + x_unique=np.unique(location[2]) + y_unique=np.unique(location[1]) + xtest1=abs(np.mean(x_unique)-np.median(x_unique)) # median is resistant while mean is not + ytest1=abs(np.mean(y_unique)-np.median(y_unique)) + + #### reconnnects split cld , idea: moves part of cld to otherside + if xtest1 > epsilon1: + splitx=np.where(location[2] < nx/2) + location[2][splitx] = location[2][splitx] + nx + + if ytest1 > epsilon1: + splity=np.where(location[1] < ny/2) + location[1][splity] = location[1][splity] + ny + + + #sys.exit("Error message") + + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + COM=np.zeros((top-base+1,3)) + newlocation_matrix=np.zeros(location_matrix.shape) + cross_area_z=np.zeros(int(layers)) + #u, indices = np.unique(location[0], return_index=True) + #COM[:,0]=u + + ############################################################ + #### generate updraft speed data + basez=base;topz=top;basey=min(location[1]);topy=max(location[1]);basex=min(location[2]);topx=max(location[2]); + w_abs=abs(wt) + #wz_avg=np.sum(w_abs[basez:topz+1,:,:],axis=0) / (topz - basez+1) + #wy_avg=np.sum(wz_avg[basey:topy+1,:],axis=0) / (topy - basey+1) + #wx_avg=np.sum(wy_avg[basex:topx+1],axis=0) / (topx - basex+1) + ##wz_avg=np.mean(w_abs[min(location[0]):max(location[0])+1,:,:],axis=0) + ##wy_avg=np.mean(wz_avg[min(location[1]):max(location[1])+1,:],axis=0) + ##wx_avg=np.mean(wy_avg[min(location[2]):max(location[2])+1],axis=0) + #w_avg[m]=wx_avg + #print(w_avg[m]) + """ + wy_avg=np.sum(w_abs[:,basey:topy+1,:],axis=1) / (topy - basey+1) + wx_avg=np.sum(wy_avg[:,basex:topx+1],axis=1) / (topx - basex+1) + wz = wx_avg[basez:topz+1] + + wz_max[m] = np.amax(wz) + wz_cb[m] = wz[0] + wz_ct[m] = wz[-1] + wz_avg[m] = np.mean(wz) + wz_min[m] = np.amin(wz) + """ + ##################### + ### generate Convex hull data + if dz*layers >100: + hull_3d=ConvexHull(location_matrix, qhull_options='QJ') + height_convex[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + vol_convex[m]=dx*dy*dz*hull_3d.volume + bd_pts=hull_3d.points[hull_3d.vertices] + hull_2d=ConvexHull(bd_pts[:,1:], qhull_options='QJ') + projarea_convex[m]=dx*dy*hull_2d.volume # volume and area are named base in 3d, so the 2d volume is indeed area + overlap_convex[m]= vol_convex[m] / (height_convex[m]*projarea_convex[m]) + + ######################## + ##### find center of mass and area of each layer of cld + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + # height / dz = layers + + #COM[z-base,:]=[z,sum(location[1][findz[0]])/findz[0].size, sum(location[2][findz[0]])/findz[0].size] + COM[z-base,:]=[z,np.mean(location[1][findz[0]]), np.mean(location[2][findz[0]])] #find center of mass w/ arithmetic mean + + + area_z_ratio[m]= np.mean(cross_area_z)/np.amax(cross_area_z) + center_choice=[np.mean(COM[:,1]), np.mean(COM[:,2])] ### choosing pt to align COMs + movement=np.subtract(center_choice , COM[:,1:]) + for z in np.arange(base,top+1,1): ### shifting cld + findz=np.where(location[0] == z) + newlocation_matrix[findz,1:]=location_matrix[findz,1:] + movement[z-base,:] + + newlocation_matrix[:,0]=location_matrix[:,0] + + location[0][:]=newlocation_matrix[:,0] # change to calculate overlap w/ code below + location[1][:]=newlocation_matrix[:,1] + location[2][:]=newlocation_matrix[:,2] + + #####################################\ + ### calculate shift distance b/c => w = (wind diff * ht)/ shift_distance + movement1 = 25*COM[:,1:] ### having center at origin,spacing in x and y direction + shift_cld= np.sqrt(movement1[:,0]**2 + movement1[:,1]**2) + #shift_cld = (abs(movement[:,0]) + abs(movement[:,1]) ) / 2 + shift_max[m] = np.amax(shift_cld) + shift_min[m] = np.amin(shift_cld) + shift_avg[m] = np.mean(shift_cld) + shift_distance[m] = np.amax(shift_cld) - np.amin(shift_cld) + ######################################### + + ######## + + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] # fraction of cld height + #height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: ### probably dont need this loop since we are not chopping cld ht + + part_loc= part_loc +1 # to index later for diff ht levels + for i in range(location[0].size): + if dz*(location[0][i]-location[0][0]+1) <= partial: # finding all cells below chopped cld ht (take highest cell) + celltop=i + else: + break + #if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,location[0].size): + if location[0][celltop] +1 == location[0][j]: # to use partial cells + cellabove=j + elif location[0][celltop] +1 < location[0][j]: + break + #print('partial',partial) + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + if partial == height_c[m]: # difference=0, so stop at celltop + proj_area_loop1=np.zeros(celltop +1) + vol_loop1=np.zeros(celltop +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + """ + ### plotting in cld in 3d + + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2][0:celltop+1],dy*location[1][0:celltop+1], dz*location[0][0:celltop+1], c=dz*location[0][0:celltop+1] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + else: + proj_area_loop1=np.zeros(cellabove +1) + vol_loop1=np.zeros(cellabove +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + + for loc0 in range(location[0].size): ### calculating proj area and vol + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop < loc0 and loc0 <=cellabove: + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: # full cell vol + vol_loop1[loc0]=(dx*dy*dz) + elif celltop < loc0 and loc0 <=cellabove: # partial cell vol + vol_loop1[loc0]=(dx*dy*difference) + else: + break + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) # counting cells w/ ! id # & proj-ing + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + + + + #m = m+1 + + #mu1=np.mean(Total_dr) + #sigma1=np.std(Total_dr) + #Check1=[Total_dr >= mu1 + 1.96 *sigma1] + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + """ + #################################################### + ##### saving data for convex hull + #if dz*layers >100: + # overlap_contra=1/overlap_ratio - 1/overlap_convex + + + #step=1800 # 30*60 + #time_array= np.arange(step,36000+step,step) + #npyfilespath ="/home/anthonys/Documents/bomex_overlap_convex" + ### + npyfilespath ="/home/anthonys/Documents/" + + name1 = 'overlap_convex_' + + #np.save(npyfilespath+str(time_array[file1_numb])+'.npy',overlap_convex) + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',overlap_convex) + + ############################################################ + + #### save wind differentials and updraft vel. + + + #step=1800 # 30*60 + #time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='bomex' + + + name1='shearTB_' + name2='shear_sum_' + #name3='wavg1_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',shear_cal) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',shear00) + #np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',w_avg) + + name1='wz_max_' + name2='wz_min_' + name3='wz_avg_' + name4='wz_ct_' + name5='wz_cb_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',wz_max) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',wz_min) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',wz_avg) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',wz_ct) + np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',wz_cb) + + name1='shift_max_' + name2='shift_min_' + name3='shift_avg_' + name4='shift_distance' + #name5='area_z_ratio_' + + + ### + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',shift_max) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',shift_min) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',shift_avg) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',shift_distance) + #np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',area_z_ratio) + + + + ################################ + ### saving data + + + + #step=1800 # 30*60 + #time_array= np.arange(step,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='bomex' + ### + #step=3600 # 60*60 + #time_array= np.arange(step,216000+step,step) + #npyfilespath ="/home/anthonys/Documents/" + #case='rico' + ### + #step = 600 + #time_array = np.zeros(56) + #time_array[0:2] = [0,1200,6600] + #time_array[3:] = np.arange(7800,41400+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='lasso' + + name1='overlap_no_shear_' + name2='volume_no_shear_' + name3='projarea_no_shear_' + name4='height_no_shear_' + name5='area_z_ratio_' + + + ### + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',overlap_c) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',volume_c) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',projected_area_c) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',height_c) + np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',area_z_ratio) + + + #np.save(npyfilespath+str(time_array[20])+'.npy',area_z_ratio) + + + + ########################### + """ + + + + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + diff --git a/data/graph3d_1.py b/data/graph3d_1.py new file mode 100644 index 0000000..3eee71c --- /dev/null +++ b/data/graph3d_1.py @@ -0,0 +1,431 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 21 11:25:54 2019 + +@author: anthonys +""" + + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# def + +def overlap(s,h,l): + #return l / (l +s*h) + return 1 - (s*h / (l + s*h)) +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack36] +ricofilenames=[ricotrack828] +armfilenames=[armtrack522] +conditional_height=0 + + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=2000 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + #cloud_numb=np.array([575]) # ricotrack828 + + ##################################################### shear + + + + uz=np.mean(u,axis=0) # avg among diff times + vz=np.mean(v,axis=0) # avg among diff times + wz=np.mean(w,axis=0) + + wint=interp1d(zh,wz,axis=0) + wz1=wint(zt) + + + one=np.ones(wz1.size) + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + #s_u=duz/np.maximum(wz1,one) + #s_v=dvz/np.maximum(wz1,one) + s_u=abs(duz)/np.maximum(wz1,one) + s_v=abs(dvz)/np.maximum(wz1,one) + + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2 + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0=np.zeros(cb.size) + shear1=np.zeros(cb.size) + for i in range(cb.size): + """ + du=uz[ct[i]]-uz[cb[i]] + dv=vz[ct[i]]-vz[cb[i]] + #w1=np.mean(wz1[cb[i]:ct[i]+1]) + su=du #/max(w1,1) + sv=dv #/max(w1,1) + #Hmean=(2*su*sv) / max( (su + sv) , 1) + Amean = (su+sv)/2 + shear0[i]= Amean #Hmean + """ + """ + s_u=sum(duz[cb[i]:ct[i]+1]) + s_v=sum(dvz[cb[i]:ct[i]+1]) + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0[i] = Hmean + """ + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + #shear0[i] = np.mean(Hmean[cb[i]:ct[i]+1]) + #shear0[i] = Hmean[ct[i]] - Hmean[cb[i]] + + + bins=2*dz + + plt.figure() + plt.hist2d(overlap_ratio,abs(shear0),bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + #plt.ylim([0,10]) + #plt.ylim([min(shear0),max(shear0)]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + + + ######################################### width + + shear=np.zeros(cloud_numb.size) + """ + width=np.zeros(cloud_numb.size) + widthx=np.zeros(cloud_numb.size) + widthy=np.zeros(cloud_numb.size) + """ + k=5 + width_base=np.zeros(cloud_numb.size) + widthx_base=np.zeros(k) + widthy_base=np.zeros(k) + + width_top=np.zeros(cloud_numb.size) + widthx_top=np.zeros(k) + widthy_top=np.zeros(k) + + m=0 + for e1 in cloud_numb: # may take a while to run + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + """ + ### calculating width of a cld by taking a max of a max + widthx[m]=dx*(np.amax(location[2]) - np.amin(location[2]) + 1) + widthy[m]=dy*(np.amax(location[1]) - np.amin(location[1]) + 1) + + #width[m] = max(widthx[m], widthy[m]) + #width[m] = 0.5*widthx[m] + 0.5*widthy[m] # arithmetic mean + width[m] = ( widthx[m]*widthy[m] )**(1/2) # geometric mean + """ + ########################## + + if dz*k > ht[e1-1]: + k=int(ht[e1-1]/dz) + widthx_base=np.zeros(k) + widthy_base=np.zeros(k) + #widthx_top=np.zeros(k) + #widthy_top=np.zeros(k) + + ### want to take max of bottom layers + base=np.amin(location[0]) + + for i in range(base,base+k): + + L=np.where(location[0] == i) + + widthx_base[i-base]=dx*(np.amax(location[2][L]) - np.amin(location[2][L]) + 1) + widthy_base[i-base]=dy*(np.amax(location[1][L]) - np.amin(location[1][L]) + 1) + + + #width_base[m] =max(np.amax(widthx_base), np.amax(widthy_base)) + width_base[m] = ( np.amax(widthx_base)*np.amax(widthy_base) )**(0.5) + + """ + ### want to take max of top layers + top=np.amax(location[0]) + + for i in range(top-k,top): + + L=np.where(location[0] == i) + + widthx_top[i-top+k]=dx*(np.amax(location[2][L]) - np.amin(location[2][L]) + 1) + widthy_top[i-top+k]=dy*(np.amax(location[1][L]) - np.amin(location[1][L]) + 1) + + + #width_top[m] =max(np.amax(widthx_top), np.amax(widthy_top)) + width_top[m] = ( np.amax(widthx_top)*np.amax(widthy_top) )**(0.5) + + """ + + + + shear[m]=shear0[e1-1] + + + + ### plotting in cld in 3d + """ + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2], dy*location[1], dz*location[0], c=dz*location[0] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + #### ploting z vs. x or z vs. x in scatter plots + """ + plt.figure() + plt.plot(dx*location[2], dz*location[0],'go') + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + plt.figure() + plt.plot(dy*location[1], dz*location[0],'go') + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + """ + #### ploting z vs. x or z vs. x in 2d historgrams + """ + bins=dz + plt.figure() + plt.hist2d(dx*location[2],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + m=m+1 + """ + plt.figure() + plt.plot(overlap(abs(shear),ht_anvil,width_base,np.ones(5)),ht_anvil,'o') + plt.figure() + plt.plot(overlap_ratio_anvil,ht_anvil,'*') + """ + bins=dz + plt.figure() + plt.hist2d(overlap(abs(shear),ht_anvil,width_base),ht_anvil,bins=bins,cmin=0.5) + plt.title('Calculated Overlap vs. height') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(overlap_ratio_anvil,ht_anvil,bins=bins,cmin=0.5) + plt.title('Actual Overlap vs. height') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/graph3d_2.py b/data/graph3d_2.py new file mode 100644 index 0000000..264736d --- /dev/null +++ b/data/graph3d_2.py @@ -0,0 +1,262 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Mar 28 14:13:44 2019 + +@author: anthonys +""" + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# def + +def overlap(s,h,l): + #return l / (l +s*h) + return 1 - (s*h / (l + s*h)) +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack36] +ricofilenames=[ricotrack828] +armfilenames=[armtrack522] +conditional_height=2000 + +### choose which case and track file + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=2000 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + cloud_numb=np.array([533,860,1991,2004]) # ricotrack828 + + + + m=0 + for e1 in cloud_numb: # may take a while to run + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + + + + """ + ### plotting in cld in 3d + + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2], dy*location[1], dz*location[0], c=dz*location[0] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + #### ploting z vs. x or z vs. x in scatter plots + """ + plt.figure() + plt.plot(dx*location[2], dz*location[0],'go') + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + plt.figure() + plt.plot(dy*location[1], dz*location[0],'go') + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + """ + #### ploting z vs. x or z vs. x in 2d historgrams + + bins=dz + plt.figure() + plt.hist2d(dx*location[2],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + m=m+1 + + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + diff --git a/data/h_shape_rico2016.npy b/data/h_shape_rico2016.npy new file mode 100644 index 0000000..be44d0c Binary files /dev/null and b/data/h_shape_rico2016.npy differ diff --git a/data/h_shape_rico828.npy b/data/h_shape_rico828.npy new file mode 100644 index 0000000..7e6d571 Binary files /dev/null and b/data/h_shape_rico828.npy differ diff --git a/data/h_shear_rico2016.npy b/data/h_shear_rico2016.npy new file mode 100644 index 0000000..a2748e9 Binary files /dev/null and b/data/h_shear_rico2016.npy differ diff --git a/data/h_shear_rico828.npy b/data/h_shear_rico828.npy new file mode 100644 index 0000000..efb007c Binary files /dev/null and b/data/h_shear_rico828.npy differ diff --git a/data/h_turb_rico2016.npy b/data/h_turb_rico2016.npy new file mode 100644 index 0000000..6a9c52f Binary files /dev/null and b/data/h_turb_rico2016.npy differ diff --git a/data/h_turb_rico828.npy b/data/h_turb_rico828.npy new file mode 100644 index 0000000..30bb085 Binary files /dev/null and b/data/h_turb_rico828.npy differ diff --git a/data/height_no_shear_arm28800.npy b/data/height_no_shear_arm28800.npy new file mode 100644 index 0000000..d634457 Binary files /dev/null and b/data/height_no_shear_arm28800.npy differ diff --git a/data/height_no_shear_arm41400.npy b/data/height_no_shear_arm41400.npy new file mode 100644 index 0000000..329cadd Binary files /dev/null and b/data/height_no_shear_arm41400.npy differ diff --git a/data/height_no_shear_bomex10800.npy b/data/height_no_shear_bomex10800.npy new file mode 100644 index 0000000..8824d72 Binary files /dev/null and b/data/height_no_shear_bomex10800.npy differ diff --git a/data/height_no_shear_bomex12600.npy b/data/height_no_shear_bomex12600.npy new file mode 100644 index 0000000..2cd58b9 Binary files /dev/null and b/data/height_no_shear_bomex12600.npy differ diff --git a/data/height_no_shear_bomex14400.npy b/data/height_no_shear_bomex14400.npy new file mode 100644 index 0000000..d961925 Binary files /dev/null and b/data/height_no_shear_bomex14400.npy differ diff --git a/data/height_no_shear_bomex16200.npy b/data/height_no_shear_bomex16200.npy new file mode 100644 index 0000000..b031a23 Binary files /dev/null and b/data/height_no_shear_bomex16200.npy differ diff --git a/data/height_no_shear_bomex18000.npy b/data/height_no_shear_bomex18000.npy new file mode 100644 index 0000000..c4f07b7 Binary files /dev/null and b/data/height_no_shear_bomex18000.npy differ diff --git a/data/height_no_shear_bomex19800.npy b/data/height_no_shear_bomex19800.npy new file mode 100644 index 0000000..bb048d5 Binary files /dev/null and b/data/height_no_shear_bomex19800.npy differ diff --git a/data/height_no_shear_bomex21600.npy b/data/height_no_shear_bomex21600.npy new file mode 100644 index 0000000..74a9258 Binary files /dev/null and b/data/height_no_shear_bomex21600.npy differ diff --git a/data/height_no_shear_bomex23400.npy b/data/height_no_shear_bomex23400.npy new file mode 100644 index 0000000..620ee9a Binary files /dev/null and b/data/height_no_shear_bomex23400.npy differ diff --git a/data/height_no_shear_bomex25200.npy b/data/height_no_shear_bomex25200.npy new file mode 100644 index 0000000..04dc2dd Binary files /dev/null and b/data/height_no_shear_bomex25200.npy differ diff --git a/data/height_no_shear_bomex27000.npy b/data/height_no_shear_bomex27000.npy new file mode 100644 index 0000000..6f8c69f Binary files /dev/null and b/data/height_no_shear_bomex27000.npy differ diff --git a/data/height_no_shear_bomex28800.npy b/data/height_no_shear_bomex28800.npy new file mode 100644 index 0000000..aeb3185 Binary files /dev/null and b/data/height_no_shear_bomex28800.npy differ diff --git a/data/height_no_shear_bomex30600.npy b/data/height_no_shear_bomex30600.npy new file mode 100644 index 0000000..4909ca7 Binary files /dev/null and b/data/height_no_shear_bomex30600.npy differ diff --git a/data/height_no_shear_bomex32400.npy b/data/height_no_shear_bomex32400.npy new file mode 100644 index 0000000..a2e069a Binary files /dev/null and b/data/height_no_shear_bomex32400.npy differ diff --git a/data/height_no_shear_bomex34200.npy b/data/height_no_shear_bomex34200.npy new file mode 100644 index 0000000..70a9f0e Binary files /dev/null and b/data/height_no_shear_bomex34200.npy differ diff --git a/data/height_no_shear_bomex360.npy b/data/height_no_shear_bomex360.npy new file mode 100644 index 0000000..c21d660 Binary files /dev/null and b/data/height_no_shear_bomex360.npy differ diff --git a/data/height_no_shear_bomex36000.npy b/data/height_no_shear_bomex36000.npy new file mode 100644 index 0000000..c21d660 Binary files /dev/null and b/data/height_no_shear_bomex36000.npy differ diff --git a/data/height_no_shear_lasso306.npy b/data/height_no_shear_lasso306.npy new file mode 100644 index 0000000..cb67102 Binary files /dev/null and b/data/height_no_shear_lasso306.npy differ diff --git a/data/height_no_shear_rico2016.npy b/data/height_no_shear_rico2016.npy new file mode 100644 index 0000000..41fcaa6 Binary files /dev/null and b/data/height_no_shear_rico2016.npy differ diff --git a/data/height_no_shear_rico828.npy b/data/height_no_shear_rico828.npy new file mode 100644 index 0000000..8a1e472 Binary files /dev/null and b/data/height_no_shear_rico828.npy differ diff --git a/data/model_inv_rico2016.npy b/data/model_inv_rico2016.npy new file mode 100644 index 0000000..b7b3cdd Binary files /dev/null and b/data/model_inv_rico2016.npy differ diff --git a/data/model_opt2_rico2016.npy b/data/model_opt2_rico2016.npy new file mode 100644 index 0000000..7a43507 Binary files /dev/null and b/data/model_opt2_rico2016.npy differ diff --git a/data/model_opt_rico2016.npy b/data/model_opt_rico2016.npy new file mode 100644 index 0000000..e22a20a Binary files /dev/null and b/data/model_opt_rico2016.npy differ diff --git a/data/model_rico2016.npy b/data/model_rico2016.npy new file mode 100644 index 0000000..65ee4a2 Binary files /dev/null and b/data/model_rico2016.npy differ diff --git a/data/overlap_anvil1.py b/data/overlap_anvil1.py new file mode 100644 index 0000000..4f750fe --- /dev/null +++ b/data/overlap_anvil1.py @@ -0,0 +1,212 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Feb 6 11:41:38 2019 + +@author: anthonys +""" + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +import collections +from collections import Counter +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script + +bomexfilenames=[bomextrack18] + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + #nrcloudlist=nrcloudarray.tolist() + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells + uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + volume=dx*dy*dz*count_elmts + + #A=np.where(nrcloudarray==158) + #Ma=np.amax(A[1]) + #Mi=np.amin(A[1]) + #H=Ma-Mi+1 + # height, projected area + """ + vert_res=25 + height=np.zeros(uni_elmts.size) + #locx=[] + projected_area=np.zeros(uni_elmts.size) + for e1 in uni_elmts: # ~13 min to run + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + height[e1-1]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #locx.append(location[2]+location[1]*nx) + projected_area[e1-1]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + """ + + + + #overlap=volume/(height*projected_area) + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/overlap_calculation.py b/data/overlap_calculation.py new file mode 100644 index 0000000..a2fffb4 --- /dev/null +++ b/data/overlap_calculation.py @@ -0,0 +1,200 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 7 11:50:04 2019 + +@author: anthonys +""" + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +import collections +from collections import Counter +############################################## + + +""" +def overlap_calculation(index,nrcloudarray,xt,yt,zt): + + + index7=np.asarray(index) + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells + uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + uninew=[];countnew=[] + for uni in range(uni_elmts.size): + for i in range(index7.size): + if uni_elmts[uni] == index7[i]: + uninew.append(index7[i]) + countnew.append(count_elmts[index7[i]]) + uninew1=np.asarray(uninew) + countnew1=np.asarray(countnew) + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + volume_c=dx*dy*dz*countnew1 + + + #vert_res=25 + height_c=np.zeros(uninew1.size) + projected_area_c=np.zeros(uninew1.size) + m=0; + for e1 in uninew1: # may take a while to run + location=np.where(nrcloudarray == e1+1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + m = m+1 + + + + overlap_c=volume_c/(height_c*projected_area_c) + + return overlap_c, volume_c, height_c, projected_area_c +""" + +def overlap_calculation(index1,nrcloudarray,xt,yt,zt): + + + index7=np.asarray(index1) + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells + uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + uninew=[];countnew=[] + for uni in range(uni_elmts.size): + for i in range(index7.size): + if uni_elmts[uni] == index7[i]: + uninew.append(index7[i]) + countnew.append(count_elmts[index7[i]]) + uninew1=np.asarray(uninew) + countnew1=np.asarray(countnew) + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + volume_c=dx*dy*dz*countnew1 + + + #vert_res=25 + height_c=np.zeros(uninew1.size) + projected_area_c=np.zeros(uninew1.size) + m=0; + #alpha=[1.0] #, 0.9, 0.8, 0.7, 0.6, 0.5,0.2] + #alpha=np.asarray(alpha) + alpha=np.arange(1,0.15,-0.05) + for e1 in uninew1: # may take a while to run + + + location=np.where(nrcloudarray == e1+1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] + height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: + celltop=0 + part_loc= part_loc +1 + proj_area_loop1=[] + vol_loop1=[] + for i in range(location[0].size): + if dz*(location[0][i]-location[0][0]+1) <= partial: + celltop=i + if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) + for j in range(celltop,location[0].size): + if location[0][celltop] +1 == location[0][j]: + cellabove=j + #loc_loc0=-1 + for loc0 in range(location[0].size): + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + if celltop < loc0 and loc0 <=cellabove: + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: + vol_loop1.append(dx*dy*dz) + if celltop < loc0 and loc0 <=cellabove: + vol_loop1.append(dx*dy*difference) + #if dz*loc0 < parital: + proj_area_loop1=np.asarray(proj_area_loop1) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) + vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + plt.plot(overlap_changed,alpha,'o-') + #plt.xlim([0, 1]) + #plt.plot(overlap_changed,height_c[m],'o') + #plt.plot(overlap_ratio_new1,htnew1,'o') + m = m+1 + + + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + + + return overlap_c, volume_c, height_c, projected_area_c, height_diff + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/overlap_convex_arm28800.npy b/data/overlap_convex_arm28800.npy new file mode 100644 index 0000000..9c77506 Binary files /dev/null and b/data/overlap_convex_arm28800.npy differ diff --git a/data/overlap_convex_arm41400.npy b/data/overlap_convex_arm41400.npy new file mode 100644 index 0000000..8600efb Binary files /dev/null and b/data/overlap_convex_arm41400.npy differ diff --git a/data/overlap_convex_rico201600.npy b/data/overlap_convex_rico201600.npy new file mode 100644 index 0000000..48864e7 Binary files /dev/null and b/data/overlap_convex_rico201600.npy differ diff --git a/data/overlap_convex_rico82800.npy b/data/overlap_convex_rico82800.npy new file mode 100644 index 0000000..836c85f Binary files /dev/null and b/data/overlap_convex_rico82800.npy differ diff --git a/data/overlap_no_shear_arm28800.npy b/data/overlap_no_shear_arm28800.npy new file mode 100644 index 0000000..63478b4 Binary files /dev/null and b/data/overlap_no_shear_arm28800.npy differ diff --git a/data/overlap_no_shear_arm41400.npy b/data/overlap_no_shear_arm41400.npy new file mode 100644 index 0000000..e377e0c Binary files /dev/null and b/data/overlap_no_shear_arm41400.npy differ diff --git a/data/overlap_no_shear_bomex10800.npy b/data/overlap_no_shear_bomex10800.npy new file mode 100644 index 0000000..829bb90 Binary files /dev/null and b/data/overlap_no_shear_bomex10800.npy differ diff --git a/data/overlap_no_shear_bomex12600.npy b/data/overlap_no_shear_bomex12600.npy new file mode 100644 index 0000000..74cc39b Binary files /dev/null and b/data/overlap_no_shear_bomex12600.npy differ diff --git a/data/overlap_no_shear_bomex14400.npy b/data/overlap_no_shear_bomex14400.npy new file mode 100644 index 0000000..a8c2a95 Binary files /dev/null and b/data/overlap_no_shear_bomex14400.npy differ diff --git a/data/overlap_no_shear_bomex16200.npy b/data/overlap_no_shear_bomex16200.npy new file mode 100644 index 0000000..22472b9 Binary files /dev/null and b/data/overlap_no_shear_bomex16200.npy differ diff --git a/data/overlap_no_shear_bomex18000.npy b/data/overlap_no_shear_bomex18000.npy new file mode 100644 index 0000000..d50f82b Binary files /dev/null and b/data/overlap_no_shear_bomex18000.npy differ diff --git a/data/overlap_no_shear_bomex19800.npy b/data/overlap_no_shear_bomex19800.npy new file mode 100644 index 0000000..aa50a4e Binary files /dev/null and b/data/overlap_no_shear_bomex19800.npy differ diff --git a/data/overlap_no_shear_bomex21600.npy b/data/overlap_no_shear_bomex21600.npy new file mode 100644 index 0000000..d14dcfb Binary files /dev/null and b/data/overlap_no_shear_bomex21600.npy differ diff --git a/data/overlap_no_shear_bomex23400.npy b/data/overlap_no_shear_bomex23400.npy new file mode 100644 index 0000000..3df6dee Binary files /dev/null and b/data/overlap_no_shear_bomex23400.npy differ diff --git a/data/overlap_no_shear_bomex25200.npy b/data/overlap_no_shear_bomex25200.npy new file mode 100644 index 0000000..d6ce291 Binary files /dev/null and b/data/overlap_no_shear_bomex25200.npy differ diff --git a/data/overlap_no_shear_bomex27000.npy b/data/overlap_no_shear_bomex27000.npy new file mode 100644 index 0000000..c8eb32f Binary files /dev/null and b/data/overlap_no_shear_bomex27000.npy differ diff --git a/data/overlap_no_shear_bomex28800.npy b/data/overlap_no_shear_bomex28800.npy new file mode 100644 index 0000000..f157030 Binary files /dev/null and b/data/overlap_no_shear_bomex28800.npy differ diff --git a/data/overlap_no_shear_bomex30600.npy b/data/overlap_no_shear_bomex30600.npy new file mode 100644 index 0000000..2ab41cc Binary files /dev/null and b/data/overlap_no_shear_bomex30600.npy differ diff --git a/data/overlap_no_shear_bomex32400.npy b/data/overlap_no_shear_bomex32400.npy new file mode 100644 index 0000000..a10d3dc Binary files /dev/null and b/data/overlap_no_shear_bomex32400.npy differ diff --git a/data/overlap_no_shear_bomex34200.npy b/data/overlap_no_shear_bomex34200.npy new file mode 100644 index 0000000..bb21666 Binary files /dev/null and b/data/overlap_no_shear_bomex34200.npy differ diff --git a/data/overlap_no_shear_bomex360.npy b/data/overlap_no_shear_bomex360.npy new file mode 100644 index 0000000..9175169 Binary files /dev/null and b/data/overlap_no_shear_bomex360.npy differ diff --git a/data/overlap_no_shear_bomex36000.npy b/data/overlap_no_shear_bomex36000.npy new file mode 100644 index 0000000..9175169 Binary files /dev/null and b/data/overlap_no_shear_bomex36000.npy differ diff --git a/data/overlap_no_shear_lasso306.npy b/data/overlap_no_shear_lasso306.npy new file mode 100644 index 0000000..175ebf7 Binary files /dev/null and b/data/overlap_no_shear_lasso306.npy differ diff --git a/data/overlap_no_shear_rico2016.npy b/data/overlap_no_shear_rico2016.npy new file mode 100644 index 0000000..1c6c7fa Binary files /dev/null and b/data/overlap_no_shear_rico2016.npy differ diff --git a/data/overlap_no_shear_rico828.npy b/data/overlap_no_shear_rico828.npy new file mode 100644 index 0000000..98a8f70 Binary files /dev/null and b/data/overlap_no_shear_rico828.npy differ diff --git a/data/overlap_width_cv.py b/data/overlap_width_cv.py new file mode 100644 index 0000000..0b02326 --- /dev/null +++ b/data/overlap_width_cv.py @@ -0,0 +1,509 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 27 17:03:07 2019 + +@author: anthonys +""" + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# def +""" +def overlap(s,h,l): + #return l / (l +s*h) + return 1 - (s*h / (l + s*h)) +""" +def overlap1(s,h,l,w): + alpha= 1 / (1+w) + 1 + return 1 - (alpha*0.5*s*h / (l + s*h)) + +def overlap2(s,h,l): + #return l / (l +s*h) + B=1/(1+(h/l)) + return 1 - (B*s*h / (l + B*s*h)) + +def overlap_inv1(s,h,l): + #return l / (l +s*h) + B=h/l + #return 1 + ( (B*s*h) / l) + return ( (B*s*h) / l) + +def opt_fun1(X,B): + #return l / (l +s*h) + #B=1*h/l + s,h,l = X + return ( (B*s*h) / l) + +def shearpar(X,gs): + h,l = X + return gs * (h/l) + + +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack360] +ricofilenames=[ricotrack828] +armfilenames=[armtrack522] +conditional_height=0 + + +fractal= (6*np.sqrt(3)) / (5*np.pi) + +### rico828 +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') + +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +""" +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=2000 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + #cloud_numb=np.array([575]) # ricotrack828 + + ##################################################### shear + + + + uz=np.mean(u,axis=0) # avg among diff times + vz=np.mean(v,axis=0) # avg among diff times + wz=np.mean(w,axis=0) + + UVz= (2*uz*vz)/(uz+vz) + #UVz= (uz**2 + vz **2)**0.5 + + wint=interp1d(zh,wz,axis=0) + wz1=wint(zt) + + + one=np.ones(wz1.size) + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + + #s_u=duz/np.maximum(wz1,one) + #s_v=dvz/np.maximum(wz1,one) + s_u=abs(duz)/np.maximum(wz1,one) + s_v=abs(dvz)/np.maximum(wz1,one) + + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2 + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v) + pyth= (s_u**2 + s_v**2)**0.5 + + shear0=np.zeros(cb.size) + w_cld=np.zeros(cb.size) + for i in range(cb.size): + """ + du=uz[ct[i]]-uz[cb[i]] + dv=vz[ct[i]]-vz[cb[i]] + #w1=np.mean(wz1[cb[i]:ct[i]+1]) + su=du #/max(w1,1) + sv=dv #/max(w1,1) + #Hmean=(2*su*sv) / max( (su + sv) , 1) + Amean = (su+sv)/2 + shear0[i]= Amean #Hmean + """ + """ + s_u=sum(duz[cb[i]:ct[i]+1]) + s_v=sum(dvz[cb[i]:ct[i]+1]) + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0[i] = Hmean + """ + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + + #shear0[i] = abs(UVz[ct[i]] - UVz[cb[i]]) + + + #shear0[i] = np.mean(Hmean[cb[i]:ct[i]+1]) + #shear0[i] = Hmean[ct[i]] - Hmean[cb[i]] + w_cld[i]=np.mean(wz1[cb[i]:ct[i]+1]) + + """ + bins=2*dz + + plt.figure() + plt.hist2d(overlap_ratio,abs(shear0),bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + #plt.ylim([0,10]) + #plt.ylim([min(shear0),max(shear0)]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + """ + + + + beta_find=( ((1/overlap)-1)*cv**(0.5) ) / (abs(shear0)*ht_anvil ) + + + + bins=dz + """ + plt.figure() + plt.hist2d(overlap1(abs(shear0),ht_anvil,(cv)**(1/2),w_cld),ht_anvil,bins=bins,cmin=0.5) + plt.title('Height vs. Calculated Overlap') + plt.xlim([0,1.0]) + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + plt.figure() + plt.hist2d(overlap(abs(shear0),ht_anvil,(cv)**(1/2)),ht_anvil,bins=bins,cmin=0.5) + plt.title('Height vs. Calculated Overlap') + plt.xlim([0,1]) + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + plt.figure() + plt.hist2d(overlap_ratio_anvil,ht_anvil,bins=bins,cmin=0.5) + plt.title('Height vs. Actual Overlap') + plt.xlim([0,1]) + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + """ + """ + plt.figure() + plt.hist2d(1/overlap1(abs(shear0),ht_anvil,(cv)**(1/2),w_cld),1/overlap_ratio,bins=bins,cmin=2.0) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.title('Model Comparison') + #plt.xlim([0,1.0]) + plt.xlim(left=0) + plt.ylim(bottom=0) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + """ + + + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + beta_find=( ((shear))*cv**(0.5) ) / (abs(shear0)*ht_anvil ) + l=cv**(1/2) + Model_inv=overlap_inv1(abs(shear0),ht_anvil,l) + bins=3*dz + plt.figure() + ###Note: cmin=5 here while we usually have cmin=2 , or ... cmin=2 and have bins=2*dz + plt.hist2d(Model_inv,1/overlap_ratio,bins=[4*dz,1*dz],cmin=3.0) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.title('Model Comparison') + #plt.xlim([0,1.0]) + plt.xlim(left=0) + plt.ylim(bottom=0) + plt.xlim([0,10]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + plt.figure() + ###Note: cmin=5 here while we usually have cmin=2 , or ... cmin=2 and have bins=2*dz + plt.hist2d(shear0,ht,bins=[1*dz,1*dz],cmin=3.0) + #plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.title('Ht vs. Shear') + #plt.xlim([0,1.0]) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,15]) + plt.xlabel('Shear') + plt.ylabel('Ht') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + + + + cmin=3.0 + + X1=(abs(shear0),ht_anvil,cv**0.5) + opt1, cov1 = curve_fit(opt_fun1, X1 , shear) + model_opt1=opt_fun1(X1,*opt1) + + plt.figure() + plt.hist2d(model_opt1, shear, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + + """ + + #### + #when cmin=3, some (outlier) clds are not shown, this clds have rinv > 5 + ## be careful here , only run once + non_out= np.where(model_opt1<5) + ##### + + X2=(abs(shear0[non_out]),ht_anvil[non_out],cv[non_out]**0.5) + opt2, cov2 = curve_fit(opt_fun1, X2 ,1/overlap[non_out]) + model_opt2=opt_fun1((abs(shear0[non_out]),ht_anvil[non_out],cv[non_out]**0.5),*opt2) + + #opt2=np.float64([2.4]) + + plt.figure() + plt.hist2d(opt_fun1(X2,*opt2), 1/overlap[non_out], bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + shear=opt_fun1(X1,*opt2) + #r_total = ( (1/(overlap)) + (1/areaz) + (1/fractal) ) -3 # correction: need to subtract 1 from each + #r_total = ( ((shear)) + (1/areaz) + (1/fractal) ) -3 # correction: need to subtract 1 from each + + + horizontal= shear + vertical= 1/overlap + + plt.figure() + plt.hist2d(horizontal, vertical, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + plt.xlim([0,5]) + plt.ylim([0,5]) + """ + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + diff --git a/data/parmfit1.py b/data/parmfit1.py new file mode 100644 index 0000000..7fadf47 --- /dev/null +++ b/data/parmfit1.py @@ -0,0 +1,380 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon May 20 11:32:06 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import matplotlib.colors as colors +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + + + +################################################ +start=time.time() + + +def shearpar(X,gs): + h,l = X + return gs * (h/l) + + +def shearpar2(X,gs): + h,l = X + return gs * (h/l)**2 + + +def turbpar(h,g): + return g*h + +def multi1(X,parm1,parm2,parm3): + h,l,V = X + return parm1*h+parm2*l+parm3*V + + +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + + +#################################################### + +### rico828 +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') + +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +""" + + + + + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +#Bfilenames = Afilenames[5:6] +Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + """ + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + """ + + + + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + """ + ### upper bound to turb + lam = np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + keep=np.argwhere(fractalf >1.5*lam-1) + fractalf[np.array(keep)]=1.5*lam-1 + """ + + ### upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + l=cv**0.5 + + """ + cmin=1 + l=cv**0.5 + V=volume + X1=(ht,l,V) + opt1, cov1 = curve_fit(multi1, X1 , shear) + model_opt1=multi1(X1,*opt1) + + plt.figure() + plt.hist2d(shear, model_opt1, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + cmin=1 + l=cv**0.5 + X1=(ht,l) + opt1, cov1 = curve_fit(shearpar, X1 , shear,p0=2) + model_opt1=shearpar(X1,*opt1) + + plt.figure() + plt.hist2d(ht/l, model_opt1, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + + + ht_sort=np.sort(ht) + ht_arg=np.argsort(ht) + fractalf_sort=np.zeros(fractalf.size) + count=-1 + for i in ht_arg: + count= count+1 + fractalf_sort[count]=fractalf[i] + + cmin=1 + l=cv**0.5 + X2=ht + opt2, cov2 = curve_fit(turbpar, X2 , fractalf) + model_opt2=turbpar(X2,*opt2) + + plt.figure() + plt.hist2d(ht,model_opt2, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + """ + + """ + ### curve fit binned data + opt_t, cov_t = curve_fit(f_turb , ht, fractalf) + + c=opt_t + model_turb=f_turb(ht,c) + + + bins=1*dz; + + plt.figure(); + plt.hist2d(ht,model_turb,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + + + plt.title('Effect of Turbulence'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + + plt.xlabel('ht') + plt.ylabel('Cal Overlap') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + """ + + plt.figure() + plt.plot(ht,fractalf,'o') + z= np.polyfit(ht, fractalf,3) + p=np.poly1d(z) + plt.plot(ht,p(ht),'o') + + + plt.figure() + plt.plot(fractalf,p(ht),'o') + plt.plot(fractalf,fractalf) + + + #plt.figure() + ##plt.plot(fractalf-p(ht),'o') # residual plot + + #plt.hist(fractalf-p(ht)) + + plt.figure() + plt.hist2d(ht,fractalf - p(ht), bins=25,cmin=1) # res plt + plt.clim(0,200) + plt.plot(ht,np.zeros(ht.size),'k',linewidth=3) + + z_t = z;p_t=p + + plt.figure() + plt.plot(ht/l,shear,'o') + z= np.polyfit(ht/l, shear,3) + p=np.poly1d(z) + plt.plot(ht/l,p(ht/l),'o') + + + plt.figure() + plt.plot(shear,p(ht/l),'o') + plt.plot(shear,shear) + + plt.figure() + plt.hist2d(ht/l,shear - p(ht/l), bins=25,cmin=1) # res plt + plt.clim(0,200) + plt.plot(ht/l,np.zeros(ht.size),'k',linewidth=3) + z_s = z;p_s=p + + + plt.figure() + plt.plot(ht,shape,'o') + z= np.polyfit(ht, shape,3) + p=np.poly1d(z) + plt.plot(ht,p(ht),'o') + + + plt.figure() + plt.plot(shape,p(ht),'o') + plt.plot(shape,shape) + + plt.figure() + plt.hist2d(ht,shape - p(ht), bins=25,cmin=1) # res plt + plt.clim(0,200) + plt.plot(ht,np.zeros(ht.size),'k',linewidth=3) + z_a = z;p_a=p + + + + p_c = p_s(ht/l) + p_t(ht) + p_a(ht) +1 + + + + plt.figure() + plt.plot(p_c,1/overlap_ratio,'o') + plt.plot(p_c,p_c) + + plt.figure() + plt.hist2d(p_c,1/overlap_ratio, bins=dz , cmin=3) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) \ No newline at end of file diff --git a/data/percentcloud2.py b/data/percentcloud2.py new file mode 100644 index 0000000..b05203a --- /dev/null +++ b/data/percentcloud2.py @@ -0,0 +1,509 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 7 11:51:46 2019 + +@author: anthonys +""" +""" +calculates overlap ratio base on ht of cld from chopping the cld at the top + + +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation + +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +##### choose case and track file +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack36] +armfilenames=[armtrack522] +conditional_height=1500 + +kt=0; +file_numb=-1 +file1_numb=-1 + +for file in filenames: + file_numb = file_numb+1 + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + file1_numb = file1_numb+1 + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + + + ### take cloud that satisfy conditional ht + + #conditional_height=1500 + index_anvil=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + print('conditional height is',conditional_height,'meters') + + + + + + +############################################################################ + # calculate overlap of a cld that at some of its height chopped off at the top + + + index7=index_anvil[0] # to make easy on coder + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + #countnew1=count_elmts[index7] # dont need as vol is calculatd in for loop + + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + + #cloud_numb=np.array([533]) # choosing a particular cld + #vert_res=25 + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + m=0; + ###### choppong cld at a certain fractional ht + #alpha=np.arange(1,0,-1) # just 1 + alpha=np.arange(1,0.35,-0.1) # fraction + #alpha=np.array([0.7,0.5,0.3,0.1]) + + #Dist=np.zeros((cloud_numb.size , alpha.size -1)) + #Dcurve=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve2=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve3=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + + Total_dr=np.zeros((cloud_numb.size,alpha.size -1)) # multi dimensional array + mu=np.zeros(cloud_numb.size) + sigma=np.zeros(cloud_numb.size) + Keeptrack_tdr=np.zeros((cloud_numb.size,3)) #make abitrarily big + alpha_matrix=np.zeros((cloud_numb.size,alpha.size)) + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + + ##### loop for clouds + for e1 in cloud_numb: # may take a while to run + + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] # fraction of cld height + #height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: ### loop over fractional hts of cld + + part_loc= part_loc +1 # to index later for diff ht levels + for i in range(location[0].size): + if dz*(location[0][i]-location[0][0]+1) <= partial: # finding all cells below chopped cld ht (take highest cell) + celltop=i + else: + break + #if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,location[0].size): #### find top grid pts + if location[0][celltop] +1 == location[0][j]: # to use partial cells + cellabove=j + elif location[0][celltop] +1 < location[0][j]: + break + #print('partial',partial) + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + if partial == height_c[m]: # difference=0, so stop at celltop + proj_area_loop1=np.zeros(celltop +1) + vol_loop1=np.zeros(celltop +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + else: + proj_area_loop1=np.zeros(cellabove +1) + vol_loop1=np.zeros(cellabove +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + + for loc0 in range(location[0].size): + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop < loc0 and loc0 <=cellabove: + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: # full cell vol + vol_loop1[loc0]=(dx*dy*dz) + elif celltop < loc0 and loc0 <=cellabove: # partial cell vol + vol_loop1[loc0]=(dx*dy*difference) + else: + break + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) # counting cells w/ ! id # & proj-ing + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + + ### dist btw adjacent pts + #if part_loc>0: + # Dist[m,part_loc-1]= np.sqrt( (alpha[part_loc]-alpha[part_loc-1])**2 + (overlap_changed[part_loc]-overlap_changed[part_loc-1])**2 ) + + + ###derivative at each pt + #vol_grad=np.gradient(vol_changed) + #projA_grad=np.gradient(projected_area_changed) + #ht_grad=np.gradient(partial_heights) + #Dcurve2[m]=(vol_grad/volume_c[m])-(ht_grad/height_c[m])-(projA_grad/projected_area_c[m]) + #overlap_changed_grad=np.gradient(overlap_changed) + #alpha_grad=np.gradient(alpha) + #Dcurve[m]=alpha_grad/overlap_changed_grad + #Dcurve3[m]=np.gradient(alpha/overlap_changed) + + ## calculates change in r of a cld + dr=np.zeros(alpha.size -1) + for i in range(alpha.size -1 ) : + dr[i]= overlap_changed[i+1] - overlap_changed[i] # having abs lowers the high pt of the interval + Total_dr[m,i]=dr[i] + + + + alpha_matrix[m,:]=alpha + overlap_changed_matrix[m,:]=overlap_changed + Keeptrack_tdr[kt,:]=[file_numb,file1_numb,e1] + kt=kt+1 + """ + mu[m]=np.mean(dr) + sigma[m]=np.std(dr) + + ### prints index of matrix where change in r is outside the confidence interval + for i in range(alpha.size -1 ): + if abs(Total_dr[m,i]) >= mu[m]+1.96*sigma[m]: + print('index',(m,i)) #remeber indices start at zero + """ + ###putting alpha = partial_heights / height_c[m] b/c partial_heights = alpha * height_c[m] + plt.plot(overlap_changed,alpha,'o-',label=str(cloud_numb[m])) + plt.title('normalized height vs. overlap') + + #plt.plot(alpha,overlap_changed,'o-',label=str(cloud_numb[m])) + #plt.title('overlap vs. normalized height ') + #plt.xlim([1,0.2]) + + + + + plt.legend(loc='upper right', bbox_to_anchor=(1.40, 1.0), fontsize='small',ncol=2) + + + + + + + + m = m+1 + + #mu1=np.mean(Total_dr) + #sigma1=np.std(Total_dr) + #Check1=[Total_dr >= mu1 + 1.96 *sigma1] + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + + + + + + +""" +corr_spear, p_spear = spearmanr(overlap_changed_matrix.flatten(), alpha_matrix.flatten()) #spearman correlation measures monoticity of overlap and normalized ht +spearman=[corr_spear, p_spear] +print('spearman correlation:',corr_spear,', spearman p-value:',p_spear) + +avg_dr=np.mean(Total_dr, axis=1) # average dr for each cld +avg_avg_dr=np.mean(Total_dr.flatten()) # avg dr for trackfile, # approx mean of boxplot ? + + +### calculate interquartile range +#data=Total_dr.flatten() +q25, q75 = percentile(Total_dr.flatten(), 25), percentile(Total_dr.flatten(), 75) +iqr = q75 - q25 + +### calculate the outlier cutoff +cut_off = iqr * 1.5 +lower, upper = q25 - cut_off, q75 + cut_off +#outliers = [x for x in data if x < lower or x > upper] +outliers_great = [x for x in Total_dr.flatten() if x > upper] +### plot box and whisker plot +fig1, ax1 = plt.subplots() +ax1.set_title('Change in Overlap per chop') +ax1.boxplot(Total_dr.flatten())#,notch=True,bootstrap=1000) +### plot histogram +plt.figure() +plt.hist(Total_dr.flatten(), bins='auto') +plt.title('count of change in r vs. change in r per chop') +""" + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/percentcloud3.py b/data/percentcloud3.py new file mode 100644 index 0000000..21ad52d --- /dev/null +++ b/data/percentcloud3.py @@ -0,0 +1,413 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 14 11:41:26 2019 + +@author: anthonys +""" + +""" +calculates overlap ratio base on ht of cld from chopping the cld at the bottom + + +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script + +bomexfilenames=[bomextrack36] +ricofilenames=[ricotrack2016] +armfilenames=[armtrack522] +conditional_height=1500 + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=1500 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + """ + cbnew1=[];ctnew1=[];cbnew2=[];ctnew2=[];area_projnew1=[];area_projnew2=[]; + overlap_ratio_new1=[];overlap_ratio_new2=[];htnew1=[];htnew2=[]; + index1=[];index2=[]; + + for i in range(ht.size): + if ht[i] > conditional_height: #ht[i]*overlap_ratio[i] > 200: + cbnew1.append(cb[i]) + ctnew1.append(ct[i]) + area_projnew1.append(area_proj[i]) + overlap_ratio_new1.append(overlap_ratio[i]) + htnew1.append(ht[i]) + index1.append(i) + else: + cbnew2.append(cb[i]) + ctnew2.append(ct[i]) + area_projnew2.append(area_proj[i]) + overlap_ratio_new2.append(overlap_ratio[i]) + htnew2.append(ht[i]) + index2.append(i) + + cbnew1=np.asarray(cbnew1) + ctnew1=np.asarray(ctnew1) + cbnew2=np.asarray(cbnew2) + ctnew2=np.asarray(ctnew2) + area_projnew1=np.asarray(area_projnew1) + area_projnew2=np.asarray(area_projnew2) + overlap_ratio_new1=np.asarray(overlap_ratio_new1) + overlap_ratio_new2=np.asarray(overlap_ratio_new2) + htnew1=np.asarray(htnew1) + htnew2=np.asarray(htnew2) + """ + + + + #overlap_cal, volume_cal, height_cal, projected_area_cal, height_diff = overlap_calculation.overlap_calculation(index1,nrcloudarray,xt,yt,zt) + + + + #plt.figure() + #plt.plot(overlap_cal,height_cal,'o') + #plt.figure() + #plt.plot(overlap_ratio_new1,htnew1,'o') + + + +############################################################################ + # calculate overlap of a cld that at some of its height chopped off at the bottom + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + #unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells, comment out saved 2 sec + #uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + # dont need above as we dont need the for loops below + """ + uninew=[];countnew=[] + for uni in range(uni_elmts.size): + for i in range(index7.size): + if uni_elmts[uni] == index7[i]: # taking index of cloud w/ certain condition + uninew.append(index7[i]) + countnew.append(count_elmts[index7[i]]) + uninew1=np.asarray(uninew) + countnew1=np.asarray(countnew) + """ + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + #countnew1=count_elmts[index7] # dont need as vol is calculatd in for loop + + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + #volume_c=dx*dy*dz*countnew1 # calculated later + + #cloud_numb=np.array([533]) # choose a particular cld + #vert_res=25 + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + + m=0; + #alpha=[1.0] #, 0.9, 0.8, 0.7, 0.6, 0.5,0.2] + #alpha=np.asarray(alpha) + alpha=np.arange(1,0.15,-0.1) # fraction + + #Dcurve=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + for e1 in cloud_numb: # may take a while to run + + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + locz_size=location[0].size + #print('locz',locz_size) + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] # fraction of cld height + #height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: + + part_loc= part_loc +1 + for i in range(locz_size-1,-1,-1): + if dz*(-location[0][i]+location[0][-1]+1) <= partial: # finding all cells above chopped cld ht + celltop=i # celltop is more like cellbottom + else: + break + #if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(-location[0][celltop]+location[0][-1]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,-1,-1): + if location[0][celltop] -1 == location[0][j]: # to use partial cells + cellabove=j # cellabove is more like cellbelow + elif location[0][celltop] -1 > location[0][j]: + break + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + + ##################################### + """ + proj_area_loop1=[] + vol_loop1=[] + for loc0 in range(locz_size-1,-1,-1): + + #loc_loc0 = loc_loc0 +1 + if loc0 >= celltop : + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + elif celltop > loc0 and loc0 >=cellabove: + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + if loc0 >= celltop: # full cell vol + vol_loop1.append(dx*dy*dz) + elif celltop > loc0 and loc0 >=cellabove: # partial cell vol + vol_loop1.append(dx*dy*difference) + else: + break + + proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + vol_loop1=np.asarray(vol_loop1) + + ########################## + """ + if partial == height_c[m]: + proj_area_loop1=np.zeros(locz_size - celltop) + vol_loop1=np.zeros(locz_size - celltop) + else: + proj_area_loop1=np.zeros(locz_size -cellabove ) + vol_loop1=np.zeros(locz_size -cellabove ) + + loc0_m= -1 + for loc0 in range(locz_size-1,-1,-1): + loc0_m= loc0_m+1 + #loc_loc0 = loc_loc0 +1 + if loc0 >= celltop : + proj_area_loop1[loc0_m]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop > loc0 and loc0 >=cellabove: + proj_area_loop1[loc0_m]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 >= celltop: # full cell vol + vol_loop1[loc0_m]=(dx*dy*dz) + elif celltop > loc0 and loc0 >=cellabove: # partial cell vol + vol_loop1[loc0_m]=(dx*dy*difference) + else: + break + + + + ###################### + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + #plt.figure() + #if e1==351: + + overlap_changed_grad=np.gradient(overlap_changed) + alpha_grad=np.gradient(alpha) + + #Dcurve[m]=abs(alpha_grad/overlap_changed_grad) + + plt.plot(overlap_changed,partial_heights/height_c[m],'o-',label=str(cloud_numb[m])) + plt.title('fractional height (cut at bottom) vs. overlap') + + plt.legend(loc='upper right', bbox_to_anchor=(1.40, 1.0), fontsize='small',ncol=2) + + + + + m = m+1 + + + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + + + + + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + diff --git a/data/percentofcloud1.py b/data/percentofcloud1.py new file mode 100644 index 0000000..f5bd7b4 --- /dev/null +++ b/data/percentofcloud1.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Feb 4 11:56:08 2019 + +@author: anthonys +""" + + + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +import collections + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + + + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + +######## +# when |ct-cb|<1 ra -> rashear +def rashear(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/cb + return (1+multiple*multiplicand)**(-1) + +def raanvil(grad,ht,w,ct,cb,one): + multiple=1/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return (1+multiple*multiplicand)**(-1) + +# model +def ra(grad,ht,w,ct,cb,one): + multiple=(np.maximum(abs(grad)*ht,one))/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return ((1)+multiple*multiplicand)**(-1) + + + + + +#################################### + +# script + +bomexfilenames=[bomextrack18] + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + + cbnew1=[];ctnew1=[];cbnew2=[];ctnew2=[];area_projnew1=[];area_projnew2=[]; + overlap_ratio_new1=[];overlap_ratio_new2=[];htnew1=[];htnew2=[]; + for i in range(cb.size): + if abs(ct[i]-cb[i]+1) > 5: + cbnew1.append(cb[i]) + ctnew1.append(ct[i]) + area_projnew1.append(area_proj[i]) + overlap_ratio_new1.append(overlap_ratio[i]) + htnew1.append(ht[i]) + else: + cbnew2.append(cb[i]) + ctnew2.append(ct[i]) + area_projnew2.append(area_proj[i]) + overlap_ratio_new2.append(overlap_ratio[i]) + htnew2.append(ht[i]) + + + cbnew1=np.asarray(cbnew1) + ctnew1=np.asarray(ctnew1) + cbnew2=np.asarray(cbnew2) + ctnew2=np.asarray(ctnew2) + area_projnew1=np.asarray(area_projnew1) + area_projnew2=np.asarray(area_projnew2) + overlap_ratio_new1=np.asarray(overlap_ratio_new1) + overlap_ratio_new2=np.asarray(overlap_ratio_new2) + htnew1=np.asarray(htnew1) + htnew2=np.asarray(htnew2) + + + + + + + + + + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + bins=5; + """ + for z in range(zt.size): + hist1,edges = np.histogram(nrcloud[z,:,:],bins=bins) + """ + + + nrcloudarray = np.ma.getdata(nrcloud) + cld_maskarray = np.ma.getdata(cld_mask) + """ + cloudfrac = np.empty((zt.size)) + for z in range(zt.size): + cloudfrac[z] = np.sum((nrclouddata[z,:,:]))/(xt.size*yt.size) + """ + + """ + cvlayer=np.zeros(cfrac.size) + for i in range(cfrac.size): + cvlayer[i]=cfrac[i]/(dz+1) + """ + + """ + N=[] + for i in range(xt.size): + for j in range(yt.size): + #Z=sum(nrcloudarray[:,j,i]) + #N.append(Z) + for k in range(zt.size): + if nrcloudarray[k,j,i]>0: + N.append(1) + + Narray=np.asarray(N) + S=sum(Narray) + """ + + + count1=np.count_nonzero(nrcloudarray) + count2=np.count_nonzero(cld_maskarray) + + #nrcloudarray.index(1) + #nrcloudlist=np.tolist(nrcloudarray) + #nrcloudarray.index(1) + A=np.where(nrcloudarray==158) + + + + + + + + + + + + + + + + + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + diff --git a/data/projarea_no_shear_arm28800.npy b/data/projarea_no_shear_arm28800.npy new file mode 100644 index 0000000..620571c Binary files /dev/null and b/data/projarea_no_shear_arm28800.npy differ diff --git a/data/projarea_no_shear_arm41400.npy b/data/projarea_no_shear_arm41400.npy new file mode 100644 index 0000000..8f1ad4c Binary files /dev/null and b/data/projarea_no_shear_arm41400.npy differ diff --git a/data/projarea_no_shear_bomex10800.npy b/data/projarea_no_shear_bomex10800.npy new file mode 100644 index 0000000..9de702e Binary files /dev/null and b/data/projarea_no_shear_bomex10800.npy differ diff --git a/data/projarea_no_shear_bomex12600.npy b/data/projarea_no_shear_bomex12600.npy new file mode 100644 index 0000000..d4c69d6 Binary files /dev/null and b/data/projarea_no_shear_bomex12600.npy differ diff --git a/data/projarea_no_shear_bomex14400.npy b/data/projarea_no_shear_bomex14400.npy new file mode 100644 index 0000000..72a2745 Binary files /dev/null and b/data/projarea_no_shear_bomex14400.npy differ diff --git a/data/projarea_no_shear_bomex16200.npy b/data/projarea_no_shear_bomex16200.npy new file mode 100644 index 0000000..bd92785 Binary files /dev/null and b/data/projarea_no_shear_bomex16200.npy differ diff --git a/data/projarea_no_shear_bomex18000.npy b/data/projarea_no_shear_bomex18000.npy new file mode 100644 index 0000000..7988215 Binary files /dev/null and b/data/projarea_no_shear_bomex18000.npy differ diff --git a/data/projarea_no_shear_bomex19800.npy b/data/projarea_no_shear_bomex19800.npy new file mode 100644 index 0000000..f32fdd9 Binary files /dev/null and b/data/projarea_no_shear_bomex19800.npy differ diff --git a/data/projarea_no_shear_bomex21600.npy b/data/projarea_no_shear_bomex21600.npy new file mode 100644 index 0000000..6ad581c Binary files /dev/null and b/data/projarea_no_shear_bomex21600.npy differ diff --git a/data/projarea_no_shear_bomex23400.npy b/data/projarea_no_shear_bomex23400.npy new file mode 100644 index 0000000..94d3e80 Binary files /dev/null and b/data/projarea_no_shear_bomex23400.npy differ diff --git a/data/projarea_no_shear_bomex25200.npy b/data/projarea_no_shear_bomex25200.npy new file mode 100644 index 0000000..5c290a3 Binary files /dev/null and b/data/projarea_no_shear_bomex25200.npy differ diff --git a/data/projarea_no_shear_bomex27000.npy b/data/projarea_no_shear_bomex27000.npy new file mode 100644 index 0000000..03bc1f7 Binary files /dev/null and b/data/projarea_no_shear_bomex27000.npy differ diff --git a/data/projarea_no_shear_bomex28800.npy b/data/projarea_no_shear_bomex28800.npy new file mode 100644 index 0000000..660b370 Binary files /dev/null and b/data/projarea_no_shear_bomex28800.npy differ diff --git a/data/projarea_no_shear_bomex30600.npy b/data/projarea_no_shear_bomex30600.npy new file mode 100644 index 0000000..dadf5d3 Binary files /dev/null and b/data/projarea_no_shear_bomex30600.npy differ diff --git a/data/projarea_no_shear_bomex32400.npy b/data/projarea_no_shear_bomex32400.npy new file mode 100644 index 0000000..d0958c7 Binary files /dev/null and b/data/projarea_no_shear_bomex32400.npy differ diff --git a/data/projarea_no_shear_bomex34200.npy b/data/projarea_no_shear_bomex34200.npy new file mode 100644 index 0000000..4fdef12 Binary files /dev/null and b/data/projarea_no_shear_bomex34200.npy differ diff --git a/data/projarea_no_shear_bomex360.npy b/data/projarea_no_shear_bomex360.npy new file mode 100644 index 0000000..93417af Binary files /dev/null and b/data/projarea_no_shear_bomex360.npy differ diff --git a/data/projarea_no_shear_bomex36000.npy b/data/projarea_no_shear_bomex36000.npy new file mode 100644 index 0000000..93417af Binary files /dev/null and b/data/projarea_no_shear_bomex36000.npy differ diff --git a/data/projarea_no_shear_lasso306.npy b/data/projarea_no_shear_lasso306.npy new file mode 100644 index 0000000..347fd75 Binary files /dev/null and b/data/projarea_no_shear_lasso306.npy differ diff --git a/data/projarea_no_shear_rico2016.npy b/data/projarea_no_shear_rico2016.npy new file mode 100644 index 0000000..0796810 Binary files /dev/null and b/data/projarea_no_shear_rico2016.npy differ diff --git a/data/projarea_no_shear_rico828.npy b/data/projarea_no_shear_rico828.npy new file mode 100644 index 0000000..e1fb03a Binary files /dev/null and b/data/projarea_no_shear_rico828.npy differ diff --git a/data/rico82800_shearTB_vel.npy b/data/rico82800_shearTB_vel.npy new file mode 100644 index 0000000..095f643 Binary files /dev/null and b/data/rico82800_shearTB_vel.npy differ diff --git a/data/rico82800_sheara_vel.npy b/data/rico82800_sheara_vel.npy new file mode 100644 index 0000000..c3e9b75 Binary files /dev/null and b/data/rico82800_sheara_vel.npy differ diff --git a/data/rico82800_shearh_vel.npy b/data/rico82800_shearh_vel.npy new file mode 100644 index 0000000..62e16f2 Binary files /dev/null and b/data/rico82800_shearh_vel.npy differ diff --git a/data/rico82800_wavg.npy b/data/rico82800_wavg.npy new file mode 100644 index 0000000..74ab8c5 Binary files /dev/null and b/data/rico82800_wavg.npy differ diff --git a/data/rico_area_gmean10800.npy b/data/rico_area_gmean10800.npy new file mode 100644 index 0000000..4636b1b Binary files /dev/null and b/data/rico_area_gmean10800.npy differ diff --git a/data/rico_area_gmean82800.npy b/data/rico_area_gmean82800.npy new file mode 100644 index 0000000..f888000 Binary files /dev/null and b/data/rico_area_gmean82800.npy differ diff --git a/data/shearTB_arm28800.npy b/data/shearTB_arm28800.npy new file mode 100644 index 0000000..b6178a1 Binary files /dev/null and b/data/shearTB_arm28800.npy differ diff --git a/data/shearTB_arm41400.npy b/data/shearTB_arm41400.npy new file mode 100644 index 0000000..c2bc712 Binary files /dev/null and b/data/shearTB_arm41400.npy differ diff --git a/data/shearTB_bomex10800.npy b/data/shearTB_bomex10800.npy new file mode 100644 index 0000000..7440caa Binary files /dev/null and b/data/shearTB_bomex10800.npy differ diff --git a/data/shearTB_bomex12600.npy b/data/shearTB_bomex12600.npy new file mode 100644 index 0000000..2e6248f Binary files /dev/null and b/data/shearTB_bomex12600.npy differ diff --git a/data/shearTB_bomex14400.npy b/data/shearTB_bomex14400.npy new file mode 100644 index 0000000..132fa97 Binary files /dev/null and b/data/shearTB_bomex14400.npy differ diff --git a/data/shearTB_bomex16200.npy b/data/shearTB_bomex16200.npy new file mode 100644 index 0000000..e9cae8e Binary files /dev/null and b/data/shearTB_bomex16200.npy differ diff --git a/data/shearTB_bomex18000.npy b/data/shearTB_bomex18000.npy new file mode 100644 index 0000000..6923bc4 Binary files /dev/null and b/data/shearTB_bomex18000.npy differ diff --git a/data/shearTB_bomex19800.npy b/data/shearTB_bomex19800.npy new file mode 100644 index 0000000..ca36b0c Binary files /dev/null and b/data/shearTB_bomex19800.npy differ diff --git a/data/shearTB_bomex21600.npy b/data/shearTB_bomex21600.npy new file mode 100644 index 0000000..0d5cc24 Binary files /dev/null and b/data/shearTB_bomex21600.npy differ diff --git a/data/shearTB_bomex23400.npy b/data/shearTB_bomex23400.npy new file mode 100644 index 0000000..714ec50 Binary files /dev/null and b/data/shearTB_bomex23400.npy differ diff --git a/data/shearTB_bomex25200.npy b/data/shearTB_bomex25200.npy new file mode 100644 index 0000000..0bc9f21 Binary files /dev/null and b/data/shearTB_bomex25200.npy differ diff --git a/data/shearTB_bomex27000.npy b/data/shearTB_bomex27000.npy new file mode 100644 index 0000000..6943c1f Binary files /dev/null and b/data/shearTB_bomex27000.npy differ diff --git a/data/shearTB_bomex28800.npy b/data/shearTB_bomex28800.npy new file mode 100644 index 0000000..17ad01b Binary files /dev/null and b/data/shearTB_bomex28800.npy differ diff --git a/data/shearTB_bomex30600.npy b/data/shearTB_bomex30600.npy new file mode 100644 index 0000000..eace386 Binary files /dev/null and b/data/shearTB_bomex30600.npy differ diff --git a/data/shearTB_bomex32400.npy b/data/shearTB_bomex32400.npy new file mode 100644 index 0000000..c03bd93 Binary files /dev/null and b/data/shearTB_bomex32400.npy differ diff --git a/data/shearTB_bomex34200.npy b/data/shearTB_bomex34200.npy new file mode 100644 index 0000000..28bf7eb Binary files /dev/null and b/data/shearTB_bomex34200.npy differ diff --git a/data/shearTB_bomex36000.npy b/data/shearTB_bomex36000.npy new file mode 100644 index 0000000..b83ffb2 Binary files /dev/null and b/data/shearTB_bomex36000.npy differ diff --git a/data/shearTB_rico201600.npy b/data/shearTB_rico201600.npy new file mode 100644 index 0000000..000187b Binary files /dev/null and b/data/shearTB_rico201600.npy differ diff --git a/data/shearTB_rico82800.npy b/data/shearTB_rico82800.npy new file mode 100644 index 0000000..095f643 Binary files /dev/null and b/data/shearTB_rico82800.npy differ diff --git a/data/shearTB_vel_arm28800.npy b/data/shearTB_vel_arm28800.npy new file mode 100644 index 0000000..b6178a1 Binary files /dev/null and b/data/shearTB_vel_arm28800.npy differ diff --git a/data/shearTB_vel_arm41400.npy b/data/shearTB_vel_arm41400.npy new file mode 100644 index 0000000..c2bc712 Binary files /dev/null and b/data/shearTB_vel_arm41400.npy differ diff --git a/data/shear_cal1.py b/data/shear_cal1.py new file mode 100644 index 0000000..d40e55b --- /dev/null +++ b/data/shear_cal1.py @@ -0,0 +1,526 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed May 29 10:55:59 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +from scipy.stats import hmean +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + +from scipy.special import comb + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + +# definitions +#def pyth(u,v): # magnitude +# return np.sqrt(u*u+v*v) + + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + +def shear_amod(shear,h,l): + return shear * h / l + + +#################################### + +# script + +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +#kt=0; +#file_numb=-1 +#file1_numb=-1 + + + +### rico828 +""" +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') +""" +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +""" + +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +""" +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" + + +""" +datad = Dataset("/data/rico/rico.default.0000000.nc","r") +zh=datad.variables['zh'][:] +time_t=datad.variables['time'][:] +u=datad.variables['u'][:,:] +v=datad.variables['v'][:,:] +w=datad.variables['w'][:,:] +""" +#################################################################### +""" +datau = Dataset('/data/rico/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/rico/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/rico/w.nc','r') +time_t = datau.variables['time'][:] +step=3600;time_array= np.arange(step,216000+step,step) +case='rico' +""" +""" +datau = Dataset('/data/bomex/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/bomex/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/bomex/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(step,36000+step,step) +case='bomex' +""" + +datau = Dataset('/data/arm/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/arm/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/arm/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(10800,52200+step,step) +case='arm' + +conditional_height=50 + +#file1_numb=-1 +begin=5 +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[begin:] +#file3_numb = np.arange(5,19+1) +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#begin=22 +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +#Bfilenames = [Afilenames[22], Afilenames[55]] +#Bfilenames = [Afilenames[22]] +#file1_numb=begin-1 ## python: arrays start at index 0 +#file3_numb = [22,55] +#file3_numb = [22] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:2] +Bfilenames = [Afilenames[10], Afilenames[17]] +file3_numb = [10,17] + +file2_numb = -1 + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + #file1_numb = file1_numb+1 + file2_numb = file2_numb+1 + file1_numb = file3_numb[file2_numb] + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + ### + access = np.where(time_t == time_array[file1_numb])[0][0] ## slicing at correct spot + u=datau.variables['u'][access,:,:,:] + xh=datau.variables['xh'][:] + v=datav.variables['v'][access,:,:,:] + yh=datav.variables['yh'][:] + w=dataw.variables['w'][access,:,:,:] + zh=dataw.variables['zh'][:] + ### + + uint=interp1d(xh,u,axis=2,fill_value='extrapolate') + vint=interp1d(yh,v,axis=1,fill_value='extrapolate') + wint=interp1d(zh,w,axis=0,fill_value='extrapolate') + + ut=uint(xt) + vt=vint(yt) + wt=wint(zt) + + #w=interp1d(zh,w,axis=0,fill_value='extrapolate') + #ut=u;vt=v;#wt=w; + + + ut1=np.sum(np.sum(ut,axis=1),axis=1)/(nx*ny) + vt1=np.sum(np.sum(vt,axis=1),axis=1)/(nx*ny) + #ut1=np.mean(np.mean(ut,axis=1),axis=1) + #vt1=np.mean(np.mean(vt,axis=1),axis=1) + #wt1=np.mean(np.mean(wt,axis=1),axis=1) + + + uz=ut1 + vz=vt1 + #wz=wt1 + + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + l=cv**0.5 + + + + + + #uz=np.mean(u,axis=0) # avg among diff times + #vz=np.mean(v,axis=0) # avg among diff times + shear_calu=np.zeros(cb.size) + shear_calv=np.zeros(cb.size) + """ + for i in range(cb.size): + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + """ + + + #shear_cal = np.sqrt( shear_calu**2 + shear_calv**2 ) + #shear_cal = abs(shear_calu + shear_calv) / 2 + + + + ############################## + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + + + #s_u=abs(duz);s_v=abs(dvz) + s_u=duz;s_v=dvz; + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2;#Amean=abs(Amean) + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v);#Hmean=abs(Hmean) + pyth= (s_u**2 + s_v**2)**0.5 + + shear0=np.zeros(cb.size) + shear00=np.zeros(cb.size) + w_cld=np.zeros(cb.size) + for i in range(cb.size): #### wind differential + + #shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + shear00[i] = sum(Amean[cb[i]:ct[i]+1]) + + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + + shear_cal = abs(shear_calu + shear_calv) / 2 + + ####################### + #shear= (1/overlap_ratio) - (1/overlap) ### overlap form shear + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + ll = np.zeros(index1_size) + shear1_cal = np.zeros(index1_size) + shear2_cal = np.zeros(index1_size) + shear3_cal = np.zeros(index1_size) + w_avg = np.zeros(index1_size) + shear_overlap=np.zeros(index1_size) + + C_true_bar = np.zeros(index1_size) + alpha_overlap = np.zeros(index1_size) + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + + wz_max = np.zeros(index1_size) + wz_cb = np.zeros(index1_size) + wz_ct = np.zeros(index1_size) + wz_avg = np.zeros(index1_size) + wz_min = np.zeros(index1_size) + m=-1; #m=0; + + + #### calculating updraft + for e1 in cloud_numb: # may take a while to run + + m = m+1 + + ll[m]=l[e1-1] + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + + loc_mat_tran=np.matrix.transpose(location_matrix) + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + base=np.amin(location[0]);top=np.amax(location[0]); + z_array = np.arange(base, top+1,1) + ########### + ### shear + basez=base;topz=top;basey=min(location[1]);topy=max(location[1]);basex=min(location[2]);topx=max(location[2]); + w_abs=abs(wt) + #wz_avg=np.sum(w_abs[basez:topz+1,:,:],axis=0) / (topz - basez+1) # maybe avoid avg along z axis? use max up vel along z to get singl # + #wy_avg=np.sum(wz_avg[basey:topy+1,:],axis=0) / (topy - basey+1) + #wx_avg=np.sum(wy_avg[basex:topx+1],axis=0) / (topx - basex+1) + ##wz_avg=np.mean(w_abs[min(location[0]):max(location[0])+1,:,:],axis=0) + ##wy_avg=np.mean(wz_avg[min(location[1]):max(location[1])+1,:],axis=0) + ##wx_avg=np.mean(wy_avg[min(location[2]):max(location[2])+1],axis=0) + + wy_avg=np.sum(w_abs[:,basey:topy+1,:],axis=1) / (topy - basey+1) + wx_avg=np.sum(wy_avg[:,basex:topx+1],axis=1) / (topx - basex+1) + wz = wx_avg[basez:topz+1] + + wz_max[m] = np.amax(wz) + wz_cb[m] = wz[0] + wz_ct[m] = wz[-1] + wz_avg[m] = np.mean(wz) + wz_min[m] = np.amin(wz) + + + #w_avg[m]=wx_avg + #print(w_avg[m]) + + + + #shear1_cal[m]= shear_cal[e1-1]/ w_avg[m] ###shear_cal + + #shear2_cal[m] = shear0[e1-1] / w_avg[m] ### shearh + + #shear3_cal[m] = shear00[e1-1] / w_avg[m] ###sheara + #print(shear1_cal) + + + #shear_overlap[m] = shear[e1-1] + ######################### + ### hogan ,illington + """ + area_layer = np.zeros(z_array.size) + for z in z_array: + area_layer[z-base] = dx*dy*len(np.where( z == location[0] )[0]) + + + C_max = np.zeros(int(comb(z_array.size,2))) + C_rand = np.zeros(int(comb(z_array.size,2))) + C_true = np.zeros(int(comb(z_array.size,2))) + alpha_a = np.zeros(int(comb(z_array.size,2))) + loc_a_1 = -1 + for c_area1 in area_layer: + loc_a_1 = loc_a_1 + 1 + loc_a_2 = - 1 + for c_area2 in area_layer: + loc_a_2 = loc_a_2 + 1 + if loc_a_1 != loc_a_2: + dzed = dz*abs(loc_a_1 - loc_a_2) + C_max[loc_a_2] = max(c_area1,c_area2) + C_rand[loc_a_2] = c_area1 + c_area2 - c_area1*c_area2 + alpha_a[loc_a_2] = np.exp(-dzed / 200 ) + C_true[loc_a_2] = alpha_a[loc_a_2]*C_max[loc_a_2] + (1-alpha_a[loc_a_2])*C_rand[loc_a_2] + + #C_max_bar = np.mean(C_max) + #C_rand_bar = np.mean(C_rand) + C_true_bar[m] = np.mean(C_true) + alpha_overlap[m] = np.exp(-dz*layers / 200) + """ + + ################################################### + """ + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + + f_t=f_turb(ht,175); f_t[ht<=100]=0 + f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_total = f_t + f_s + f_a +1 + + ################################################## + """ + ################################ + ### saving data + """ + #step=1800 # 30*60 + #time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='bomex' + + + name1='shearTB_' + name2='shear_sum_' + #name3='wavg1_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',shear_cal) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',shear00) + #np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',w_avg) + + name1='wz_max_' + name2='wz_min_' + name3='wz_avg_' + name4='wz_ct_' + name5='wz_cb_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',wz_max) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',wz_min) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',wz_avg) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',wz_ct) + np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',wz_cb) + """ + ############################# + +############################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/shear_center_of_mass1.py b/data/shear_center_of_mass1.py new file mode 100644 index 0000000..f6f0316 --- /dev/null +++ b/data/shear_center_of_mass1.py @@ -0,0 +1,584 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 4 11:47:11 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') + +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') +bomextrack234 = Dataset('/data/bomex/l.0023400.track.nc','r') +bomextrack252 = Dataset('/data/bomex/l.0025200.track.nc','r') +bomextrack270 = Dataset('/data/bomex/l.0027000.track.nc','r') +bomextrack288 = Dataset('/data/bomex/l.0028800.track.nc','r') +bomextrack306 = Dataset('/data/bomex/l.0030600.track.nc','r') +bomextrack324 = Dataset('/data/bomex/l.0032400.track.nc','r') +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + + + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + + +lassotrack306 = Dataset('/data/lasso/sims/20160611_micro/l.0030600.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script +filenames=[bomexd] +ricofilenames=[ricotrack2016] +bomexfilenames=[bomextrack216,bomextrack234,bomextrack252,bomextrack270,bomextrack288,bomextrack306,bomextrack324,bomextrack342,bomextrack360] +armfilenames=[armtrack522] +lassofilenames=[lassotrack306] +conditional_height=0 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +conditional_height=0 + +file1_numb=-1 + +begin=5 +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] + +file1_numb=begin-1 + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + m=0; + + alpha=np.arange(1,0,-1) # just 1 + #alpha=np.arange(1,0.35,-0.1) # fraction + #alpha=np.array([0.7,0.5,0.3,0.1]) + + #Dist=np.zeros((cloud_numb.size , alpha.size -1)) + #Dcurve=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve2=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve3=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + + #Total_dr=np.zeros((cloud_numb.size,alpha.size -1)) # multi dimensional array + #mu=np.zeros(cloud_numb.size) + #sigma=np.zeros(cloud_numb.size) + #Keeptrack_tdr=np.zeros((cloud_numb.size,3)) #make abitrarily big + #alpha_matrix=np.zeros((cloud_numb.size,alpha.size)) + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + + for e1 in cloud_numb: # may take a while to run + + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + #layers=height/dz + ### + + base=np.amin(location[0]);top=np.amax(location[0]); + #levels=range(base,top+1,1) + + x_unique=np.unique(location[2]) + y_unique=np.unique(location[1]) + xtest1=abs(np.mean(x_unique)-np.median(x_unique)) # median is resistant while mean is not + ytest1=abs(np.mean(y_unique)-np.median(y_unique)) + + #xtest1=abs(np.mean(location[2])-np.median(location[2])) + #ytest1=abs(np.mean(location[1])-np.median(location[1])) + #x_small=np.extract(location[2] < 512,location[2]) + #x_large=np.extract(x_unique > 512,x_unique) + #y_small=np.extract(y_unique < 512,y_unique) + #y_large=np.extract(y_unique > 512,y_unique) + + if xtest1 > epsilon1: + splitx=np.where(location[2] < 512) + location[2][splitx] = location[2][splitx] + nx + + if ytest1 > epsilon1: + splity=np.where(location[1] < 512) + location[1][splity] = location[1][splity] + ny + + + #sys.exit("Error message") + + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + COM=np.zeros((top-base+1,3)) + newlocation_matrix=np.zeros(location_matrix.shape) + cross_area_z=np.zeros(int(layers)) + #u, indices = np.unique(location[0], return_index=True) + #COM[:,0]=u + + + + + + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + # height / dz = layers + + + #COM[z-base,:]=[z,sum(location[1][findz[0]])/findz[0].size, sum(location[2][findz[0]])/findz[0].size] + COM[z-base,:]=[z,np.mean(location[1][findz[0]]), np.mean(location[2][findz[0]])] #find center of mass w/ arithmetic mean + ### not quite (close) + """ + if z0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,location[0].size): + if location[0][celltop] +1 == location[0][j]: # to use partial cells + cellabove=j + elif location[0][celltop] +1 < location[0][j]: + break + #print('partial',partial) + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + if partial == height_c[m]: # difference=0, so stop at celltop + proj_area_loop1=np.zeros(celltop +1) + vol_loop1=np.zeros(celltop +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + """ + ### plotting in cld in 3d + + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2][0:celltop+1],dy*location[1][0:celltop+1], dz*location[0][0:celltop+1], c=dz*location[0][0:celltop+1] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + else: + proj_area_loop1=np.zeros(cellabove +1) + vol_loop1=np.zeros(cellabove +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + + for loc0 in range(location[0].size): + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop < loc0 and loc0 <=cellabove: + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: # full cell vol + vol_loop1[loc0]=(dx*dy*dz) + elif celltop < loc0 and loc0 <=cellabove: # partial cell vol + vol_loop1[loc0]=(dx*dy*difference) + else: + break + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) # counting cells w/ ! id # & proj-ing + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + + ### dist btw adjacent pts + #if part_loc>0: + # Dist[m,part_loc-1]= np.sqrt( (alpha[part_loc]-alpha[part_loc-1])**2 + (overlap_changed[part_loc]-overlap_changed[part_loc-1])**2 ) + + + ###derivative at each pt + #vol_grad=np.gradient(vol_changed) + #projA_grad=np.gradient(projected_area_changed) + #ht_grad=np.gradient(partial_heights) + #Dcurve2[m]=(vol_grad/volume_c[m])-(ht_grad/height_c[m])-(projA_grad/projected_area_c[m]) + #overlap_changed_grad=np.gradient(overlap_changed) + #alpha_grad=np.gradient(alpha) + #Dcurve[m]=alpha_grad/overlap_changed_grad + #Dcurve3[m]=np.gradient(alpha/overlap_changed) + """ + ## calculates change in r of a cld + dr=np.zeros(alpha.size -1) + for i in range(alpha.size -1 ) : + dr[i]= overlap_changed[i+1] - overlap_changed[i] # having abs lowers the high pt of the interval + Total_dr[m,i]=dr[i] + + """ + """ + alpha_matrix[m,:]=alpha + overlap_changed_matrix[m,:]=overlap_changed + Keeptrack_tdr[kt,:]=[file_numb,file1_numb,e1] + kt=kt+1 + """ + """ + mu[m]=np.mean(dr) + sigma[m]=np.std(dr) + + ### prints index of matrix where change in r is outside the confidence interval + for i in range(alpha.size -1 ): + if abs(Total_dr[m,i]) >= mu[m]+1.96*sigma[m]: + print('index',(m,i)) #remeber indices start at zero + """ + ###putting alpha = partial_heights / height_c[m] b/c partial_heights = alpha * height_c[m] + #plt.plot(overlap_changed,alpha,'o-',label=str(cloud_numb[m])) + #plt.title('normalized height vs. overlap') + + #plt.plot(alpha,overlap_changed,'o-',label=str(cloud_numb[m])) + #plt.title('overlap vs. normalized height ') + #plt.xlim([1,0.2]) + + + + #plt.legend(loc='upper right', bbox_to_anchor=(1.40, 1.0), fontsize='small',ncol=2) + + + + + + + + m = m+1 + + #mu1=np.mean(Total_dr) + #sigma1=np.std(Total_dr) + #Check1=[Total_dr >= mu1 + 1.96 *sigma1] + + overlap_c=volume_c/(height_c*projected_area_c) + + ################################ + ### + """ + + + step=1800 # 30*60 + time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + case='bomex' + + + name1=overlap_no_shear_ + name2=volume_no_shear_ + name3=projarea_no_shear_ + name4=height_no_shear_ + name5=aera_z_ratio_ + + #step=3600 # 60*60 + #time_array= np.arange(10800,216000+step,step) + #npyfilespath ="/home/anthonys/Documents/" + #case=rico + + ### + #np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',overlap_c) + #np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',volume_c) + #np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',projected_area_c) + #np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',height_c) + #np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',area_z_ratio_c) + + + #np.save(npyfilespath+str(time_array[20])+'.npy',area_z_ratio) + ### need to fix saving + """ + + ########################### + + +plt.plot(overlap_c,overlap_ratio,'o') +plt.plot(overlap_c,overlap_c) +#plt.title('Actual Overlap vs. Adjusted Overlap') +plt.title('Actual Overlap vs. Overlap with no shear') + + + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/shear_sum_arm28800.npy b/data/shear_sum_arm28800.npy new file mode 100644 index 0000000..5ac0922 Binary files /dev/null and b/data/shear_sum_arm28800.npy differ diff --git a/data/shear_sum_arm41400.npy b/data/shear_sum_arm41400.npy new file mode 100644 index 0000000..b6530a3 Binary files /dev/null and b/data/shear_sum_arm41400.npy differ diff --git a/data/shear_sum_bomex10800.npy b/data/shear_sum_bomex10800.npy new file mode 100644 index 0000000..52f2dc4 Binary files /dev/null and b/data/shear_sum_bomex10800.npy differ diff --git a/data/shear_sum_bomex12600.npy b/data/shear_sum_bomex12600.npy new file mode 100644 index 0000000..7b25bfd Binary files /dev/null and b/data/shear_sum_bomex12600.npy differ diff --git a/data/shear_sum_bomex14400.npy b/data/shear_sum_bomex14400.npy new file mode 100644 index 0000000..8615bce Binary files /dev/null and b/data/shear_sum_bomex14400.npy differ diff --git a/data/shear_sum_bomex16200.npy b/data/shear_sum_bomex16200.npy new file mode 100644 index 0000000..38a5d6b Binary files /dev/null and b/data/shear_sum_bomex16200.npy differ diff --git a/data/shear_sum_bomex18000.npy b/data/shear_sum_bomex18000.npy new file mode 100644 index 0000000..e8867bb Binary files /dev/null and b/data/shear_sum_bomex18000.npy differ diff --git a/data/shear_sum_bomex19800.npy b/data/shear_sum_bomex19800.npy new file mode 100644 index 0000000..7367bc1 Binary files /dev/null and b/data/shear_sum_bomex19800.npy differ diff --git a/data/shear_sum_bomex21600.npy b/data/shear_sum_bomex21600.npy new file mode 100644 index 0000000..ccdb3e3 Binary files /dev/null and b/data/shear_sum_bomex21600.npy differ diff --git a/data/shear_sum_bomex23400.npy b/data/shear_sum_bomex23400.npy new file mode 100644 index 0000000..4c9acd2 Binary files /dev/null and b/data/shear_sum_bomex23400.npy differ diff --git a/data/shear_sum_bomex25200.npy b/data/shear_sum_bomex25200.npy new file mode 100644 index 0000000..8ed32af Binary files /dev/null and b/data/shear_sum_bomex25200.npy differ diff --git a/data/shear_sum_bomex27000.npy b/data/shear_sum_bomex27000.npy new file mode 100644 index 0000000..64d8628 Binary files /dev/null and b/data/shear_sum_bomex27000.npy differ diff --git a/data/shear_sum_bomex28800.npy b/data/shear_sum_bomex28800.npy new file mode 100644 index 0000000..1628f78 Binary files /dev/null and b/data/shear_sum_bomex28800.npy differ diff --git a/data/shear_sum_bomex30600.npy b/data/shear_sum_bomex30600.npy new file mode 100644 index 0000000..f48e5f5 Binary files /dev/null and b/data/shear_sum_bomex30600.npy differ diff --git a/data/shear_sum_bomex32400.npy b/data/shear_sum_bomex32400.npy new file mode 100644 index 0000000..9d789f4 Binary files /dev/null and b/data/shear_sum_bomex32400.npy differ diff --git a/data/shear_sum_bomex34200.npy b/data/shear_sum_bomex34200.npy new file mode 100644 index 0000000..4a30f0f Binary files /dev/null and b/data/shear_sum_bomex34200.npy differ diff --git a/data/shear_sum_bomex36000.npy b/data/shear_sum_bomex36000.npy new file mode 100644 index 0000000..71dd675 Binary files /dev/null and b/data/shear_sum_bomex36000.npy differ diff --git a/data/shear_sum_rico201600.npy b/data/shear_sum_rico201600.npy new file mode 100644 index 0000000..4251553 Binary files /dev/null and b/data/shear_sum_rico201600.npy differ diff --git a/data/shear_sum_rico82800.npy b/data/shear_sum_rico82800.npy new file mode 100644 index 0000000..c3e9b75 Binary files /dev/null and b/data/shear_sum_rico82800.npy differ diff --git a/data/sheara_bomex10800.npy b/data/sheara_bomex10800.npy new file mode 100644 index 0000000..9620bcb Binary files /dev/null and b/data/sheara_bomex10800.npy differ diff --git a/data/sheara_bomex12600.npy b/data/sheara_bomex12600.npy new file mode 100644 index 0000000..463f56e Binary files /dev/null and b/data/sheara_bomex12600.npy differ diff --git a/data/sheara_bomex14400.npy b/data/sheara_bomex14400.npy new file mode 100644 index 0000000..adcc865 Binary files /dev/null and b/data/sheara_bomex14400.npy differ diff --git a/data/sheara_bomex16200.npy b/data/sheara_bomex16200.npy new file mode 100644 index 0000000..b460819 Binary files /dev/null and b/data/sheara_bomex16200.npy differ diff --git a/data/sheara_bomex18000.npy b/data/sheara_bomex18000.npy new file mode 100644 index 0000000..5422214 Binary files /dev/null and b/data/sheara_bomex18000.npy differ diff --git a/data/sheara_bomex19800.npy b/data/sheara_bomex19800.npy new file mode 100644 index 0000000..93e91d3 Binary files /dev/null and b/data/sheara_bomex19800.npy differ diff --git a/data/sheara_bomex21600.npy b/data/sheara_bomex21600.npy new file mode 100644 index 0000000..6231364 Binary files /dev/null and b/data/sheara_bomex21600.npy differ diff --git a/data/sheara_bomex23400.npy b/data/sheara_bomex23400.npy new file mode 100644 index 0000000..815cf23 Binary files /dev/null and b/data/sheara_bomex23400.npy differ diff --git a/data/sheara_bomex25200.npy b/data/sheara_bomex25200.npy new file mode 100644 index 0000000..bdeef31 Binary files /dev/null and b/data/sheara_bomex25200.npy differ diff --git a/data/sheara_bomex27000.npy b/data/sheara_bomex27000.npy new file mode 100644 index 0000000..840e072 Binary files /dev/null and b/data/sheara_bomex27000.npy differ diff --git a/data/sheara_bomex28800.npy b/data/sheara_bomex28800.npy new file mode 100644 index 0000000..7688cee Binary files /dev/null and b/data/sheara_bomex28800.npy differ diff --git a/data/sheara_bomex30600.npy b/data/sheara_bomex30600.npy new file mode 100644 index 0000000..0f40937 Binary files /dev/null and b/data/sheara_bomex30600.npy differ diff --git a/data/sheara_bomex32400.npy b/data/sheara_bomex32400.npy new file mode 100644 index 0000000..41c97a8 Binary files /dev/null and b/data/sheara_bomex32400.npy differ diff --git a/data/sheara_bomex34200.npy b/data/sheara_bomex34200.npy new file mode 100644 index 0000000..2b00208 Binary files /dev/null and b/data/sheara_bomex34200.npy differ diff --git a/data/sheara_bomex36000.npy b/data/sheara_bomex36000.npy new file mode 100644 index 0000000..32809c5 Binary files /dev/null and b/data/sheara_bomex36000.npy differ diff --git a/data/shearh_bomex10800.npy b/data/shearh_bomex10800.npy new file mode 100644 index 0000000..7a419ca Binary files /dev/null and b/data/shearh_bomex10800.npy differ diff --git a/data/shearh_bomex12600.npy b/data/shearh_bomex12600.npy new file mode 100644 index 0000000..bce1c13 Binary files /dev/null and b/data/shearh_bomex12600.npy differ diff --git a/data/shearh_bomex14400.npy b/data/shearh_bomex14400.npy new file mode 100644 index 0000000..8e290a2 Binary files /dev/null and b/data/shearh_bomex14400.npy differ diff --git a/data/shearh_bomex16200.npy b/data/shearh_bomex16200.npy new file mode 100644 index 0000000..18d0ccb Binary files /dev/null and b/data/shearh_bomex16200.npy differ diff --git a/data/shearh_bomex18000.npy b/data/shearh_bomex18000.npy new file mode 100644 index 0000000..0ae4fc7 Binary files /dev/null and b/data/shearh_bomex18000.npy differ diff --git a/data/shearh_bomex19800.npy b/data/shearh_bomex19800.npy new file mode 100644 index 0000000..ce785e7 Binary files /dev/null and b/data/shearh_bomex19800.npy differ diff --git a/data/shearh_bomex21600.npy b/data/shearh_bomex21600.npy new file mode 100644 index 0000000..00e636c Binary files /dev/null and b/data/shearh_bomex21600.npy differ diff --git a/data/shearh_bomex23400.npy b/data/shearh_bomex23400.npy new file mode 100644 index 0000000..65046e0 Binary files /dev/null and b/data/shearh_bomex23400.npy differ diff --git a/data/shearh_bomex25200.npy b/data/shearh_bomex25200.npy new file mode 100644 index 0000000..1db1b4f Binary files /dev/null and b/data/shearh_bomex25200.npy differ diff --git a/data/shearh_bomex27000.npy b/data/shearh_bomex27000.npy new file mode 100644 index 0000000..81267f3 Binary files /dev/null and b/data/shearh_bomex27000.npy differ diff --git a/data/shearh_bomex28800.npy b/data/shearh_bomex28800.npy new file mode 100644 index 0000000..e6bcb08 Binary files /dev/null and b/data/shearh_bomex28800.npy differ diff --git a/data/shearh_bomex30600.npy b/data/shearh_bomex30600.npy new file mode 100644 index 0000000..99c217f Binary files /dev/null and b/data/shearh_bomex30600.npy differ diff --git a/data/shearh_bomex32400.npy b/data/shearh_bomex32400.npy new file mode 100644 index 0000000..3131255 Binary files /dev/null and b/data/shearh_bomex32400.npy differ diff --git a/data/shearh_bomex34200.npy b/data/shearh_bomex34200.npy new file mode 100644 index 0000000..44fe29c Binary files /dev/null and b/data/shearh_bomex34200.npy differ diff --git a/data/shearh_bomex36000.npy b/data/shearh_bomex36000.npy new file mode 100644 index 0000000..31ffbba Binary files /dev/null and b/data/shearh_bomex36000.npy differ diff --git a/data/shift_avg_arm28800.npy b/data/shift_avg_arm28800.npy new file mode 100644 index 0000000..5a40273 Binary files /dev/null and b/data/shift_avg_arm28800.npy differ diff --git a/data/shift_avg_arm41400.npy b/data/shift_avg_arm41400.npy new file mode 100644 index 0000000..0f51882 Binary files /dev/null and b/data/shift_avg_arm41400.npy differ diff --git a/data/shift_avg_bomex10800.npy b/data/shift_avg_bomex10800.npy new file mode 100644 index 0000000..f66bf0a Binary files /dev/null and b/data/shift_avg_bomex10800.npy differ diff --git a/data/shift_avg_bomex12600.npy b/data/shift_avg_bomex12600.npy new file mode 100644 index 0000000..7f47cc7 Binary files /dev/null and b/data/shift_avg_bomex12600.npy differ diff --git a/data/shift_avg_bomex14400.npy b/data/shift_avg_bomex14400.npy new file mode 100644 index 0000000..eca64cb Binary files /dev/null and b/data/shift_avg_bomex14400.npy differ diff --git a/data/shift_avg_bomex16200.npy b/data/shift_avg_bomex16200.npy new file mode 100644 index 0000000..77ab576 Binary files /dev/null and b/data/shift_avg_bomex16200.npy differ diff --git a/data/shift_avg_bomex18000.npy b/data/shift_avg_bomex18000.npy new file mode 100644 index 0000000..fe8eb6d Binary files /dev/null and b/data/shift_avg_bomex18000.npy differ diff --git a/data/shift_avg_bomex19800.npy b/data/shift_avg_bomex19800.npy new file mode 100644 index 0000000..5e7f8ba Binary files /dev/null and b/data/shift_avg_bomex19800.npy differ diff --git a/data/shift_avg_bomex21600.npy b/data/shift_avg_bomex21600.npy new file mode 100644 index 0000000..b583039 Binary files /dev/null and b/data/shift_avg_bomex21600.npy differ diff --git a/data/shift_avg_bomex23400.npy b/data/shift_avg_bomex23400.npy new file mode 100644 index 0000000..e88e06a Binary files /dev/null and b/data/shift_avg_bomex23400.npy differ diff --git a/data/shift_avg_bomex25200.npy b/data/shift_avg_bomex25200.npy new file mode 100644 index 0000000..1e6255b Binary files /dev/null and b/data/shift_avg_bomex25200.npy differ diff --git a/data/shift_avg_bomex27000.npy b/data/shift_avg_bomex27000.npy new file mode 100644 index 0000000..754933d Binary files /dev/null and b/data/shift_avg_bomex27000.npy differ diff --git a/data/shift_avg_bomex28800.npy b/data/shift_avg_bomex28800.npy new file mode 100644 index 0000000..4318542 Binary files /dev/null and b/data/shift_avg_bomex28800.npy differ diff --git a/data/shift_avg_bomex30600.npy b/data/shift_avg_bomex30600.npy new file mode 100644 index 0000000..10939b6 Binary files /dev/null and b/data/shift_avg_bomex30600.npy differ diff --git a/data/shift_avg_bomex32400.npy b/data/shift_avg_bomex32400.npy new file mode 100644 index 0000000..380b366 Binary files /dev/null and b/data/shift_avg_bomex32400.npy differ diff --git a/data/shift_avg_bomex34200.npy b/data/shift_avg_bomex34200.npy new file mode 100644 index 0000000..1589eb9 Binary files /dev/null and b/data/shift_avg_bomex34200.npy differ diff --git a/data/shift_avg_bomex36000.npy b/data/shift_avg_bomex36000.npy new file mode 100644 index 0000000..57080a2 Binary files /dev/null and b/data/shift_avg_bomex36000.npy differ diff --git a/data/shift_avg_rico201600.npy b/data/shift_avg_rico201600.npy new file mode 100644 index 0000000..1c7b4a9 Binary files /dev/null and b/data/shift_avg_rico201600.npy differ diff --git a/data/shift_avg_rico82800.npy b/data/shift_avg_rico82800.npy new file mode 100644 index 0000000..e37fe1f Binary files /dev/null and b/data/shift_avg_rico82800.npy differ diff --git a/data/shift_cld1.py b/data/shift_cld1.py new file mode 100644 index 0000000..cb700c3 --- /dev/null +++ b/data/shift_cld1.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jun 14 12:35:46 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +start=time.time() + + + +############################################################### + + + + + +epsilon1=50 ##### helps find clds that are split by grid box +#arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +#file1_numb=-1 + +""" +datau = Dataset('/data/rico/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/rico/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/rico/w.nc','r') +time_t = datau.variables['time'][:] +step=3600;time_array= np.arange(step,216000+step,step) +case='rico' +""" +""" +datau = Dataset('/data/bomex/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/bomex/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/bomex/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(step,36000+step,step) +case='bomex' +""" +""" +datau = Dataset('/data/lasso/sims/20160830/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/lasso/sims/20160830/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/lasso/sims/20160830/w.nc','r') +""" + +datau = Dataset('/data/arm/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/arm/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/arm/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(10800,52200+step,step) +case='arm' + + +conditional_height=50 +#file1_numb=-1 +begin=5 +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[begin:] +#file3_numb = np.arange(5,19+1) +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#begin=22 +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +#Bfilenames = [Afilenames[22], Afilenames[55]] +#Bfilenames = [Afilenames[22]] +#file1_numb=begin-1 ## python: arrays start at index 0 +#file3_numb = [22,55] +#file3_numb = [22] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:2] +Bfilenames = [Afilenames[10], Afilenames[17]] +file3_numb = [10,17] + +file2_numb = -1 + + +############################# +#### loop over trackfiles +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file2_numb = file2_numb+1 + file1_numb = file3_numb[file2_numb] + + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + #index1=np.where( (400 < ht) & (ht < 500)) + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + m=-1; + + alpha=np.arange(1,0,-1) # just 1 + + + + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + shift_max=np.zeros(cloud_numb.size) + shift_min=np.zeros(cloud_numb.size) + shift_avg=np.zeros(cloud_numb.size) + shift_distance=np.zeros(cloud_numb.size) + + for e1 in cloud_numb: # may take a while to run + + m=m+1 + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + #layers=height/dz + ### + + base=np.amin(location[0]);top=np.amax(location[0]); + #levels=range(base,top+1,1) + + x_unique=np.unique(location[2]) + y_unique=np.unique(location[1]) + xtest1=abs(np.mean(x_unique)-np.median(x_unique)) # median is resistant while mean is not + ytest1=abs(np.mean(y_unique)-np.median(y_unique)) + + #xtest1=abs(np.mean(location[2])-np.median(location[2])) + #ytest1=abs(np.mean(location[1])-np.median(location[1])) + #x_small=np.extract(location[2] < 512,location[2]) + #x_large=np.extract(x_unique > 512,x_unique) + #y_small=np.extract(y_unique < 512,y_unique) + #y_large=np.extract(y_unique > 512,y_unique) + + if xtest1 > epsilon1: + splitx=np.where(location[2] < 512) + location[2][splitx] = location[2][splitx] + nx + + if ytest1 > epsilon1: + splity=np.where(location[1] < 512) + location[1][splity] = location[1][splity] + ny + + + #sys.exit("Error message") + + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + COM=np.zeros((top-base+1,3)) + newlocation_matrix=np.zeros(location_matrix.shape) + cross_area_z=np.zeros(int(layers)) + #u, indices = np.unique(location[0], return_index=True) + #COM[:,0]=u + + + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + # height / dz = layers + + + #COM[z-base,:]=[z,sum(location[1][findz[0]])/findz[0].size, sum(location[2][findz[0]])/findz[0].size] + COM[z-base,:]=[z,np.mean(location[1][findz[0]]), np.mean(location[2][findz[0]])] #find center of mass w/ arithmetic mean + ### not quite (close) + """ + if z0] +turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) +turb[turb<0]=0 +fractalf[ht>100]=turb + + +## upper bound to turb +lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi +#C1=np.argwhere((1/overlap_ratio)>1.5*lam) +keep=np.argwhere(fractalf > lam) +fractalf[np.array(keep)] = lam + +##fractalf = np.minimum(1.5*lam*np.ones(overlap_ratio.size),1/overlap_ratio) -1 ### trying only 3d Koch overpredicts + +#fractalf = np.minimum(((3*np.pi) / 4)*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + +#fractalf = np.minimum( (3*np.pi /4)*np.ones(overlap_ratio.size), 1/overlap_ratio ) +#fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) + +""" +fractal_ones=fractal*np.ones(overlap_ratio.size) +r_fractal= np.minimum(1/fractal_ones,1/overlap_ratio) +r_total = ( (1/(overlap)) + (1/areaz) + (r_fractal) ) -3 # correction: need to subtract 1 from each + +plt.figure() +plt.plot(r_fractal,1/overlap_ratio,'o') +plt.plot(np.arange(0,3,1),'k',linewidth=3) +plt.xlim(left=0) +plt.ylim(bottom=0) +""" + +#shape = 1 / np.exp( -ht/200 ) - 1 + +#r_total = ( (1/(overlap)) + (1/areaz) + (fractal) ) +#r_total = ( (shear) + (shape) + (fractalf) ) +1 + +#updraft_cb=np.mean(wz_cb)*np.zeros(ht.size) +#updraft_cb[ht>50] = wz_cb +#updraft_max=np.mean(wz_cb)*np.zeros(ht.size) +#updraft_max[ht>50] = wz_cb + + +FF = f_turb(ht,200);FF[ht<=100]=0; +shear_sum = abs(shear_sum) +shift_d = np.zeros(ht.size) +shift_d[ht>50] = shift_distance + +shift_d = shift_d + shape*cp**0.5/2 ### draw the picture +updraft = (shear_sum*ht)/shift_d +FS = (shear_sum*ht)/(updraft*cp**0.5) +FS[updraft<0.1] = 0 + +#shear = FS ; fractalf = FF + +r_total = ( (shear) + (shape) + (fractalf) ) +1 + +horizontal= r_total +vertical= 1/overlap_ratio + + +bins=dz; +cmin=3 +### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico +plt.figure(); +HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) +plt.plot(line,'k',linewidth=3) +#plt.plot(ht,FF,'ko') + +#plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) +#plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + +plt.title('Effect of All Contributors'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); +#plt.title('Overlap from Shear') +#plt.title('Overlap from Turbulence') + + +plt.xlabel('Calculated Overlap') +plt.ylabel('Actual Overlap') +#plt.xlabel('Numerical Overlap') +#plt.ylabel('Overlap from Eqn') +#plt.xlabel('Cloud Height') +#plt.ylabel('Calculated Overlap') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') +#plt.clim(0,200) + +#plt.xlim([0,1]) +#plt.ylim([0,1]) +#plt.xlim(left=0) +#plt.ylim(bottom=0) +plt.xlim([0,8]) +plt.ylim([0,8]) #use cmin=5 +#plt.loglog(horizontal,vertical,'o') + + + + +#plt.savefig('arm41400_total_emp1_r_061719.eps', dpi=300,bbox_inches='tight') + +################################################################################### +binwidth=0.1 +###prob plot, histogram ,line plot +plt.figure() +#ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=10,density=True);#,log=True); # may want to use one w/ log & one standard +ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=np.arange(min(r_total*overlap_ratio), max(r_total*overlap_ratio) + binwidth, binwidth),density=True); +plt.yticks(np.arange(0,10,2)) + +""" +#plt.figure() +bincenters = 0.5*(binEdges[1:]+binEdges[:-1]) +plt.plot(bincenters,ybin,'k-',linewidth=2) +""" +plt.title('Accuracy of Model') +plt.xlabel('Relative Effect') +plt.ylabel('Probability Density') + + +#plt.savefig('arm41400_rel_effect_061119.eps', dpi=300,bbox_inches='tight') + +############################# +""" +plt.figure() +plt.hist2d(ht,vertical-horizontal,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis', norm=colors.LogNorm()); + +plt.plot(ht,np.zeros(ht.size),'k',linewidth=3) + + +plt.xlabel('Cloud Height') +plt.ylabel('Residual') + +colorbar=plt.colorbar() +colorbar.set_label('count in bin') +""" +################################################ + +""" +plt.figure() +# Density Plot and Histogram +sns.distplot(r_total*overlap_ratio, hist=True, kde=False, + bins=int(10), color = 'darkblue', + hist_kws={'edgecolor':'black'}, + kde_kws={'linewidth': 2}) +""" + +#plt.figure() +#sns.distplot(r_total*overlap_ratio) + + + +################################################################################## +""" +binwidth=500000 +###prob plot, histogram ,line plot +plt.figure() +horiz = (1/overlap) * cv +#ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=10,density=True);#,log=True); # may want to use one w/ log & one standard +ybin, binEdges, patches =plt.hist(horiz,bins=np.arange(min(horiz), max(horiz) + binwidth, binwidth),density=False); +#plt.yticks(np.arange(0,10,2)) + + +plt.title('Calculated Cloud Cover') +#plt.xlabel('Relative Effect') +#plt.ylabel('Probability Density') + + +cld_cover= sum(ybin*binwidth) +print(cld_cover) +""" +######################################################################################## +""" +plt.figure() + +plt.plot((1/overlap)-1,(1/overlap_ratio),'ob',label='Shear') +#plt.plot(line) +plt.plot((1/overlap)+(1/areaz)-2,(1/overlap_ratio),color='purple',marker='o',linestyle='none',label='Shear and Shape') +plt.plot((1/overlap)+(1/areaz)+(1/fractal)-3,(1/overlap_ratio),color='pink',marker='o',linestyle='None',label='Shear, Shape, and Fractal') +plt.plot(np.arange(0,10,1),'k',linewidth=3) +plt.xlabel('Inverse Calculated Overlap') +plt.ylabel('Inverse Actual Overlap') +plt.title('Inverse Overlap due to Contributions') +plt.legend(loc='lower right', bbox_to_anchor=(1.10, 0.0),fontsize='small',ncol=1) +#plt.savefig('rico2016_contributions_041619.eps', dpi=300, bbox_inches='tight') +""" +""" +plt.figure() +plt.subplot(2,2,1) +plt.hist2d(1/overlap -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.subplot(2,2,2) +plt.hist2d( 1/areaz -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) + +plt.subplot(2,2,3) +plt.hist2d(1/np.ones(overlap_ratio.size)*fractal -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) + +plt.subplot(2,2,4) +plt.hist2d(1/overlap + 1/areaz + 1/fractal -3,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +""" +################################################### +##subplots +""" +plt.figure() +fig, ax = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(9, 4));None + +plt.subplot(1,3,1) +plt.hist2d(1/overlap -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.clim(0,200) +plt.xlim(left=0) +plt.ylim(bottom=0) +plt.title('Shear') + +plt.subplot(1,3,2) +plt.hist2d( 1/overlap + 1/areaz -2,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.clim(0,200) +plt.xlim(left=0) +plt.ylim(bottom=0) +plt.title('Shear,Area') + +plt.subplot(1,3,3) +plt.hist2d(1/overlap + 1/areaz + 1/fractal -3,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.clim(0,200) +plt.xlim(left=0) +plt.ylim(bottom=0) +plt.title('All') + +#plt.suptitle('Inverse Overlap'); +colorbar=plt.colorbar(extend='both'); +colorbar.set_label('count in bin') +plt.clim(0,200) +fig.text(0.5, 0.004, 'Inverse Calculated Overlap', ha='center') +fig.text(0.06, 0.5, 'Inverse Actual Overlap', va='center', rotation='vertical') + +#plt.xlabel('Inverse Calculated Overlap') +#plt.ylabel('Inverse Actual Overlap') +#plt.xlim([0,1]) +#plt.ylim([0,1]) + + +#plt.savefig('rico2016_subplot_invoverlap_042219.eps', dpi=300, bbox_inches='tight') +""" +############################ +""" +plt.figure() + +plt.figure(); +plt.hist2d(1/overlap -1, 1/overlap_ratio,bins=bins,cmin=2,cmap='pink',alpha=0.3); #norm=colors.LogNorm(), normed: normalizes data +plt.hist2d(1/overlap + 1/areaz -2, 1/overlap_ratio,bins=bins,cmin=2,cmap='bone',alpha=0.3); +plt.hist2d(1/overlap -1 + 1/areaz + 1/fractal -3, 1/overlap_ratio,bins=bins,cmin=2,cmap='Blues',alpha=0.3); +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) +plt.plot(line,'k',linewidth=3) +#plt.title('Actual Overlap vs. Area Ratio'); +plt.title('Inverse Overlap'); +colorbar=plt.colorbar(extend='both'); +colorbar.set_label('count in bin') +plt.clim(0,200) +plt.xlabel('Inverse Total Calculated Overlap') +plt.ylabel('Inverse Actual Overlap') +""" + +""" +plt.figure() +plt.scatter(1/overlap -1, 1/overlap_ratio,cmap='pink',alpha=0.3) +plt.scatter(1/overlap + 1/areaz -2, 1/overlap_ratio,cmap='bone',alpha=0.3); +plt.scatter(1/overlap -1 + 1/areaz + 1/fractal -3, 1/overlap_ratio,cmap='Blues',alpha=0.3); +plt.plot(np.arange(0,10,1),'k',linewidth=3) +""" + + + + + + + + + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/volume_no_shear_arm28800.npy b/data/volume_no_shear_arm28800.npy new file mode 100644 index 0000000..cbc4b7c Binary files /dev/null and b/data/volume_no_shear_arm28800.npy differ diff --git a/data/volume_no_shear_arm41400.npy b/data/volume_no_shear_arm41400.npy new file mode 100644 index 0000000..82765d7 Binary files /dev/null and b/data/volume_no_shear_arm41400.npy differ diff --git a/data/volume_no_shear_bomex10800.npy b/data/volume_no_shear_bomex10800.npy new file mode 100644 index 0000000..bcf0ddc Binary files /dev/null and b/data/volume_no_shear_bomex10800.npy differ diff --git a/data/volume_no_shear_bomex12600.npy b/data/volume_no_shear_bomex12600.npy new file mode 100644 index 0000000..6b5d62e Binary files /dev/null and b/data/volume_no_shear_bomex12600.npy differ diff --git a/data/volume_no_shear_bomex14400.npy b/data/volume_no_shear_bomex14400.npy new file mode 100644 index 0000000..2f1d082 Binary files /dev/null and b/data/volume_no_shear_bomex14400.npy differ diff --git a/data/volume_no_shear_bomex16200.npy b/data/volume_no_shear_bomex16200.npy new file mode 100644 index 0000000..3aa5fc4 Binary files /dev/null and b/data/volume_no_shear_bomex16200.npy differ diff --git a/data/volume_no_shear_bomex18000.npy b/data/volume_no_shear_bomex18000.npy new file mode 100644 index 0000000..5aee917 Binary files /dev/null and b/data/volume_no_shear_bomex18000.npy differ diff --git a/data/volume_no_shear_bomex19800.npy b/data/volume_no_shear_bomex19800.npy new file mode 100644 index 0000000..f8551c1 Binary files /dev/null and b/data/volume_no_shear_bomex19800.npy differ diff --git a/data/volume_no_shear_bomex21600.npy b/data/volume_no_shear_bomex21600.npy new file mode 100644 index 0000000..5073348 Binary files /dev/null and b/data/volume_no_shear_bomex21600.npy differ diff --git a/data/volume_no_shear_bomex23400.npy b/data/volume_no_shear_bomex23400.npy new file mode 100644 index 0000000..89ba9fa Binary files /dev/null and b/data/volume_no_shear_bomex23400.npy differ diff --git a/data/volume_no_shear_bomex25200.npy b/data/volume_no_shear_bomex25200.npy new file mode 100644 index 0000000..bb12ad5 Binary files /dev/null and b/data/volume_no_shear_bomex25200.npy differ diff --git a/data/volume_no_shear_bomex27000.npy b/data/volume_no_shear_bomex27000.npy new file mode 100644 index 0000000..67c79d8 Binary files /dev/null and b/data/volume_no_shear_bomex27000.npy differ diff --git a/data/volume_no_shear_bomex28800.npy b/data/volume_no_shear_bomex28800.npy new file mode 100644 index 0000000..f258172 Binary files /dev/null and b/data/volume_no_shear_bomex28800.npy differ diff --git a/data/volume_no_shear_bomex30600.npy b/data/volume_no_shear_bomex30600.npy new file mode 100644 index 0000000..dbfcfb4 Binary files /dev/null and b/data/volume_no_shear_bomex30600.npy differ diff --git a/data/volume_no_shear_bomex32400.npy b/data/volume_no_shear_bomex32400.npy new file mode 100644 index 0000000..18a50ca Binary files /dev/null and b/data/volume_no_shear_bomex32400.npy differ diff --git a/data/volume_no_shear_bomex34200.npy b/data/volume_no_shear_bomex34200.npy new file mode 100644 index 0000000..941f3c4 Binary files /dev/null and b/data/volume_no_shear_bomex34200.npy differ diff --git a/data/volume_no_shear_bomex360.npy b/data/volume_no_shear_bomex360.npy new file mode 100644 index 0000000..4b9aa09 Binary files /dev/null and b/data/volume_no_shear_bomex360.npy differ diff --git a/data/volume_no_shear_bomex36000.npy b/data/volume_no_shear_bomex36000.npy new file mode 100644 index 0000000..4b9aa09 Binary files /dev/null and b/data/volume_no_shear_bomex36000.npy differ diff --git a/data/volume_no_shear_lasso306.npy b/data/volume_no_shear_lasso306.npy new file mode 100644 index 0000000..b18b977 Binary files /dev/null and b/data/volume_no_shear_lasso306.npy differ diff --git a/data/volume_no_shear_rico2016.npy b/data/volume_no_shear_rico2016.npy new file mode 100644 index 0000000..47a273d Binary files /dev/null and b/data/volume_no_shear_rico2016.npy differ diff --git a/data/volume_no_shear_rico828.npy b/data/volume_no_shear_rico828.npy new file mode 100644 index 0000000..21e2752 Binary files /dev/null and b/data/volume_no_shear_rico828.npy differ diff --git a/data/wavg1_arm28800.npy b/data/wavg1_arm28800.npy new file mode 100644 index 0000000..7406afb Binary files /dev/null and b/data/wavg1_arm28800.npy differ diff --git a/data/wavg1_arm41400.npy b/data/wavg1_arm41400.npy new file mode 100644 index 0000000..36483d3 Binary files /dev/null and b/data/wavg1_arm41400.npy differ diff --git a/data/wavg1_bomex10800.npy b/data/wavg1_bomex10800.npy new file mode 100644 index 0000000..2b986bc Binary files /dev/null and b/data/wavg1_bomex10800.npy differ diff --git a/data/wavg1_bomex12600.npy b/data/wavg1_bomex12600.npy new file mode 100644 index 0000000..f4ead8d Binary files /dev/null and b/data/wavg1_bomex12600.npy differ diff --git a/data/wavg1_bomex14400.npy b/data/wavg1_bomex14400.npy new file mode 100644 index 0000000..55871b6 Binary files /dev/null and b/data/wavg1_bomex14400.npy differ diff --git a/data/wavg1_bomex16200.npy b/data/wavg1_bomex16200.npy new file mode 100644 index 0000000..5395e69 Binary files /dev/null and b/data/wavg1_bomex16200.npy differ diff --git a/data/wavg1_bomex18000.npy b/data/wavg1_bomex18000.npy new file mode 100644 index 0000000..e913a54 Binary files /dev/null and b/data/wavg1_bomex18000.npy differ diff --git a/data/wavg1_bomex19800.npy b/data/wavg1_bomex19800.npy new file mode 100644 index 0000000..cdf44a9 Binary files /dev/null and b/data/wavg1_bomex19800.npy differ diff --git a/data/wavg1_rico201600.npy b/data/wavg1_rico201600.npy new file mode 100644 index 0000000..8b78f92 Binary files /dev/null and b/data/wavg1_rico201600.npy differ diff --git a/data/wavg1_rico82800.npy b/data/wavg1_rico82800.npy new file mode 100644 index 0000000..f9148ec Binary files /dev/null and b/data/wavg1_rico82800.npy differ diff --git a/data/wavg_bomex10800.npy b/data/wavg_bomex10800.npy new file mode 100644 index 0000000..f047d34 Binary files /dev/null and b/data/wavg_bomex10800.npy differ diff --git a/data/wavg_bomex12600.npy b/data/wavg_bomex12600.npy new file mode 100644 index 0000000..d807f0c Binary files /dev/null and b/data/wavg_bomex12600.npy differ diff --git a/data/wavg_bomex14400.npy b/data/wavg_bomex14400.npy new file mode 100644 index 0000000..2071583 Binary files /dev/null and b/data/wavg_bomex14400.npy differ diff --git a/data/wavg_bomex16200.npy b/data/wavg_bomex16200.npy new file mode 100644 index 0000000..840c79b Binary files /dev/null and b/data/wavg_bomex16200.npy differ diff --git a/data/wavg_bomex18000.npy b/data/wavg_bomex18000.npy new file mode 100644 index 0000000..82d7e52 Binary files /dev/null and b/data/wavg_bomex18000.npy differ diff --git a/data/wavg_bomex19800.npy b/data/wavg_bomex19800.npy new file mode 100644 index 0000000..dedcc12 Binary files /dev/null and b/data/wavg_bomex19800.npy differ diff --git a/data/wavg_bomex21600.npy b/data/wavg_bomex21600.npy new file mode 100644 index 0000000..ddcd04a Binary files /dev/null and b/data/wavg_bomex21600.npy differ diff --git a/data/wavg_bomex23400.npy b/data/wavg_bomex23400.npy new file mode 100644 index 0000000..2bb44fd Binary files /dev/null and b/data/wavg_bomex23400.npy differ diff --git a/data/wavg_bomex25200.npy b/data/wavg_bomex25200.npy new file mode 100644 index 0000000..0e73222 Binary files /dev/null and b/data/wavg_bomex25200.npy differ diff --git a/data/wavg_bomex27000.npy b/data/wavg_bomex27000.npy new file mode 100644 index 0000000..5e2e37f Binary files /dev/null and b/data/wavg_bomex27000.npy differ diff --git a/data/wavg_bomex28800.npy b/data/wavg_bomex28800.npy new file mode 100644 index 0000000..b07109f Binary files /dev/null and b/data/wavg_bomex28800.npy differ diff --git a/data/wavg_bomex30600.npy b/data/wavg_bomex30600.npy new file mode 100644 index 0000000..2414170 Binary files /dev/null and b/data/wavg_bomex30600.npy differ diff --git a/data/wavg_bomex32400.npy b/data/wavg_bomex32400.npy new file mode 100644 index 0000000..8e78e8b Binary files /dev/null and b/data/wavg_bomex32400.npy differ diff --git a/data/wavg_bomex34200.npy b/data/wavg_bomex34200.npy new file mode 100644 index 0000000..55d6049 Binary files /dev/null and b/data/wavg_bomex34200.npy differ diff --git a/data/wavg_bomex36000.npy b/data/wavg_bomex36000.npy new file mode 100644 index 0000000..681ea09 Binary files /dev/null and b/data/wavg_bomex36000.npy differ diff --git a/data/width_base_rico828.npy b/data/width_base_rico828.npy new file mode 100644 index 0000000..29a7e21 Binary files /dev/null and b/data/width_base_rico828.npy differ diff --git a/data/windshear1.py b/data/windshear1.py new file mode 100644 index 0000000..e134588 --- /dev/null +++ b/data/windshear1.py @@ -0,0 +1,568 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 23 16:06:23 2019 + +@author: anthonys +""" + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil + + +start=time.time() + +############################################################################# + +armd= Dataset("arm.default.0000000.nc","r") +armql=Dataset("arm.ql.0000000.nc","r") +armqlcore=Dataset("arm.qlcore.0000000.nc","r") +ricod= Dataset("rico.default.0000000.nc","r") +ricoql=Dataset("rico.ql.0000000.nc","r") +ricoqlcore=Dataset("rico.qlcore.0000000.nc","r") + +#data = pkgutil.get_data("conf", "fielddump.ql.00.05.track.nc") + + +#print(bomexd.variables.keys()) +#print(bomexd.variables['area']) +#print(bomexd.variables['area'][:][:]) +#print(bomexd.variables) +#print(bomexd.variables.values()) +######################################################################### +# Define variables and importing files +bomexd = Dataset("bomex.default.0000000.nc","r") +area = bomexd.variables["area"][:,:] # fractional area contained in mask +areah = bomexd.variables['areah'][:,:] +time_t=bomexd.variables['time'][:] + +z=bomexd.variables['z'][:] # full level ht +zh=bomexd.variables['zh'][:] # half level height +ql=bomexd.variables['ql'][:,:] + +thl=bomexd.variables['thl'][:,:] # liquid water potential temp +qlfrac=bomexd.variables['qlfrac'][:,:] # cloud fraction +qlcover=bomexd.variables['qlcover'][:] # projected cloud cover + +u2=bomexd.variables['u2'][:,:] #moment 2 of u vel, weighted ave of intenties of pixels in seq of images +u3=bomexd.variables['u3'][:,:] +u4=bomexd.variables['u4'][:,:] + +ugrad=bomexd.variables['ugrad'][:,:] # gradient (shear) of the u velocity +vgrad=bomexd.variables['vgrad'][:,:] +u=bomexd.variables['u'][:,:] # vel in u direction +v=bomexd.variables['v'][:,:] # vel in v direction +w=bomexd.variables['w'][:,:] # vertical velocities + + + +b=bomexd.variables['b'][:,:] # buoyancy +rho=bomexd.variables['rho'][:,:] # full level density +rhoh=bomexd.variables['rhoh'][:,:] # half level density +phydro=bomexd.variables['phydro'][:,:] # full level hydrostatic pressure + + +bomexql=Dataset("bomex.ql.0000000.nc","r") +qlfrac1=bomexql.variables['qlfrac'][:,:] +z1=bomexql.variables['z'][:] +zh1=bomexql.variables['zh'][:] + + +bomexqlcore=Dataset("bomex.qlcore.0000000.nc","r") +qlfrac2=bomexqlcore.variables['qlfrac'][:,:] +z2=bomexqlcore.variables['z'][:] +zh2=bomexqlcore.variables['zh'][:] + + +bomextrack=Dataset("l.0001800.track.nc","r") +cv=bomextrack.variables['cv'][:] # cloud cover by volume +cp=bomextrack.variables['cp'][:] # cloud cover by area +area_proj=bomextrack.variables['area_proj'][:] # projected cloud area +cloudsize=np.sqrt(area_proj) +area_proj_conn=bomextrack.variables['area_proj_conn'][:] # connected projected cloud area +ht=bomextrack.variables['ht'][:] # height +zt=bomextrack.variables['z'][:] +xt=bomextrack.variables['x'][:] +yt=bomextrack.variables['y'][:] +cld_mask=bomextrack.variables['cld_mask'][:,:,:] # +cfrac=bomextrack.variables['cfrac'][:] # cloud fraction:percentage of each pixel in gridbox in model that is covered w/ clouds +nrcloud=bomextrack.variables['nrcloud'][:,:,:] # cloud number, masks (inte array) +nr=bomextrack.variables['nr'][:] # number density rain ? +cb=bomextrack.variables['cb'][:] # cloud base +ct=bomextrack.variables['ct'][:] # cloud top, # ct - cb , height difference +overlap_ratio=bomextrack.variables['chr'][:] # overlap ratio based on cloud height +cfv=bomextrack.variables['cfv'][:,:] # cv for cloud layer/field, cloud field projected area +cfp=bomextrack.variables['cfp'][:,:] # cp for cloud layer/field, cloud field vol per ht +# cfr=cfv/cfp # overall ratio +# rav=bomextrack.variables['rav'][:] # average ratio + +nz=zt.size;nx=xt.size;ny=yt.size; # sizes of dimensions + + + + +bomextrack1=Dataset("l.0003600.track.nc","r") +""" +cv1=bomextrack1.variables['cv'][:] +cp1=bomextrack1.variables['cp'][:] +""" + +bomextrack2=Dataset("l.0005400.track.nc","r") +""" +cv2=bomextrack.variables['cv'][:] +cp2=bomextrack.variables['cp'][:] +area_proj2=bomextrack.variables['area_proj'][:] +cloudsize2=np.sqrt(area_proj) +ht2=bomextrack.variables['ht'][:] +""" + + + +bomexw=Dataset('w.nc','r') + +########################################################################### + +def pyth(u,v): + return np.sqrt(u*u+v*v) + + +def r1(x): + return 1/(1+abs(x)) + +def r2(x): + return 1/(1+x*x) + +def rpow(x): + return 1/(1+(abs(x))**(0.2)) + + +def rb(u,w,h,b): + return 1/(1+abs((u/w)*(h/b))) + +def rbpow(u,w,h,b): + return 1/(1+abs((u**0.2/w**0.2)*(h**0.2/b**0.2))) + + +def rexp(x): + return np.exp(-abs(x)) + + + +def rb1(grad,ht,w,one,width): + return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + +def ra0(grad,ht,w,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + return (1+multiple)**(-1) + + + +def ra(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/ct + return (1+multiple*multiplicand)**(-1) + + + + +#################################### + +filenames=[bomexd]#, ricod, armd] + +for file in filenames: + zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + + + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + #r=1/(1+abs(ugrad2(zt))) + #plt.plot(ugrad2(zt),r1(ugrad2(zt))) + + #plt.plot(grad,r1(grad)) + #plt.title('r vs. gradient ') + plt.plot(1/r1(grad),grad) + plt.title('gradient vs. 1/r') + + + ## + gradint=interp1d(zt,grad,axis=0) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + #plt.plot(gradint(ztnew),overlap_ratio,'o') + ## + + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew), bins=bins,cmin=0.5) + #colorbar = plt.colorbar() + #colorbar.set_label('counts in bin') + + + + # using rb1 + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + + plt.plot(1/rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'o') + plt.title('gradient vs. 1/ratio') + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.plot(gradint(ztnew),rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),'o') + #plt.title('ratio vs. grad') + + + + # using ra + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + + plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'o') + plt.title('gradient vs. 1/ratio') + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + #plt.plot(gradint(ztnew),ra0(gradint(ztnew),ht,wnew2(ztnew),one),'o') + #plt.title('ratio vs. grad') + #plt.hist2d(gradint(ztnew),overlap_ratio,bins=bins,cmin=0.5) + + ############################################################ +# shear vs. 1/ overlap with hist2d grid +""" + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + + + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + #r=1/(1+abs(ugrad2(zt))) + #plt.plot(ugrad2(zt),r1(ugrad2(zt))) + + #plt.plot(grad,r1(grad)) + #plt.title('r vs. gradient ') + plt.plot(1/r1(grad),grad) + plt.title('gradient vs. 1/r') + + + ## + gradint=interp1d(zt,grad,axis=0) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + #plt.plot(gradint(ztnew),overlap_ratio,'o') + ## + + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew), bins=bins,cmin=0.5) + #colorbar = plt.colorbar() + #colorbar.set_label('counts in bin') + + + + # using rb(u,w,h,b) + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'o') + plt.title('gradient vs. 1/ratio') + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + +""" + +################################################################################### + +""" +# seems like vert updraft vel has little affect on ratio + plt.figure() + for t in range(time_t.size): + wnew1=w[t,:] + + + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + #r=1/(1+abs(ugrad2(zt))) + #plt.plot(ugrad2(zt),r1(ugrad2(zt))) + + + + + ## + wint=interp1d(zh,wnew1,axis=0) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + #plt.plot(gradint(ztnew),overlap_ratio,'o') + ## + + bins=15 + plt.hist2d(wint(ztnew), overlap_ratio, bins=bins,cmin=10.5) + #plt.plot(wint(ztnew),overlap_ratio,'o') + #colorbar = plt.colorbar() + #colorbar.set_label('counts in bin') +""" + + +""" + # using rb(u,w,h,b) + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + plt.plot(gradint(ztnew),rb(gradint(ztnew),one,ht,cb),'o') + plt.title('rb vs. gradient ') + bins=15 + plt.hist2d(gradint(ztnew), overlap_ratio, bins=bins,cmin=0.5) + + # plt.plot(zt,wnew2(zt)) # w is small ~0 +""" + + +""" + # plotting grad vs. w + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + #ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + #plt.plot(gradint(ztnew),rb(gradint(ztnew),one,ht,cb),'o') + #plt.title('rb vs. gradient ') + plt.plot(wnew2(zt),gradint(zt)) + plt.title('grad vs. w') +""" +################################################################################ +""" + plt.figure() + for t in range(time_t.size): + vgrad1=vgrad[t,:] + vgrad2=interp1d(zh,vgrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + r=1/(1+abs(vgrad2(zt))) + plt.plot(vgrad2(zt),r) + plt.title('r vs. gradient of v') +""" + + + + +""" + for t in range(time_t.size): + plt.figure() + ugrad1=ugrad[t,:] + ugrad2=interp1d(zh,ugrad1) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1) + plt.plot(wnew2(zt),ugrad2(zt)) + plt.title('gradient of u vs. w') +""" + + +""" +plt.figure() +plt.plot(cb,ht) # cb= width of cld base? +plt.title('ht vs. cb') + +plt.figure() +plt.plot(cb,ct) +plt.title('ct vs. cb') +plt.show() +""" + +""" +# r(u,w,ht,cb) +ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + +plt.figure() +for t in range(time_t.size): + ugrad1=ugrad[t,:] + ugrad2=interp1d(zh,ugrad1) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1) + + plt.plot(wnew2(ztnew),ugrad2(ztnew)) + + #rb=1/(1+(ugrad2(ztnew)/wnew2(ztnew))*(ht/cb)) + + #plt.plot(ugrad2(ztnew),rb) + #plt.title('rb vs. gradient of u') +""" + +""" +# r(u,w,ht,cb) with w=1 +ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + +plt.figure() +for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + zh=bomexd.variables['zh'][:] + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1) + + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + plt.plot(grad,rb(grad,wnew2(z),ht,cb)) + plt.title('rb vs. gradient of u') + +""" + +""" +# plots of overlap_ratio (track file) vs. grad of u +for t in range(time_t.size): + ugrad1=ugrad[t,:] + ugrad2=interp1d(zh,ugrad1) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + plt.figure() + #plt.plot(ugrad2(ztnew),overlap_ratio) + bins=15 + plt.hist2d(ugrad2(ztnew), overlap_ratio, bins=bins,cmin=0.5) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.title('ratio vs. gradient of u') + + """ + + + + + + + + +############################################################################# +# shows that ct>=cb +# plt.plot(cb,ct,'o');plt.plot(cb,cb,'-');None +# ct -cb incr as r decr *(inv rel) +#plt.plot(ct-cb,overlap_ratio,'o');None +# linear relationship +#plt.plot(ct-cb,ht,'o');None +# inv relationship +# plt.plot(ht,overlap_ratio,'o');None +# inv relationship +# plt.plot(area_proj,overlap_ratio,'o');None + + + + + +#################################################################### +#savfig('filename.pdf') +#savfig('filename.png') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + diff --git a/data/windshear2.py b/data/windshear2.py new file mode 100644 index 0000000..4fe9a48 --- /dev/null +++ b/data/windshear2.py @@ -0,0 +1,410 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jan 25 15:33:07 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil + + +start=time.time() + +############################################################################# +""" +armd= Dataset("arm.default.0000000.nc","r") +armql=Dataset("arm.ql.0000000.nc","r") +armqlcore=Dataset("arm.qlcore.0000000.nc","r") +ricod= Dataset("rico.default.0000000.nc","r") +ricoql=Dataset("rico.ql.0000000.nc","r") +ricoqlcore=Dataset("rico.qlcore.0000000.nc","r") +""" +#data = pkgutil.get_data("conf", "fielddump.ql.00.05.track.nc") + + +#print(bomexd.variables.keys()) +#print(bomexd.variables['area']) +#print(bomexd.variables['area'][:][:]) +#print(bomexd.variables) +#print(bomexd.variables.values()) +######################################################################### +# Define variables and importing files +""" +bomexd = Dataset("bomex.default.0000000.nc","r") +area = bomexd.variables["area"][:,:] # fractional area contained in mask +areah = bomexd.variables['areah'][:,:] +time_t=bomexd.variables['time'][:] + +z=bomexd.variables['z'][:] # full level ht +zh=bomexd.variables['zh'][:] # half level height +ql=bomexd.variables['ql'][:,:] + +thl=bomexd.variables['thl'][:,:] # liquid water potential temp +qlfrac=bomexd.variables['qlfrac'][:,:] # cloud fraction +qlcover=bomexd.variables['qlcover'][:] # projected cloud cover + +u2=bomexd.variables['u2'][:,:] #moment 2 of u vel, weighted ave of intenties of pixels in seq of images +u3=bomexd.variables['u3'][:,:] +u4=bomexd.variables['u4'][:,:] + +ugrad=bomexd.variables['ugrad'][:,:] # gradient (shear) of the u velocity +vgrad=bomexd.variables['vgrad'][:,:] +u=bomexd.variables['u'][:,:] # vel in u direction +v=bomexd.variables['v'][:,:] # vel in v direction +w=bomexd.variables['w'][:,:] # vertical velocities + + + +b=bomexd.variables['b'][:,:] # buoyancy +rho=bomexd.variables['rho'][:,:] # full level density +rhoh=bomexd.variables['rhoh'][:,:] # half level density +phydro=bomexd.variables['phydro'][:,:] # full level hydrostatic pressure + + +bomexql=Dataset("bomex.ql.0000000.nc","r") +qlfrac1=bomexql.variables['qlfrac'][:,:] +z1=bomexql.variables['z'][:] +zh1=bomexql.variables['zh'][:] + + +bomexqlcore=Dataset("bomex.qlcore.0000000.nc","r") +qlfrac2=bomexqlcore.variables['qlfrac'][:,:] +z2=bomexqlcore.variables['z'][:] +zh2=bomexqlcore.variables['zh'][:] + + +bomextrack=Dataset("l.0001800.track.nc","r") +cv=bomextrack.variables['cv'][:] # cloud cover by volume +cp=bomextrack.variables['cp'][:] # cloud cover by area +area_proj=bomextrack.variables['area_proj'][:] # projected cloud area +cloudsize=np.sqrt(area_proj) +area_proj_conn=bomextrack.variables['area_proj_conn'][:] # connected projected cloud area +ht=bomextrack.variables['ht'][:] # height +zt=bomextrack.variables['z'][:] +xt=bomextrack.variables['x'][:] +yt=bomextrack.variables['y'][:] +cld_mask=bomextrack.variables['cld_mask'][:,:,:] # +cfrac=bomextrack.variables['cfrac'][:] # cloud fraction:percentage of each pixel in gridbox in model that is covered w/ clouds +nrcloud=bomextrack.variables['nrcloud'][:,:,:] # cloud number, masks (inte array) +nr=bomextrack.variables['nr'][:] # number density rain ? +cb=bomextrack.variables['cb'][:] # cloud base +ct=bomextrack.variables['ct'][:] # cloud top, # ct - cb , height difference +overlap_ratio=bomextrack.variables['chr'][:] # overlap ratio based on cloud height +cfv=bomextrack.variables['cfv'][:,:] # cv for cloud layer/field, cloud field projected area +cfp=bomextrack.variables['cfp'][:,:] # cp for cloud layer/field, cloud field vol per ht +# cfr=cfv/cfp # overall ratio +# rav=bomextrack.variables['rav'][:] # average ratio + +nz=zt.size;nx=xt.size;ny=yt.size; # sizes of dimensions + + + + +bomextrack1=Dataset("l.0003600.track.nc","r") + +cv1=bomextrack1.variables['cv'][:] +cp1=bomextrack1.variables['cp'][:] + + +bomextrack2=Dataset("l.0005400.track.nc","r") + +cv2=bomextrack.variables['cv'][:] +cp2=bomextrack.variables['cp'][:] +area_proj2=bomextrack.variables['area_proj'][:] +cloudsize2=np.sqrt(area_proj) +ht2=bomextrack.variables['ht'][:] + + + + +bomexw=Dataset('w.nc','r') +bomexqt=Dataset('/data/bomex/qt.nc','r') + +""" +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +def r1(x): + return 1/(1+abs(x)) + + + +def rb1(grad,ht,w,one,width): + return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + +def ra0(grad,ht,w,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + return (1+multiple)**(-1) + + +""" +def ra1(grad,ht,w,cv,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/(cv)**(0.5) + return (1+multiple*multiplicand)**(-1) +""" + +def ra2(grad,ht,w,ct,cv,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/(cv)**(0.5) + return (1+multiple*multiplicand)**(-1) +######## +# when |ct-cb|<1 ra -> rashear +def rashear(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/cb + return (1+multiple*multiplicand)**(-1) + +def raanvil(grad,ht,w,ct,cb,one): + multiple=1/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return (1+multiple*multiplicand)**(-1) + + +# model +def ra(grad,ht,w,ct,cb,one): + multiple=(np.maximum(abs(grad)*ht,one))/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return ((1)+multiple*multiplicand)**(-1) +############ +def raalt(grad,ht,w,ct,cb,one): + term1=abs(grad*ht)/(np.maximum(abs(w),one)*cb) + term2=abs(ct-cb)/cb + return ((1) + term1 + term2)**(-1) + + +#################################### + +# script + +bomexfilenames=[bomextrack216] + + + +for file in filenames: + zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + + + + # using ra + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #plt.figure() + #plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=40 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + #plt.plot(ra1(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + #plt.title('grad vs. ratio') + ##plt.hist2d(gradint(ztnew),overlap_ratio,bins=bins,cmin=0.5) + ############################################################## + plt.hist2d(rashear(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),bins=bins,cmin=0.5) + plt.title('shear vs. ratio') + #plt.hist2d(rashear(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew)*ht,bins=bins,cmin=0.5) + #plt.title('shear*ht vs. ratio') + #plt.hist2d(raanvil(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),abs(ct-cb),bins=bins,cmin=0.5) + #plt.title('ct-cb vs. ratio') + #plt.hist2d(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),ht,bins=bins,cmin=0.5) + #plt.title('ht vs. ratio') + ##plt.plot(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),ht,'o') + #plt.hist2d(overlap_ratio,ht,bins=bins,cmin=0.5) + + #z=np.polyfit(overlap_ratio,ht,1) + #plt.plot(overlap_ratio,z[0]*overlap_ratio +z[1]) + ############################################################### + + + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + """ + # using rb1 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + plt.plot(rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + plt.title('grad vs. ratio') + """ + + + + + + """ + # using ra0 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + plt.plot(ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + plt.title('grad vs. ratio') + + """ + + + + + + +#################################################################### +#savfig('filename.pdf') +#savfig('filename.png') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + diff --git a/data/windshear3.py b/data/windshear3.py new file mode 100644 index 0000000..45674dc --- /dev/null +++ b/data/windshear3.py @@ -0,0 +1,375 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Jan 28 12:00:15 2019 + +@author: anthonys +""" + +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jan 25 15:33:07 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil + + +start=time.time() + +############################################################################# +""" +armd= Dataset("arm.default.0000000.nc","r") +armql=Dataset("arm.ql.0000000.nc","r") +armqlcore=Dataset("arm.qlcore.0000000.nc","r") +ricod= Dataset("rico.default.0000000.nc","r") +ricoql=Dataset("rico.ql.0000000.nc","r") +ricoqlcore=Dataset("rico.qlcore.0000000.nc","r") +""" +#data = pkgutil.get_data("conf", "fielddump.ql.00.05.track.nc") + + +#print(bomexd.variables.keys()) +#print(bomexd.variables['area']) +#print(bomexd.variables['area'][:][:]) +#print(bomexd.variables) +#print(bomexd.variables.values()) +######################################################################### +# Define variables and importing files +""" +bomexd = Dataset("bomex.default.0000000.nc","r") +area = bomexd.variables["area"][:,:] # fractional area contained in mask +areah = bomexd.variables['areah'][:,:] +time_t=bomexd.variables['time'][:] + +z=bomexd.variables['z'][:] # full level ht +zh=bomexd.variables['zh'][:] # half level height +ql=bomexd.variables['ql'][:,:] + +thl=bomexd.variables['thl'][:,:] # liquid water potential temp +qlfrac=bomexd.variables['qlfrac'][:,:] # cloud fraction +qlcover=bomexd.variables['qlcover'][:] # projected cloud cover + +u2=bomexd.variables['u2'][:,:] #moment 2 of u vel, weighted ave of intenties of pixels in seq of images +u3=bomexd.variables['u3'][:,:] +u4=bomexd.variables['u4'][:,:] + +ugrad=bomexd.variables['ugrad'][:,:] # gradient (shear) of the u velocity +vgrad=bomexd.variables['vgrad'][:,:] +u=bomexd.variables['u'][:,:] # vel in u direction +v=bomexd.variables['v'][:,:] # vel in v direction +w=bomexd.variables['w'][:,:] # vertical velocities + + + +b=bomexd.variables['b'][:,:] # buoyancy +rho=bomexd.variables['rho'][:,:] # full level density +rhoh=bomexd.variables['rhoh'][:,:] # half level density +phydro=bomexd.variables['phydro'][:,:] # full level hydrostatic pressure + + +bomexql=Dataset("bomex.ql.0000000.nc","r") +qlfrac1=bomexql.variables['qlfrac'][:,:] +z1=bomexql.variables['z'][:] +zh1=bomexql.variables['zh'][:] + + +bomexqlcore=Dataset("bomex.qlcore.0000000.nc","r") +qlfrac2=bomexqlcore.variables['qlfrac'][:,:] +z2=bomexqlcore.variables['z'][:] +zh2=bomexqlcore.variables['zh'][:] + + +bomextrack=Dataset("l.0001800.track.nc","r") +cv=bomextrack.variables['cv'][:] # cloud cover by volume +cp=bomextrack.variables['cp'][:] # cloud cover by area +area_proj=bomextrack.variables['area_proj'][:] # projected cloud area +cloudsize=np.sqrt(area_proj) +area_proj_conn=bomextrack.variables['area_proj_conn'][:] # connected projected cloud area +ht=bomextrack.variables['ht'][:] # height +zt=bomextrack.variables['z'][:] +xt=bomextrack.variables['x'][:] +yt=bomextrack.variables['y'][:] +cld_mask=bomextrack.variables['cld_mask'][:,:,:] # +cfrac=bomextrack.variables['cfrac'][:] # cloud fraction:percentage of each pixel in gridbox in model that is covered w/ clouds +nrcloud=bomextrack.variables['nrcloud'][:,:,:] # cloud number, masks (inte array) +nr=bomextrack.variables['nr'][:] # number density rain ? +cb=bomextrack.variables['cb'][:] # cloud base +ct=bomextrack.variables['ct'][:] # cloud top, # ct - cb , height difference +overlap_ratio=bomextrack.variables['chr'][:] # overlap ratio based on cloud height +cfv=bomextrack.variables['cfv'][:,:] # cv for cloud layer/field, cloud field projected area +cfp=bomextrack.variables['cfp'][:,:] # cp for cloud layer/field, cloud field vol per ht +# cfr=cfv/cfp # overall ratio +# rav=bomextrack.variables['rav'][:] # average ratio + +nz=zt.size;nx=xt.size;ny=yt.size; # sizes of dimensions + + + + +bomextrack1=Dataset("l.0003600.track.nc","r") + +cv1=bomextrack1.variables['cv'][:] +cp1=bomextrack1.variables['cp'][:] + + +bomextrack2=Dataset("l.0005400.track.nc","r") + +cv2=bomextrack.variables['cv'][:] +cp2=bomextrack.variables['cp'][:] +area_proj2=bomextrack.variables['area_proj'][:] +cloudsize2=np.sqrt(area_proj) +ht2=bomextrack.variables['ht'][:] + + + + +bomexw=Dataset('w.nc','r') +bomexqt=Dataset('/data/bomex/qt.nc','r') + +""" +################################################################################ +# importing files +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') + + + + +########################################################################### + +def pyth(u,v): + return np.sqrt(u*u+v*v) + + +def r1(x): + return 1/(1+abs(x)) + + +def rb1(grad,ht,w,one,width): + return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + +def ra0(grad,ht,w,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + return (1+multiple)**(-1) + +def ra1(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/ct + return (1+multiple*multiplicand)**(-1) + +def ra2(grad,ht,w,ct,cv,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/(cv)**(0.5) + return (1+multiple*multiplicand)**(-1) + +def ra(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/ct + return (1+multiple*multiplicand)**(-1) + + +#################################### + + + + +filenames=[bomexd]#, ricod, armd] +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144] + + + + +for file in filenames: + zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + elif file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + elif file == armd: + for file1 in armfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + + + + + + # using ra + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #plt.figure() + #plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + plt.plot(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + plt.title('grad vs. ratio') + ##plt.hist2d(gradint(ztnew),overlap_ratio,bins=bins,cmin=0.5) + #plt.hist2d(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),ct-cb,bins=bins,cmin=0.5) + #plt.title('ct vs. ratio') + + + + + """ + # using rb1 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + plt.plot(rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + plt.title('grad vs. ratio') + """ + + + + + + """ + # using ra0 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + plt.plot(ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + plt.title('grad vs. ratio') + + """ + + + +#################################################################### +#savfig('filename.pdf') +#savfig('filename.png') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + diff --git a/data/windshear4.py b/data/windshear4.py new file mode 100644 index 0000000..7b17bc7 --- /dev/null +++ b/data/windshear4.py @@ -0,0 +1,299 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 4 11:11:48 2019 + +@author: anthonys +""" + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +def rb1(grad,ht,w,one,width): + #return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + return 1/ ( (abs(grad)*ht) / (width*np.maximum(abs(w),one) ) +1 ) + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack342] +ricofilenames=[ricotrack828] +armfilenames=[armtrack126] +conditional_height=2000 + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + uv=np.zeros((time_t.size, zt.size)) + grad=np.zeros((time_t.size, zt.size)) + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv[t]=pyth(unew,vnew) + grad[t]=np.gradient(uv[t]) + + uv_z=np.mean(uv, axis=0) # average among different times + grad_z=np.mean(grad, axis=0) # average among different times + + #uv_diff=np.zeros(zt.size -1) + #for i in range(zt.size -1): + # uv_diff[i] = uv_z[i+1] - uv_z[i] + + + shear0 = ( uv_z[ct] - uv_z[cb] ) / 1 + shear1 = uv_z[ct] - uv_z[cb-1] # need to subtract 1 from cb OR add 1 to ct + shear2 = uv_z[ct+1] - uv_z[cb] # need to subtract 1 from cb OR add 1 to ct + shear3 = np.zeros(cb.size) + #shear4 = np.zeros(cb.size) + s1 = np.zeros(cb.size) + A_T=np.zeros(cb.size) + s2=np.zeros(cb.size) + s3= ( ( (dz*ct)**2 - (dz*cb)**2 ) / ht**2 )**(1/4) + for i in range(cb.size): + shear3[i] = sum(grad_z[cb[i]:ct[i]+1]) / 1 + #shear4[i] = sum(uv_diff[cb[i]+1:ct[i]+1]) + if uv_z[ct[i]] >= uv_z[cb[i]]: + s1[i]=2*dz*sum(uv_z[cb[i]:ct[i]+1]) / (ht[i]*ht[i]) + A_T[i]=dz*sum(uv_z[cb[i]:ct[i]+1]) + s2[i]= ( uv_z[ct[i]] - uv_z[cb[i]] )**2 / (2*dz*sum(uv_z[cb[i]:ct[i]+1])) + elif uv_z[ct[i]] < uv_z[cb[i]]: + s1[i]=-2*dz*sum(uv_z[cb[i]:ct[i]+1]) / (ht[i]*ht[i]) + A_T[i]=-dz*sum(uv_z[cb[i]:ct[i]+1]) + + index_shear=np.where(ht > 0) + ht_shear=ht[index_shear[0]] # taking the ht values according to indices above + overlap_ratio_shear=overlap_ratio[index_shear[0]]; + s1_shear= s1[index_shear[0]] + s2_shear= s2[index_shear[0]] + + ### plot shear vs. overlap + bins=dz + + plt.figure() + plt.hist2d(overlap_ratio,shear3,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + plt.figure() + plt.hist2d(overlap_ratio,shear0,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + plt.figure() + plt.hist2d(overlap_ratio_shear,s1_shear,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + plt.figure() + plt.hist2d(overlap_ratio_shear,s2_shear,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/windshear5.py b/data/windshear5.py new file mode 100644 index 0000000..7e45586 --- /dev/null +++ b/data/windshear5.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Mar 21 12:33:14 2019 + +@author: anthonys +""" + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +def rb1(grad,ht,w,one,width): + #return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + return 1/ ( (abs(grad)*ht) / (width*np.maximum(abs(w),one) ) +1 ) + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack342] +ricofilenames=[ricotrack828] +armfilenames=[armtrack126] +conditional_height=2000 + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + uz=np.mean(u,axis=0) # avg among diff times + vz=np.mean(v,axis=0) # avg among diff times + wz=np.mean(w,axis=0) + + wint=interp1d(zh,wz,axis=0) + wz1=wint(zt) + + + one=np.ones(wz1.size) + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + s_u=duz/np.maximum(wz1,one) + s_v=dvz/np.maximum(wz1,one) + + #Gmean=(s_u*s_v)**(0.5) + #Amean=(s_u+s_v)/2 + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0=np.zeros(cb.size) + shear1=np.zeros(cb.size) + for i in range(cb.size): + """ + du=uz[ct[i]]-uz[cb[i]] + dv=vz[ct[i]]-vz[cb[i]] + w1=np.mean(wz1[cb[i]:ct[i]+1]) + su=du/max(w1,1) + sv=dv/max(w1,1) + Hmean=(2*su*sv) / max( (su + sv) , 1) + shear0[i]=Hmean + """ + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + + #shear0[i] = np.mean(Hmean[cb[i]:ct[i]+1]) + #shear0[i] = Hmean[ct[i]] - Hmean[cb[i]] + bins=2*dz + + plt.figure() + plt.hist2d(overlap_ratio,abs(shear0),bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + #plt.ylim([min(shear0),max(shear0)]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/wz_avg_arm28800.npy b/data/wz_avg_arm28800.npy new file mode 100644 index 0000000..dc2b695 Binary files /dev/null and b/data/wz_avg_arm28800.npy differ diff --git a/data/wz_avg_arm41400.npy b/data/wz_avg_arm41400.npy new file mode 100644 index 0000000..bfa81fb Binary files /dev/null and b/data/wz_avg_arm41400.npy differ diff --git a/data/wz_avg_bomex10800.npy b/data/wz_avg_bomex10800.npy new file mode 100644 index 0000000..6ff71a9 Binary files /dev/null and b/data/wz_avg_bomex10800.npy differ diff --git a/data/wz_avg_bomex12600.npy b/data/wz_avg_bomex12600.npy new file mode 100644 index 0000000..13cd67d Binary files /dev/null and b/data/wz_avg_bomex12600.npy differ diff --git a/data/wz_avg_bomex14400.npy b/data/wz_avg_bomex14400.npy new file mode 100644 index 0000000..d6a7781 Binary files /dev/null and b/data/wz_avg_bomex14400.npy differ diff --git a/data/wz_avg_bomex16200.npy b/data/wz_avg_bomex16200.npy new file mode 100644 index 0000000..7c9b325 Binary files /dev/null and b/data/wz_avg_bomex16200.npy differ diff --git a/data/wz_avg_bomex18000.npy b/data/wz_avg_bomex18000.npy new file mode 100644 index 0000000..8d8e5b1 Binary files /dev/null and b/data/wz_avg_bomex18000.npy differ diff --git a/data/wz_avg_bomex19800.npy b/data/wz_avg_bomex19800.npy new file mode 100644 index 0000000..316905b Binary files /dev/null and b/data/wz_avg_bomex19800.npy differ diff --git a/data/wz_avg_bomex21600.npy b/data/wz_avg_bomex21600.npy new file mode 100644 index 0000000..9009451 Binary files /dev/null and b/data/wz_avg_bomex21600.npy differ diff --git a/data/wz_avg_bomex23400.npy b/data/wz_avg_bomex23400.npy new file mode 100644 index 0000000..8450fd4 Binary files /dev/null and b/data/wz_avg_bomex23400.npy differ diff --git a/data/wz_avg_bomex25200.npy b/data/wz_avg_bomex25200.npy new file mode 100644 index 0000000..8cb5304 Binary files /dev/null and b/data/wz_avg_bomex25200.npy differ diff --git a/data/wz_avg_bomex27000.npy b/data/wz_avg_bomex27000.npy new file mode 100644 index 0000000..1589bf8 Binary files /dev/null and b/data/wz_avg_bomex27000.npy differ diff --git a/data/wz_avg_bomex28800.npy b/data/wz_avg_bomex28800.npy new file mode 100644 index 0000000..37b57f2 Binary files /dev/null and b/data/wz_avg_bomex28800.npy differ diff --git a/data/wz_avg_bomex30600.npy b/data/wz_avg_bomex30600.npy new file mode 100644 index 0000000..97c8616 Binary files /dev/null and b/data/wz_avg_bomex30600.npy differ diff --git a/data/wz_avg_bomex32400.npy b/data/wz_avg_bomex32400.npy new file mode 100644 index 0000000..568f9b6 Binary files /dev/null and b/data/wz_avg_bomex32400.npy differ diff --git a/data/wz_avg_bomex34200.npy b/data/wz_avg_bomex34200.npy new file mode 100644 index 0000000..94ca9ff Binary files /dev/null and b/data/wz_avg_bomex34200.npy differ diff --git a/data/wz_avg_bomex36000.npy b/data/wz_avg_bomex36000.npy new file mode 100644 index 0000000..5f77ab1 Binary files /dev/null and b/data/wz_avg_bomex36000.npy differ diff --git a/data/wz_avg_rico201600.npy b/data/wz_avg_rico201600.npy new file mode 100644 index 0000000..b1459e4 Binary files /dev/null and b/data/wz_avg_rico201600.npy differ diff --git a/data/wz_avg_rico82800.npy b/data/wz_avg_rico82800.npy new file mode 100644 index 0000000..f342a78 Binary files /dev/null and b/data/wz_avg_rico82800.npy differ diff --git a/data/wz_cb_arm28800.npy b/data/wz_cb_arm28800.npy new file mode 100644 index 0000000..7a14f37 Binary files /dev/null and b/data/wz_cb_arm28800.npy differ diff --git a/data/wz_cb_arm41400.npy b/data/wz_cb_arm41400.npy new file mode 100644 index 0000000..c42d49e Binary files /dev/null and b/data/wz_cb_arm41400.npy differ diff --git a/data/wz_cb_bomex10800.npy b/data/wz_cb_bomex10800.npy new file mode 100644 index 0000000..5e4adc3 Binary files /dev/null and b/data/wz_cb_bomex10800.npy differ diff --git a/data/wz_cb_bomex12600.npy b/data/wz_cb_bomex12600.npy new file mode 100644 index 0000000..076c4e7 Binary files /dev/null and b/data/wz_cb_bomex12600.npy differ diff --git a/data/wz_cb_bomex14400.npy b/data/wz_cb_bomex14400.npy new file mode 100644 index 0000000..ded5689 Binary files /dev/null and b/data/wz_cb_bomex14400.npy differ diff --git a/data/wz_cb_bomex16200.npy b/data/wz_cb_bomex16200.npy new file mode 100644 index 0000000..bc3cb4e Binary files /dev/null and b/data/wz_cb_bomex16200.npy differ diff --git a/data/wz_cb_bomex18000.npy b/data/wz_cb_bomex18000.npy new file mode 100644 index 0000000..82cd2cd Binary files /dev/null and b/data/wz_cb_bomex18000.npy differ diff --git a/data/wz_cb_bomex19800.npy b/data/wz_cb_bomex19800.npy new file mode 100644 index 0000000..f49088f Binary files /dev/null and b/data/wz_cb_bomex19800.npy differ diff --git a/data/wz_cb_bomex21600.npy b/data/wz_cb_bomex21600.npy new file mode 100644 index 0000000..e6d933b Binary files /dev/null and b/data/wz_cb_bomex21600.npy differ diff --git a/data/wz_cb_bomex23400.npy b/data/wz_cb_bomex23400.npy new file mode 100644 index 0000000..3437895 Binary files /dev/null and b/data/wz_cb_bomex23400.npy differ diff --git a/data/wz_cb_bomex25200.npy b/data/wz_cb_bomex25200.npy new file mode 100644 index 0000000..051cbc5 Binary files /dev/null and b/data/wz_cb_bomex25200.npy differ diff --git a/data/wz_cb_bomex27000.npy b/data/wz_cb_bomex27000.npy new file mode 100644 index 0000000..ae1da2c Binary files /dev/null and b/data/wz_cb_bomex27000.npy differ diff --git a/data/wz_cb_bomex28800.npy b/data/wz_cb_bomex28800.npy new file mode 100644 index 0000000..f7f9fc6 Binary files /dev/null and b/data/wz_cb_bomex28800.npy differ diff --git a/data/wz_cb_bomex30600.npy b/data/wz_cb_bomex30600.npy new file mode 100644 index 0000000..a163897 Binary files /dev/null and b/data/wz_cb_bomex30600.npy differ diff --git a/data/wz_cb_bomex32400.npy b/data/wz_cb_bomex32400.npy new file mode 100644 index 0000000..072b3e4 Binary files /dev/null and b/data/wz_cb_bomex32400.npy differ diff --git a/data/wz_cb_bomex34200.npy b/data/wz_cb_bomex34200.npy new file mode 100644 index 0000000..7831758 Binary files /dev/null and b/data/wz_cb_bomex34200.npy differ diff --git a/data/wz_cb_bomex36000.npy b/data/wz_cb_bomex36000.npy new file mode 100644 index 0000000..847c7d1 Binary files /dev/null and b/data/wz_cb_bomex36000.npy differ diff --git a/data/wz_cb_rico201600.npy b/data/wz_cb_rico201600.npy new file mode 100644 index 0000000..f540ee3 Binary files /dev/null and b/data/wz_cb_rico201600.npy differ diff --git a/data/wz_cb_rico82800.npy b/data/wz_cb_rico82800.npy new file mode 100644 index 0000000..8284191 Binary files /dev/null and b/data/wz_cb_rico82800.npy differ diff --git a/data/wz_ct_arm28800.npy b/data/wz_ct_arm28800.npy new file mode 100644 index 0000000..a7d1864 Binary files /dev/null and b/data/wz_ct_arm28800.npy differ diff --git a/data/wz_ct_arm41400.npy b/data/wz_ct_arm41400.npy new file mode 100644 index 0000000..c7e8930 Binary files /dev/null and b/data/wz_ct_arm41400.npy differ diff --git a/data/wz_ct_bomex10800.npy b/data/wz_ct_bomex10800.npy new file mode 100644 index 0000000..d0c8316 Binary files /dev/null and b/data/wz_ct_bomex10800.npy differ diff --git a/data/wz_ct_bomex12600.npy b/data/wz_ct_bomex12600.npy new file mode 100644 index 0000000..e562449 Binary files /dev/null and b/data/wz_ct_bomex12600.npy differ diff --git a/data/wz_ct_bomex14400.npy b/data/wz_ct_bomex14400.npy new file mode 100644 index 0000000..686dea9 Binary files /dev/null and b/data/wz_ct_bomex14400.npy differ diff --git a/data/wz_ct_bomex16200.npy b/data/wz_ct_bomex16200.npy new file mode 100644 index 0000000..7b54446 Binary files /dev/null and b/data/wz_ct_bomex16200.npy differ diff --git a/data/wz_ct_bomex18000.npy b/data/wz_ct_bomex18000.npy new file mode 100644 index 0000000..2b2d991 Binary files /dev/null and b/data/wz_ct_bomex18000.npy differ diff --git a/data/wz_ct_bomex19800.npy b/data/wz_ct_bomex19800.npy new file mode 100644 index 0000000..bf1ab57 Binary files /dev/null and b/data/wz_ct_bomex19800.npy differ diff --git a/data/wz_ct_bomex21600.npy b/data/wz_ct_bomex21600.npy new file mode 100644 index 0000000..534bce3 Binary files /dev/null and b/data/wz_ct_bomex21600.npy differ diff --git a/data/wz_ct_bomex23400.npy b/data/wz_ct_bomex23400.npy new file mode 100644 index 0000000..416c90f Binary files /dev/null and b/data/wz_ct_bomex23400.npy differ diff --git a/data/wz_ct_bomex25200.npy b/data/wz_ct_bomex25200.npy new file mode 100644 index 0000000..b7e85d5 Binary files /dev/null and b/data/wz_ct_bomex25200.npy differ diff --git a/data/wz_ct_bomex27000.npy b/data/wz_ct_bomex27000.npy new file mode 100644 index 0000000..233878b Binary files /dev/null and b/data/wz_ct_bomex27000.npy differ diff --git a/data/wz_ct_bomex28800.npy b/data/wz_ct_bomex28800.npy new file mode 100644 index 0000000..cba93cb Binary files /dev/null and b/data/wz_ct_bomex28800.npy differ diff --git a/data/wz_ct_bomex30600.npy b/data/wz_ct_bomex30600.npy new file mode 100644 index 0000000..975ccdd Binary files /dev/null and b/data/wz_ct_bomex30600.npy differ diff --git a/data/wz_ct_bomex32400.npy b/data/wz_ct_bomex32400.npy new file mode 100644 index 0000000..1c6443d Binary files /dev/null and b/data/wz_ct_bomex32400.npy differ diff --git a/data/wz_ct_bomex34200.npy b/data/wz_ct_bomex34200.npy new file mode 100644 index 0000000..687e865 Binary files /dev/null and b/data/wz_ct_bomex34200.npy differ diff --git a/data/wz_ct_bomex36000.npy b/data/wz_ct_bomex36000.npy new file mode 100644 index 0000000..712f3d0 Binary files /dev/null and b/data/wz_ct_bomex36000.npy differ diff --git a/data/wz_ct_rico201600.npy b/data/wz_ct_rico201600.npy new file mode 100644 index 0000000..9528648 Binary files /dev/null and b/data/wz_ct_rico201600.npy differ diff --git a/data/wz_ct_rico82800.npy b/data/wz_ct_rico82800.npy new file mode 100644 index 0000000..ad0e167 Binary files /dev/null and b/data/wz_ct_rico82800.npy differ diff --git a/data/wz_max_arm28800.npy b/data/wz_max_arm28800.npy new file mode 100644 index 0000000..e84aed6 Binary files /dev/null and b/data/wz_max_arm28800.npy differ diff --git a/data/wz_max_arm41400.npy b/data/wz_max_arm41400.npy new file mode 100644 index 0000000..c6be5c6 Binary files /dev/null and b/data/wz_max_arm41400.npy differ diff --git a/data/wz_max_bomex10800.npy b/data/wz_max_bomex10800.npy new file mode 100644 index 0000000..f9b1a3d Binary files /dev/null and b/data/wz_max_bomex10800.npy differ diff --git a/data/wz_max_bomex12600.npy b/data/wz_max_bomex12600.npy new file mode 100644 index 0000000..11a26f5 Binary files /dev/null and b/data/wz_max_bomex12600.npy differ diff --git a/data/wz_max_bomex14400.npy b/data/wz_max_bomex14400.npy new file mode 100644 index 0000000..16bf711 Binary files /dev/null and b/data/wz_max_bomex14400.npy differ diff --git a/data/wz_max_bomex16200.npy b/data/wz_max_bomex16200.npy new file mode 100644 index 0000000..e43d976 Binary files /dev/null and b/data/wz_max_bomex16200.npy differ diff --git a/data/wz_max_bomex18000.npy b/data/wz_max_bomex18000.npy new file mode 100644 index 0000000..739a044 Binary files /dev/null and b/data/wz_max_bomex18000.npy differ diff --git a/data/wz_max_bomex19800.npy b/data/wz_max_bomex19800.npy new file mode 100644 index 0000000..2b2f7ae Binary files /dev/null and b/data/wz_max_bomex19800.npy differ diff --git a/data/wz_max_bomex21600.npy b/data/wz_max_bomex21600.npy new file mode 100644 index 0000000..5b622e9 Binary files /dev/null and b/data/wz_max_bomex21600.npy differ diff --git a/data/wz_max_bomex23400.npy b/data/wz_max_bomex23400.npy new file mode 100644 index 0000000..ef68e32 Binary files /dev/null and b/data/wz_max_bomex23400.npy differ diff --git a/data/wz_max_bomex25200.npy b/data/wz_max_bomex25200.npy new file mode 100644 index 0000000..a93dd74 Binary files /dev/null and b/data/wz_max_bomex25200.npy differ diff --git a/data/wz_max_bomex27000.npy b/data/wz_max_bomex27000.npy new file mode 100644 index 0000000..31489dc Binary files /dev/null and b/data/wz_max_bomex27000.npy differ diff --git a/data/wz_max_bomex28800.npy b/data/wz_max_bomex28800.npy new file mode 100644 index 0000000..ee387ea Binary files /dev/null and b/data/wz_max_bomex28800.npy differ diff --git a/data/wz_max_bomex30600.npy b/data/wz_max_bomex30600.npy new file mode 100644 index 0000000..dcd7313 Binary files /dev/null and b/data/wz_max_bomex30600.npy differ diff --git a/data/wz_max_bomex32400.npy b/data/wz_max_bomex32400.npy new file mode 100644 index 0000000..03cb147 Binary files /dev/null and b/data/wz_max_bomex32400.npy differ diff --git a/data/wz_max_bomex34200.npy b/data/wz_max_bomex34200.npy new file mode 100644 index 0000000..2d20193 Binary files /dev/null and b/data/wz_max_bomex34200.npy differ diff --git a/data/wz_max_bomex36000.npy b/data/wz_max_bomex36000.npy new file mode 100644 index 0000000..b2e86f9 Binary files /dev/null and b/data/wz_max_bomex36000.npy differ diff --git a/data/wz_max_rico201600.npy b/data/wz_max_rico201600.npy new file mode 100644 index 0000000..43a80c0 Binary files /dev/null and b/data/wz_max_rico201600.npy differ diff --git a/data/wz_max_rico82800.npy b/data/wz_max_rico82800.npy new file mode 100644 index 0000000..b920481 Binary files /dev/null and b/data/wz_max_rico82800.npy differ diff --git a/data/wz_min_arm28800.npy b/data/wz_min_arm28800.npy new file mode 100644 index 0000000..6e30c6a Binary files /dev/null and b/data/wz_min_arm28800.npy differ diff --git a/data/wz_min_arm41400.npy b/data/wz_min_arm41400.npy new file mode 100644 index 0000000..530652a Binary files /dev/null and b/data/wz_min_arm41400.npy differ diff --git a/data/wz_min_bomex10800.npy b/data/wz_min_bomex10800.npy new file mode 100644 index 0000000..1effd62 Binary files /dev/null and b/data/wz_min_bomex10800.npy differ diff --git a/data/wz_min_bomex12600.npy b/data/wz_min_bomex12600.npy new file mode 100644 index 0000000..793c9a2 Binary files /dev/null and b/data/wz_min_bomex12600.npy differ diff --git a/data/wz_min_bomex14400.npy b/data/wz_min_bomex14400.npy new file mode 100644 index 0000000..3758080 Binary files /dev/null and b/data/wz_min_bomex14400.npy differ diff --git a/data/wz_min_bomex16200.npy b/data/wz_min_bomex16200.npy new file mode 100644 index 0000000..61fc050 Binary files /dev/null and b/data/wz_min_bomex16200.npy differ diff --git a/data/wz_min_bomex18000.npy b/data/wz_min_bomex18000.npy new file mode 100644 index 0000000..955b1d1 Binary files /dev/null and b/data/wz_min_bomex18000.npy differ diff --git a/data/wz_min_bomex19800.npy b/data/wz_min_bomex19800.npy new file mode 100644 index 0000000..e734a1e Binary files /dev/null and b/data/wz_min_bomex19800.npy differ diff --git a/data/wz_min_bomex21600.npy b/data/wz_min_bomex21600.npy new file mode 100644 index 0000000..ee03075 Binary files /dev/null and b/data/wz_min_bomex21600.npy differ diff --git a/data/wz_min_bomex23400.npy b/data/wz_min_bomex23400.npy new file mode 100644 index 0000000..cbfd65e Binary files /dev/null and b/data/wz_min_bomex23400.npy differ diff --git a/data/wz_min_bomex25200.npy b/data/wz_min_bomex25200.npy new file mode 100644 index 0000000..fbaf507 Binary files /dev/null and b/data/wz_min_bomex25200.npy differ diff --git a/data/wz_min_bomex27000.npy b/data/wz_min_bomex27000.npy new file mode 100644 index 0000000..f8c1807 Binary files /dev/null and b/data/wz_min_bomex27000.npy differ diff --git a/data/wz_min_bomex28800.npy b/data/wz_min_bomex28800.npy new file mode 100644 index 0000000..5f3a692 Binary files /dev/null and b/data/wz_min_bomex28800.npy differ diff --git a/data/wz_min_bomex30600.npy b/data/wz_min_bomex30600.npy new file mode 100644 index 0000000..9461bc0 Binary files /dev/null and b/data/wz_min_bomex30600.npy differ diff --git a/data/wz_min_bomex32400.npy b/data/wz_min_bomex32400.npy new file mode 100644 index 0000000..06a8ec9 Binary files /dev/null and b/data/wz_min_bomex32400.npy differ diff --git a/data/wz_min_bomex34200.npy b/data/wz_min_bomex34200.npy new file mode 100644 index 0000000..b0a3a8e Binary files /dev/null and b/data/wz_min_bomex34200.npy differ diff --git a/data/wz_min_bomex36000.npy b/data/wz_min_bomex36000.npy new file mode 100644 index 0000000..c0b1f87 Binary files /dev/null and b/data/wz_min_bomex36000.npy differ diff --git a/data/wz_min_rico201600.npy b/data/wz_min_rico201600.npy new file mode 100644 index 0000000..38728e8 Binary files /dev/null and b/data/wz_min_rico201600.npy differ diff --git a/data/wz_min_rico82800.npy b/data/wz_min_rico82800.npy new file mode 100644 index 0000000..7649eea Binary files /dev/null and b/data/wz_min_rico82800.npy differ diff --git a/scripts/Cloud_Cover1.py b/scripts/Cloud_Cover1.py new file mode 100644 index 0000000..30008ff --- /dev/null +++ b/scripts/Cloud_Cover1.py @@ -0,0 +1,390 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon May 13 10:37:38 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +import matplotlib.colors as colors +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + +####################################################### + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + + +################################################ +start=time.time() + + + +### rico828 +""" +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_rico82800.npy') +shearTB = np.load('shearTB_rico82800.npy') +shear_sum = np.load('shear_sum_rico82800.npy') +""" +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +wavg1 = np.load('wavg1_rico201600.npy') +shearTB = np.load('shearTB_rico201600.npy') +shear_sum = np.load('shear_sum_rico201600.npy') +""" + +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +""" +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" +""" +### arm28800 + +height=np.load('height_no_shear_arm28800.npy') +volume=np.load('volume_no_shear_arm28800.npy') +projar=np.load('projarea_no_shear_arm28800.npy') +overlap=np.load('overlap_no_shear_arm28800.npy') +areaz=np.load('area_z_ratio_arm28800.npy') +overlap_convex=np.load('overlap_convex_arm28800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm28800.npy') +shearTB = np.load('shearTB_vel_arm28800.npy') +shear_sum = np.load('shear_sum_arm28800.npy') +""" + +### arm41400 + +height=np.load('height_no_shear_arm41400.npy') +volume=np.load('volume_no_shear_arm41400.npy') +projar=np.load('projarea_no_shear_arm41400.npy') +overlap=np.load('overlap_no_shear_arm41400.npy') +areaz=np.load('area_z_ratio_arm41400.npy') +overlap_convex=np.load('overlap_convex_arm41400.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm41400.npy') +shearTB = np.load('shearTB_vel_arm41400.npy') +shear_sum = np.load('shear_sum_arm41400.npy') + +### Bomex_All is Below + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = Afilenames[10:11] +Bfilenames = Afilenames[17:18] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + """ + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + """ + + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + """ + ### upper bound to turb + lam = np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + keep=np.argwhere(fractalf >1.5*lam-1) + fractalf[np.array(keep)]=1.5*lam-1 + """ + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + + #f_t=f_turb(ht,175); f_t[ht<=100]=0 + #f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + #f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_total = f_t + f_s + f_a +1 + + cv_sorted=np.sort(cv) + cv_arg=np.argsort(cv) + r_sorted=np.zeros(cv.size) + act_sorted=np.zeros(cv.size) + count=-1 + for i in cv_arg: + count= count+1 + r_sorted[count]=r_total[i] + act_sorted[count]=1/overlap_ratio[i] + """ + plt.figure() + plt.plot(cv,r_total,'o') + plt.ylim([0,12]) + #plt.fill(cv,r_total,'b') + plt.figure() + plt.plot(cv,1/overlap_ratio,'o') + plt.ylim([0,12]) + """ + """ + horizontal= cv + vertical= 1/overlap_ratio + + + bins=1*dz; + + plt.figure(); + HIST2dA=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis'); #norm=colors.LogNorm() + + plt.title('Cloud Cover'); + + + plt.xlabel('C_v') + plt.ylabel('Actual Overlap') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + p_act=(sum(HIST2dA[1]*HIST2dA[2])) + + ##### + horizontal= cv + vertical= r_total + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis'); #norm=colors.LogNorm() + + plt.title('Cloud Cover'); + + + plt.xlabel('C_v') + plt.ylabel('Calculated Overlap') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + p_tot=(sum(HIST2dC[1]*HIST2dC[2])) + + + print('Calculated:', p_tot, 'Actual:',p_act) + + #per_err= (abs(p_tot - p_act) / p_act)*100 + #print(per_err) + + perr=(p_tot / p_act) *100 + print(perr) + """ + ######## + #p_tot_trap=np.trapz(r_sorted,cv_sorted) + #p_act_trap=np.trapz(act_sorted,cv_sorted) + #print('Calculated:', p_tot_trap, 'Actual:',p_act_trap) + #### total cld cover + p_tot_num=sum(r_total*cv) + p_act_num=sum(1/overlap_ratio * cv) + print('Calculated:', p_tot_num, 'Actual:',p_act_num) + + + + #per_err= (abs(p_tot_trap - p_act_trap) / p_act_trap)*100 + #print(per_err) + + #perr=(p_tot_trap / p_act_trap) *100 + #print(perr) + + #per_err= (abs(p_tot_num - p_act_num) / p_act_num)*100 + #print(per_err) + + perr=(p_tot_num / p_act_num) *100 + print('percent of cld cover explained: ',perr) + """ + plt.figure() + horizontal= ht + vertical= r_total*cv + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis',norm=colors.LogNorm()); #norm=colors.LogNorm() + + plt.title('Cloud Cover'); + + + plt.xlabel('Cloud Height') + plt.ylabel('Cloud Cover') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + #plt.clim(0,200) + """ + + + plt.figure() + horizontal= r_total*cv + vertical= cp + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis',norm=colors.LogNorm()); #norm=colors.LogNorm() + plt.plot(horizontal,horizontal,'k', linewidth=3) + plt.title('Cloud Cover'); + + + plt.xlabel('Calculated Cloud Cover') + plt.ylabel('Actual Cloud Cover') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + #plt.clim(0,200) + + #plt.savefig('arm41400_cloud_cover_061119.eps', dpi=300, bbox_inches='tight') + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) diff --git a/scripts/Cloud_Cover2.py b/scripts/Cloud_Cover2.py new file mode 100644 index 0000000..aed4511 --- /dev/null +++ b/scripts/Cloud_Cover2.py @@ -0,0 +1,346 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jun 19 13:16:04 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +import matplotlib.colors as colors +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + +####################################################### + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + + +################################################ +start=time.time() + + + + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +Afilenames2 = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +Afilenames0 = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames0[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames1 = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = Afilenames[10:11] +#Bfilenames = Afilenames[17:18] +Cfilenames0 = [Afilenames0[22:23] , Afilenames0[55:56], Afilenames1[10:11], Afilenames1[17:18], Afilenames2[5:6]] + +#Zfilenames = [Afilenames0,Afilenames1,Afilenames2] + +m0=-1 + +for file1 in Cfilenames0: + m0=m0+1 + file1=file1[0] + print(file1) + + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + if m0 == 0: + height=np.load('height_no_shear_rico828.npy') + volume=np.load('volume_no_shear_rico828.npy') + projar=np.load('projarea_no_shear_rico828.npy') + overlap=np.load('overlap_no_shear_rico828.npy') + areaz=np.load('area_z_ratio_rico828.npy') + areazg=np.load('rico_area_gmean82800.npy') + overlap_convex=np.load('overlap_convex_rico82800.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_rico82800.npy') + shearTB = np.load('shearTB_rico82800.npy') + shear_sum = np.load('shear_sum_rico82800.npy') + wz_max = np.load('wz_max_rico82800.npy') + wz_cb = np.load('wz_cb_rico82800.npy') + shift_distance = np.load('shift_distancerico82800.npy') + cmin=3 + + elif m0==1: + height=np.load('height_no_shear_rico2016.npy') + volume=np.load('volume_no_shear_rico2016.npy') + projar=np.load('projarea_no_shear_rico2016.npy') + overlap=np.load('overlap_no_shear_rico2016.npy') + areaz=np.load('area_z_ratio_rico2016.npy') + model=np.load('model_rico2016.npy') + model_inv=np.load('model_inv_rico2016.npy') + model_opt=np.load('model_opt_rico2016.npy') + model_opt2=np.load('model_opt2_rico2016.npy') + overlap_convex=np.load('overlap_convex_rico201600.npy') + wavg1 = np.load('wavg1_rico201600.npy') + shearTB = np.load('shearTB_rico201600.npy') + shear_sum = np.load('shear_sum_rico201600.npy') + shift_distance = np.load('shift_distancerico201600.npy') + cmin=3 + + elif m0 ==2: + height=np.load('height_no_shear_arm28800.npy') + volume=np.load('volume_no_shear_arm28800.npy') + projar=np.load('projarea_no_shear_arm28800.npy') + overlap=np.load('overlap_no_shear_arm28800.npy') + areaz=np.load('area_z_ratio_arm28800.npy') + overlap_convex=np.load('overlap_convex_arm28800.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_arm28800.npy') + shearTB = np.load('shearTB_vel_arm28800.npy') + shear_sum = np.load('shear_sum_arm28800.npy') + shift_distance = np.load('shift_distancearm28800.npy') + cmin=3 + + elif m0==3: + height=np.load('height_no_shear_arm41400.npy') + volume=np.load('volume_no_shear_arm41400.npy') + projar=np.load('projarea_no_shear_arm41400.npy') + overlap=np.load('overlap_no_shear_arm41400.npy') + areaz=np.load('area_z_ratio_arm41400.npy') + overlap_convex=np.load('overlap_convex_arm41400.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_arm41400.npy') + shearTB = np.load('shearTB_vel_arm41400.npy') + shear_sum = np.load('shear_sum_arm41400.npy') + shift_distance = np.load('shift_distancearm41400.npy') + cmin=3 + + elif m0==4: + ### Bomex_All + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + overlap_convex=np.load('Bomex_hull.npy') + #shearh_vel = np.load('Bomex_shearh_vel.npy') + #sheara_vel = np.load('Bomex_sheara_vel.npy') + #wavg = np.load('Bomex_wavg.npy') + shearTB = np.load('Bomex_shearTB.npy') + shear_sum = np.load('Bomex_shear_sum.npy') + wz_max = np.load('Bomex_wz_max.npy') + wz_cb = np.load('Bomex_wz_cb.npy') + shift_distance = np.load('Bomex_shift_distance.npy') + cmin=5 + print('Bomex') + + + """ + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + """ + + #fract= (5*np.pi) / (6*np.sqrt(3)) -1 + #fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + #fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + fractalf = np.zeros(ht.size) + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + """ + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + """ + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + + #f_t=f_turb(ht,175); f_t[ht<=100]=0 + #f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + #f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_total = f_t + f_s + f_a +1 + + cv_sorted=np.sort(cv) + cv_arg=np.argsort(cv) + r_sorted=np.zeros(cv.size) + act_sorted=np.zeros(cv.size) + count=-1 + for i in cv_arg: + count= count+1 + r_sorted[count]=r_total[i] + act_sorted[count]=1/overlap_ratio[i] + + + ######## + #p_tot_trap=np.trapz(r_sorted,cv_sorted) + #p_act_trap=np.trapz(act_sorted,cv_sorted) + #print('Calculated:', p_tot_trap, 'Actual:',p_act_trap) + #### total cld cover + p_tot_num=sum(r_total*cv) + p_act_num=sum(1/overlap_ratio * cv) + print('Calculated:', p_tot_num, 'Actual:',p_act_num) + + + + #per_err= (abs(p_tot_trap - p_act_trap) / p_act_trap)*100 + #print(per_err) + + #perr=(p_tot_trap / p_act_trap) *100 + #print(perr) + + #per_err= (abs(p_tot_num - p_act_num) / p_act_num)*100 + #print(per_err) + + perr=(p_tot_num / p_act_num) *100 + print('percent of cld cover explained: ',perr) + + + + plt.figure() + horizontal= (r_total)*cv + vertical= cp + + ## normalizing + max_cp = max(cp) + horizontal = horizontal / max_cp + vertical = vertical / max_cp + + plt.figure(); + HIST2dC=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=1,cmap='viridis',norm=colors.LogNorm()); #norm=colors.LogNorm() + plt.plot(horizontal,horizontal,'k', linewidth=3) + plt.title('Normalized Cloud Cover'); + + + plt.xlabel('Normalized Calculated Cloud Cover') + plt.ylabel('Normalized Actual Cloud Cover') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + #plt.clim(0,200) + + if m0==4: ### bomex + plt.clim(1,10**4) + #plt.xlim([0,10]) + #plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + #plt.xlim([0,8]) + #plt.ylim([0,8]) + + """ + if m0==0: + plt.savefig('rico82800_cld_cover_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_cld_cover_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_cld_cover_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_cld_cover_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_cld_cover_061919.eps', dpi=300,bbox_inches='tight') + """ + + #plt.savefig('arm41400_cloud_cover_061119.eps', dpi=300, bbox_inches='tight') + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + diff --git a/scripts/Read_Me_1 b/scripts/Read_Me_1 new file mode 100644 index 0000000..b6eeb1c --- /dev/null +++ b/scripts/Read_Me_1 @@ -0,0 +1,52 @@ +%%%%% Python Scripts with brief description by anthony sulak + +generate_data1: generates and saves data for overlap due to shear, area var., and turbulence +(note: this script is a combination of "shear_center_of_mass1.py" and "convexhull1.py") +added shear_cal1.py (older method for updraft) +added shift_cld1.py to this script so updraft can be calculated +NOTE: overlap is computed C_v/C_p in script and inverted for usage + +shift_cld1.py: calculates "shift distance" so that we can calculate the updraft speed using wind differential, cld ht, and shift distance (this method should be used to calculate updraft and not any other method) + +tempfile1.py: plots more important graphs (e.g. 2d histograms of overlap...) + +cal_factors2.py: calculates the contribution of each factor based on cld height; plots stacked bar graph + +shear_cal1.npy: generates and saves updraft and wind differentials (older method for updraft) + +convexhull1.py: generates and saves overlap due to convex hull clds with ht >100m + +Cloud_Cover1.py: plots cld cover graphs + +areaz_with_median1.py: generates and saves overlap due to area variability using geo mean + +check1.py: used to concatenate data (namely for bomex) + +shear_center_of_mass1.py: generates and saves the overlap due to shear and overlap due to area var. + +overlap_width_cv.py: calculates shear (in conjuction w/ analytical model) + +percentcloud2.py: calculates overlap, vol, proj area, ht of chopped clouds; plots overlap of clds with diff chopped hts + +graph3d_2.py: graphs a particular cld either in 3d of 2d + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Description of npy files: +(notice overlap calculations from scripts are C_v / C_p) +overlap_no_shear_dataset*.npy: overlap of shifted cld, for all clds +area_z_ratio_dataset*.npy: avg area over max area, for all clds +overlap_convex_dataset8.npy: overlap of convex hull cld, for clds ht>100m +shear_sum_dataset*.npy: sum of gradients of a cld, for all +shearTB_vel_dataset*.npy: difference of shear at top and bottom of cld, for all clds +shift_distance dataset8.npy: distance cld is shifted to align center of masses, for clds ht>50m + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Note: there is a collection of npy files (gen. data) that are loaded in some of the above mention python scripts + +Note: Some scripts that generate data or calculates multiples thing (such as percentcloud2.py) may take awhile to run depending on the # of clds + +Files gen. data -> npy files -> Files that use npy files (for plotting, calculations) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +other files: older scripts are less useful or practice scripts diff --git a/scripts/areaz_with_median1.py b/scripts/areaz_with_median1.py new file mode 100644 index 0000000..aa58e74 --- /dev/null +++ b/scripts/areaz_with_median1.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu May 9 12:24:46 2019 + +@author: anthonys +""" + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + +################################################ +start=time.time() + + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +begin=5 +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] + +file1numb=begin-1 + + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + alpha=np.arange(1,0,-1) # just 1 + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + m=-1 + for e1 in cloud_numb: + m=m+1 + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + base=np.amin(location[0]);top=np.amax(location[0]); + layers=(top - base + 1) # layers of cloud along z + cross_area_z=np.zeros(int(layers)) + + + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + + + area_z_ratio[m]= gmean(cross_area_z) / np.amax(cross_area_z) + + step=1800 # 30*60 + time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/bomex_area_gmean" + #step=3600 # 60*60 + #time_array= np.arange(10800,216000+step,step) + #npyfilespath ="/home/anthonys/Documents/rico_area_gmean" + ### becarful here + #np.save(npyfilespath+str(time_array[file1_numb])+'.npy',area_z_ratio) + + #np.save(npyfilespath+str(time_array[20])+'.npy',area_z_ratio) + ### need to fix time_array and saving + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + diff --git a/scripts/cal_factors2.py b/scripts/cal_factors2.py new file mode 100644 index 0000000..bf779ef --- /dev/null +++ b/scripts/cal_factors2.py @@ -0,0 +1,688 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Apr 29 16:40:13 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + + +import plotly.plotly as py +import plotly.graph_objs as go + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +#ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + +lassotrack306 = Dataset('/data/lasso/sims/20160611_micro/l.0030600.track.nc','r') + +""" +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] +""" +########################################################################### +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 +################################################################################# + +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack360] +armfilenames=[armtrack522] +lassofilenames=[lassotrack306] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + + +""" +### rico828 + +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_rico82800.npy') +shearTB = np.load('shearTB_rico82800.npy') +shear_sum = np.load('shear_sum_rico82800.npy') +wz_max = np.load('wz_max_rico82800.npy') +wz_cb = np.load('wz_cb_rico82800.npy') +shift_distance = np.load('shift_distancerico82800.npy') +""" +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +wavg1 = np.load('wavg1_rico201600.npy') +shearTB = np.load('shearTB_rico201600.npy') +shear_sum = np.load('shear_sum_rico201600.npy') +shift_distance = np.load('shift_distancerico201600.npy') +""" +""" +### bomex 342 +height342=np.load('height_no_shear_bomex34200.npy') +volume342=np.load('volume_no_shear_bomex34200.npy') +projar342=np.load('projarea_no_shear_bomex34200.npy') +overlap342=np.load('overlap_no_shear_bomex34200.npy') +areaz342=np.load('area_z_ratio_bomex34200.npy') + +### bomex 360 +height=np.load('height_no_shear_bomex36000.npy') +volume=np.load('volume_no_shear_bomex36000.npy') +projar=np.load('projarea_no_shear_bomex36000.npy') +overlap=np.load('overlap_no_shear_bomex36000.npy') +areaz=np.load('area_z_ratio_bomex36000.npy') + +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" + +### arm28800 + +height=np.load('height_no_shear_arm28800.npy') +volume=np.load('volume_no_shear_arm28800.npy') +projar=np.load('projarea_no_shear_arm28800.npy') +overlap=np.load('overlap_no_shear_arm28800.npy') +areaz=np.load('area_z_ratio_arm28800.npy') +overlap_convex=np.load('overlap_convex_arm28800.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm28800.npy') +shearTB = np.load('shearTB_vel_arm28800.npy') +shear_sum = np.load('shear_sum_arm28800.npy') +shift_distance = np.load('shift_distancearm28800.npy') + +""" +### arm41400 + +height=np.load('height_no_shear_arm41400.npy') +volume=np.load('volume_no_shear_arm41400.npy') +projar=np.load('projarea_no_shear_arm41400.npy') +overlap=np.load('overlap_no_shear_arm41400.npy') +areaz=np.load('area_z_ratio_arm41400.npy') +overlap_convex=np.load('overlap_convex_arm41400.npy') +#shearh_vel = np.load('rico82800_shearh_vel.npy') +#sheara_vel = np.load('rico82800_sheara_vel.npy') +#wavg = np.load('rico82800_wavg.npy') +#shearTB_vel = np.load('rico82800_shearTB_vel.npy') +wavg1 = np.load('wavg1_arm41400.npy') +shearTB = np.load('shearTB_vel_arm41400.npy') +shear_sum = np.load('shear_sum_arm41400.npy') +shift_distance = np.load('shift_distancearm41400.npy') +""" +### Bomex_All is Below + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +Bfilenames = Afilenames[10:11] +#Bfilenames = Afilenames[17:18] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + """ + ### Bomex_All + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + overlap_convex=np.load('Bomex_hull.npy') + #shearh_vel = np.load('Bomex_shearh_vel.npy') + #sheara_vel = np.load('Bomex_sheara_vel.npy') + #wavg = np.load('Bomex_wavg.npy') + shearTB = np.load('Bomex_shearTB.npy') + shear_sum = np.load('Bomex_shear_sum.npy') + wz_max = np.load('Bomex_wz_max.npy') + wz_cb = np.load('Bomex_wz_cb.npy') + shift_distance = np.load('Bomex_shift_distance.npy') + print('Bomex') + """ + + + + binsize=100 + condition_vec= np.arange(binsize,max(ht)+binsize,binsize) #, 500, 100, 50] # to go through multiple conditions quickly + h_shear = np.zeros(condition_vec.size) + h_shape = np.zeros(condition_vec.size) + h_turb = np.zeros(condition_vec.size) + h_ACT = np.zeros(condition_vec.size) + h_RES = np.zeros(condition_vec.size) + h_total = np.zeros(condition_vec.size) + m=-1 + + + ##### loop over bin hts + for conditional_height in condition_vec: + + m=m+1 + #conditional_height=1500 + index=np.where( (conditional_height-binsize < ht) & (ht <= conditional_height) ) # indices of where condition holds true in ht vector + index_size=index[0].size + ht_sel=ht[index[0]] # taking the ht values according to indices above + overlap_ratio_sel=overlap_ratio[index[0]]; + #area_proj_sel=area_proj[index[0]] + + + """ + print('Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_size) + """ + ######################################## + + #areaz=areazg + + + ############################################################ + ###### calculating overlap due to contributors + l=cv**0.5 + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + #shear = abs(shear) + shear[shear<0]=0 + + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + + + FF = f_turb(ht,200);FF[ht<=100]=0; + shear_sum = abs(shear_sum) + shift_d = np.zeros(ht.size) + shift_d[ht>50] = shift_distance + + shift_d = shift_d + shape*cp**0.5/2 ### draw the picture + updraft = (shear_sum*ht)/shift_d + FS = (shear_sum*ht)/(updraft*cp**0.5) + FS[updraft<0.1] = 0 + #FS[updraft<0.01] = 0 + + #shear = FS ; fractalf = FF + + #r_shear= 1/overlap_ratio[index[0]] - 1/overlap[index[0]] # index variables with index_greater[0] + #r_shear[r_shear<0]=0 + r_shear=shear[index[0]] + r_area=1/areaz[index[0]] -1 + #r_turb= (np.ones(index_size)*fractal) -1 + r_turb = fractalf[index[0]] + actual = 1/overlap_ratio[index[0]] + + #r_total = ( r_shear + r_area + r_turb ) +1 + + ######## + + #### empirical model + #f_t=f_turb(ht,200); f_t[ht<=100]=0 + #f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + #f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_shear=f_s[index[0]] + #r_area=f_a[index[0]] + #r_turb=f_t[index[0]] + + + r_total = ( r_shear + r_area + r_turb ) +1 + + + ######## + + residual = actual - r_total + #residual[residual<0]=0 + ####### binning data + """ + S=((r_shear-1)/r_total) + A=((r_area-1)/r_total) + T=((r_turb-1)/r_total) + """ + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + ACT_avg=np.mean(actual) + ACT_std=np.std(actual) + RES_avg=np.mean(residual) + RES_std=np.std(residual) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + h_shear[m]=S3_avg + h_shape[m]=A3_avg + h_turb[m]=T3_avg + h_ACT[m]=ACT_avg + h_RES[m]=RES_avg + h_total[m] = r3_avg + """ + print('average r is %.2f' % r3_avg, ', r std is %.2f' % r3_std) + print('average r_shear is %.2f' % S3_avg, ', r_shear std is %.2f' % S3_std) + print('average r_area percentage is %.2f' % A3_avg, ', r_area std is %.2f' % A3_std) + print('average r_turbulence percentage is %.2f' % T3_avg, ', r_turbulence std is %.2f' % T3_std) + """ + + + ###################################################### + + + + + + + +""" +h_shear=np.nan_to_num(h_shear) +h_shape=np.nan_to_num(h_shape) +h_turb=np.nan_to_num(h_turb) +h_ACT=np.nan_to_num(h_ACT) +h_RES=np.nan_to_num(h_RES) +""" +h_ACT=h_ACT -1 +h_ACT[h_ACT<0]=0 +########################################################################################## +###### stacked bar graph +#h_turb=f_turb(ht_bin,opt_t) +## change variable +h_total = h_shape + h_shear +h_turb + + +N= int(condition_vec.size) + +#N=np.count_nonzero(~np.isnan(h_shear)) + +ind = np.arange(N) # the x locations for the groups +width = 0.8 #1/N # the width of the bars: can also be len(x) sequence +width = 90 +ind=ind*100 +100 +arg_nan=np.argwhere(np.isnan(h_shape)) +#ind=ind[~np.isnan(h_shear)] +#N=ind.size +ind = ind.astype('float') +ind[arg_nan] = np.nan +""" +ind=ind[~np.isnan(ind)] +h_shear=h_shear[~np.isnan(h_shear)] +h_shape=h_shape[~np.isnan(h_shape)] +h_turb=h_turb[~np.isnan(h_turb)] +h_ACT = h_ACT[~np.isnan(h_ACT)] +""" +bottom2=np.zeros(ind.size) +bottom3=np.zeros(ind.size) +for i in range(ind.size): + #i = int(i/100 - 1) + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +#ind=ind[~np.isnan(ind)] +#h_shear=h_shear[~np.isnan(h_shear)] +#h_shape=h_shape[~np.isnan(h_shape)] +#h_turb=h_turb[~np.isnan(h_turb)] + +""" +mystring = [] +for digit in ind: + mystring.append(digit) +ind = np.arange(100,100*ind.size+100,100) +""" +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Height') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind,mystring) +#plt.xticks(ind[0:1],condition_vec[0:1]) +#plt.xticks([0 , 9 , 19 ], ('100', '1000', '2000' ) ) +plt.yticks(np.arange(0, 20, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) + + +pa=plt.plot(ind,h_ACT,'ko',linewidth=2) + +plt.legend((p1[0], p2[0],p3[0],pa[0]), ('Turbulence','Shear', 'Area Variability','Actual Overlap'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +#plt.savefig('arm28800_factor_average1_emp1_061719.eps', dpi=300, bbox_inches='tight') + + +############################################################ +#### makes table of fraction of factor, put it in matrix form +print('Area', '\t', 'Shear', '\t' ,'Turbulence') +h_1=h_shape/h_total +h_2=h_shear/h_total +h_3=h_turb/h_total + +for j in range(h_ACT.size): + print( '%.3f' %h_1[j],'\t', '%.3f '%h_2[j], '\t', '%.3f' %h_3[j] ) + +print('average percentages (%.3f , %.3f , %.3f)' %(np.nanmean(h_1), np.nanmean(h_2), np.nanmean(h_3))) + +h_matrix = np.array([[h_1],[h_2],[h_3]]) +h_matrix2 = np.zeros((h_1.size,4)) +h_matrix2[:,0] = np.round(ind,3) +h_matrix2[:,1] = np.round(h_1,3) +h_matrix2[:,2] = np.round(h_2,3) +h_matrix2[:,3] = np.round(h_3,3) +################################################################################### +################################################################################## +#### curve fit for turbulence + +ht_bin=ind*100 +100 +""" +Z=np.where(h_turb == 0) +h_turb=np.delete(h_turb,Z) +ht_bin=np.delete(ht_bin,Z) + + +opt_t, cov_t = curve_fit(f_turb , ht_bin[1:], h_turb[1:]) + +c=opt_t +model_turb=f_turb(ht,c) + + +bins=1*dz; + +plt.figure(); +plt.hist2d(ht,model_turb,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) + + +plt.title('Effect of Turbulence'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); + +plt.xlabel('ht') +plt.ylabel('Cal Overlap') +#plt.xlabel('Cloud Overlap') +#plt.ylabel('Cloud Height') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') + +########################################################## +""" + + + +""" +###################################################### +##replot stacked hist +plt.figure() +ht_bin=ind*100 +100 +h_turb=f_turb(ht_bin,c) + + +bottom2=np.zeros(N) +bottom3=np.zeros(N) +for i in range(N): + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Height') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind, '%' %[condition_vec]) +plt.xticks([0 , 9 , 19 ], ('100', '1000', '2000' ) ) +plt.yticks(np.arange(0, 8, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) +plt.legend((p1[0], p2[0],p3[0]), ('Turbulence','Shear', 'Area Variability'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +plt.plot(h_ACT,'ko-',linewidth=2) + +######################################################################################## +""" + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/cal_factors2_shear.py b/scripts/cal_factors2_shear.py new file mode 100644 index 0000000..ec181e0 --- /dev/null +++ b/scripts/cal_factors2_shear.py @@ -0,0 +1,475 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu May 23 16:47:58 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + +#################################### + +# script + +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + + + +### rico828 + +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') + +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +""" + +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +""" +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + l=cv**0.5 + + binsize=0.5 + condition_vec= np.arange(binsize,max(ht/l)+binsize,binsize) #, 500, 100, 50] # to go through multiple conditions quickly + h_shear = np.zeros(condition_vec.size) + h_shape = np.zeros(condition_vec.size) + h_turb = np.zeros(condition_vec.size) + h_ACT = np.zeros(condition_vec.size) + h_RES = np.zeros(condition_vec.size) + m=-1 + + + for conditional_height in condition_vec: + + m=m+1 + #conditional_height=1500 + index=np.where( (conditional_height-binsize < ht/l) & (ht/l <= conditional_height) ) # indices of where condition holds true in ht vector + index_size=index[0].size + ht_sel=ht[index[0]] # taking the ht values according to indices above + overlap_ratio_sel=overlap_ratio[index[0]]; + #area_proj_sel=area_proj[index[0]] + + + """ + print('Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_size) + """ + ######################################## + + #areaz=areazg + + + ############################################################ + + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + #fractalf = np.minimum(((3*np.pi) / 4)*np.ones(overlap_ratio.size),1/overlap_ratio) + + #fractalf = np.minimum( (3*np.pi /4)*np.ones(overlap_ratio.size), 1/overlap_ratio ) + #fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) + + + r_shear= 1/overlap_ratio[index[0]] - 1/overlap[index[0]] # index variables with index_greater[0] + r_shear[r_shear<0]=0 + r_area=1/areaz[index[0]] -1 + #r_turb= (np.ones(index_size)*fractal) -1 + r_turb = fractalf[index[0]] + actual = 1/overlap_ratio[index[0]] + + r_total = ( r_shear + r_area + r_turb ) +1 # correction: need to add 1 + + residual = actual - r_total + #residual[residual<0]=0 + + """ + S=((r_shear-1)/r_total) + A=((r_area-1)/r_total) + T=((r_turb-1)/r_total) + """ + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + ACT_avg=np.mean(actual) + ACT_std=np.std(actual) + RES_avg=np.mean(residual) + RES_std=np.std(residual) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + h_shear[m]=S3_avg + h_shape[m]=A3_avg + h_turb[m]=T3_avg + h_ACT[m]=ACT_avg + h_RES[m]=RES_avg + """ + print('average r is %.2f' % r3_avg, ', r std is %.2f' % r3_std) + print('average r_shear is %.2f' % S3_avg, ', r_shear std is %.2f' % S3_std) + print('average r_area percentage is %.2f' % A3_avg, ', r_area std is %.2f' % A3_std) + print('average r_turbulence percentage is %.2f' % T3_avg, ', r_turbulence std is %.2f' % T3_std) + """ + + + ###################################################### + + + + + + + + +h_shear=np.nan_to_num(h_shear) +h_shape=np.nan_to_num(h_shape) +h_turb=np.nan_to_num(h_turb) +h_ACT=np.nan_to_num(h_ACT) +h_RES=np.nan_to_num(h_RES) + +h_ACT=h_ACT -1 +h_ACT[h_ACT<0]=0 +########################################################################################## + + + +""" +h_shape= ( np.load('h_shape_rico828.npy') + np.load('h_shape_rico2016.npy') ) /2 +h_shear= ( np.load('h_shear_rico828.npy') + np.load('h_shear_rico2016.npy') ) /2 +h_turb= ( np.load('h_turb_rico828.npy') + np.load('h_turb_rico2016.npy') ) /2 +""" + +N= int(condition_vec.size) + +ind = np.arange(N) # the x locations for the groups +width = 0.8 #1/N # the width of the bars: can also be len(x) sequence + +bottom2=np.zeros(N) +bottom3=np.zeros(N) +for i in range(N): + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Aspect Ratio') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind, '%' %[condition_vec]) +plt.xticks([0 , 9 , 19 ], ('0.5', '5', '10' ) ) +plt.yticks(np.arange(0, 10, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) +plt.legend((p1[0], p2[0],p3[0]), ('Turbulence','Shear', 'Area Variability'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +plt.plot(h_ACT,'ko-',linewidth=2) + + +#plt.savefig('bomexAll_factor_average1_052219.eps', dpi=300, bbox_inches='tight') + +#ht_bin=ind*100 +100 +ht_bin=ind*0.5 +0.5 + +################################################################################### +################################################################################## +#### curve fit for shear + + +""" +Z=np.where(h_shear == 0) +h_shear=np.delete(h_shear,Z) +ht_bin=np.delete(ht_bin,Z) + + +opt_s, cov_s = curve_fit(f_shear , ht_bin[2:], h_shear[2:]) + +c=opt_s +model_shear=f_shear(ht/l,c) + + +bins=1*dz; + +plt.figure(); +plt.hist2d(ht/l,model_shear,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) + + +plt.title('Effect of Shear'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); + +plt.xlabel('aspect ratio') +plt.ylabel('Cal Overlap') +#plt.xlabel('Cloud Overlap') +#plt.ylabel('Cloud Height') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') +""" +########################################################## +################################################################################## +#### curve fit for area + + + +Z=np.where(h_shape == 0) +h_shape=np.delete(h_shape,Z) +ht_bin=np.delete(ht_bin,Z) + + +opt_a, cov_a = curve_fit(f_area , ht_bin[2:], h_shape[2:]) + +c=opt_a +model_shape=f_area(ht/l,c) + + +bins=1*dz; + +plt.figure(); +plt.hist2d(ht/l,model_shape,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) + + +plt.title('Effect of Area'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); + +plt.xlabel('aspect ratio') +plt.ylabel('Cal Overlap') +#plt.xlabel('Cloud Overlap') +#plt.ylabel('Cloud Height') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') + +########################################################## + + + +###################################################### +##replot stacked hist +plt.figure() +#ht_bin=ind*100 +100 +ht_bin=ind*0.5 +0.5 + +h_shape=f_area(ht_bin,c) +#h_shear=f_shear(ht_bin,c) + +bottom2=np.zeros(N) +bottom3=np.zeros(N) +for i in range(N): + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + +p1= plt.bar(ind,h_turb,width , color='pink') +p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') +p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) +#p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.xlabel('Cloud Aspect Ratio') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +#plt.xticks(ind, '%' %[condition_vec]) +plt.xticks([0 , 9 , 19 ], ('0.5', '5', '10' ) ) +plt.yticks(np.arange(0, 10, 1)) +#plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) +plt.legend((p1[0], p2[0],p3[0]), ('Turbulence','Shear', 'Area Variability'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + +plt.plot(h_ACT,'ko-',linewidth=2) + +######################################################################################## + + + + + + + + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + diff --git a/scripts/cal_factors3.py b/scripts/cal_factors3.py new file mode 100644 index 0000000..3c8ec48 --- /dev/null +++ b/scripts/cal_factors3.py @@ -0,0 +1,731 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jun 19 10:41:14 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + + +import plotly.plotly as py +import plotly.graph_objs as go + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +#ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + +lassotrack306 = Dataset('/data/lasso/sims/20160611_micro/l.0030600.track.nc','r') + +""" +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] +""" +########################################################################### +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 +################################################################################# + +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack360] +armfilenames=[armtrack522] +lassofilenames=[lassotrack306] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + + + +############################################# + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +Afilenames2 = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +Afilenames0 = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames0[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames1 = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = Afilenames[10:11] +#Bfilenames = Afilenames[17:18] +Cfilenames0 = [Afilenames0[22:23] , Afilenames0[55:56], Afilenames1[10:11], Afilenames1[17:18], Afilenames2[5:6]] + +#Zfilenames = [Afilenames0,Afilenames1,Afilenames2] + +m0=-1 + +for file1 in Cfilenames0: + m0=m0+1 + file1=file1[0] + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + if m0 == 0: + height=np.load('height_no_shear_rico828.npy') + volume=np.load('volume_no_shear_rico828.npy') + projar=np.load('projarea_no_shear_rico828.npy') + overlap=np.load('overlap_no_shear_rico828.npy') + areaz=np.load('area_z_ratio_rico828.npy') + areazg=np.load('rico_area_gmean82800.npy') + overlap_convex=np.load('overlap_convex_rico82800.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_rico82800.npy') + shearTB = np.load('shearTB_rico82800.npy') + shear_sum = np.load('shear_sum_rico82800.npy') + wz_max = np.load('wz_max_rico82800.npy') + wz_cb = np.load('wz_cb_rico82800.npy') + shift_distance = np.load('shift_distancerico82800.npy') + cmin=3 + + elif m0==1: + height=np.load('height_no_shear_rico2016.npy') + volume=np.load('volume_no_shear_rico2016.npy') + projar=np.load('projarea_no_shear_rico2016.npy') + overlap=np.load('overlap_no_shear_rico2016.npy') + areaz=np.load('area_z_ratio_rico2016.npy') + model=np.load('model_rico2016.npy') + model_inv=np.load('model_inv_rico2016.npy') + model_opt=np.load('model_opt_rico2016.npy') + model_opt2=np.load('model_opt2_rico2016.npy') + overlap_convex=np.load('overlap_convex_rico201600.npy') + wavg1 = np.load('wavg1_rico201600.npy') + shearTB = np.load('shearTB_rico201600.npy') + shear_sum = np.load('shear_sum_rico201600.npy') + shift_distance = np.load('shift_distancerico201600.npy') + cmin=3 + + elif m0 ==2: + height=np.load('height_no_shear_arm28800.npy') + volume=np.load('volume_no_shear_arm28800.npy') + projar=np.load('projarea_no_shear_arm28800.npy') + overlap=np.load('overlap_no_shear_arm28800.npy') + areaz=np.load('area_z_ratio_arm28800.npy') + overlap_convex=np.load('overlap_convex_arm28800.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_arm28800.npy') + shearTB = np.load('shearTB_vel_arm28800.npy') + shear_sum = np.load('shear_sum_arm28800.npy') + shift_distance = np.load('shift_distancearm28800.npy') + cmin=3 + + elif m0==3: + height=np.load('height_no_shear_arm41400.npy') + volume=np.load('volume_no_shear_arm41400.npy') + projar=np.load('projarea_no_shear_arm41400.npy') + overlap=np.load('overlap_no_shear_arm41400.npy') + areaz=np.load('area_z_ratio_arm41400.npy') + overlap_convex=np.load('overlap_convex_arm41400.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_arm41400.npy') + shearTB = np.load('shearTB_vel_arm41400.npy') + shear_sum = np.load('shear_sum_arm41400.npy') + shift_distance = np.load('shift_distancearm41400.npy') + cmin=3 + + elif m0==4: + ### Bomex_All + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + overlap_convex=np.load('Bomex_hull.npy') + #shearh_vel = np.load('Bomex_shearh_vel.npy') + #sheara_vel = np.load('Bomex_sheara_vel.npy') + #wavg = np.load('Bomex_wavg.npy') + shearTB = np.load('Bomex_shearTB.npy') + shear_sum = np.load('Bomex_shear_sum.npy') + wz_max = np.load('Bomex_wz_max.npy') + wz_cb = np.load('Bomex_wz_cb.npy') + shift_distance = np.load('Bomex_shift_distance.npy') + cmin=5 + print('Bomex') + + + + binsize=100 + condition_vec= np.arange(binsize,max(ht)+binsize,binsize) #, 500, 100, 50] # to go through multiple conditions quickly + h_shear = np.zeros(condition_vec.size) + h_shape = np.zeros(condition_vec.size) + h_turb = np.zeros(condition_vec.size) + h_ACT = np.zeros(condition_vec.size) + h_RES = np.zeros(condition_vec.size) + h_total = np.zeros(condition_vec.size) + m=-1 + + ########################################################################################################################## + """ + ##### loop over bin hts + for conditional_height in condition_vec: + + m=m+1 + #conditional_height=1500 + index=np.where( (conditional_height-binsize < ht) & (ht <= conditional_height) ) # indices of where condition holds true in ht vector + index_size=index[0].size + ht_sel=ht[index[0]] # taking the ht values according to indices above + overlap_ratio_sel=overlap_ratio[index[0]]; + #area_proj_sel=area_proj[index[0]] + + + + + ############################################################ + ###### calculating overlap due to contributors + + #fract= (5*np.pi) / (6*np.sqrt(3)) -1 + #fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + #fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + #shear = abs(shear) + shear[shear<0]=0 + + fractalf = np.zeros(ht.size) + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + + + FF = f_turb(ht,200);FF[ht<=100]=0; + shear_sum = abs(shear_sum) + shift_d = np.zeros(ht.size) + shift_d[ht>50] = shift_distance + + shift_d = shift_d + shape*cp**0.5/2 ### draw the picture + updraft = (shear_sum*ht)/shift_d + FS = (shear_sum*ht)/(updraft*cp**0.5) + FS[updraft<0.1] = 0 + #FS[updraft<0.01] = 0 + + + ########################################################################################################################### + + + #shear = FS ; fractalf = FF + + #r_shear= 1/overlap_ratio[index[0]] - 1/overlap[index[0]] # index variables with index_greater[0] + #r_shear[r_shear<0]=0 + r_shear=shear[index[0]] + r_area=1/areaz[index[0]] -1 + #r_turb= (np.ones(index_size)*fractal) -1 + r_turb = fractalf[index[0]] + actual = 1/overlap_ratio[index[0]] + + #r_total = ( r_shear + r_area + r_turb ) +1 + + ######## + + #### empirical model + #f_t=f_turb(ht,200); f_t[ht<=100]=0 + #f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + #f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_shear=f_s[index[0]] + #r_area=f_a[index[0]] + #r_turb=f_t[index[0]] + + + r_total = ( r_shear + r_area + r_turb ) +1 + + + ######## + + residual = actual - r_total + #residual[residual<0]=0 + ####### binning data + + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + ACT_avg=np.mean(actual) + ACT_std=np.std(actual) + RES_avg=np.mean(residual) + RES_std=np.std(residual) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + h_shear[m]=S3_avg + h_shape[m]=A3_avg + h_turb[m]=T3_avg + h_ACT[m]=ACT_avg + h_RES[m]=RES_avg + h_total[m] = r3_avg + + + + ###################################################### + + + + + h_ACT=h_ACT -1 + h_ACT[h_ACT<0]=0 + ########################################################################################## + ###### stacked bar graph + #h_turb=f_turb(ht_bin,opt_t) + ## change variable + h_total = h_shape + h_shear +h_turb + + plt.figure() + + N= int(condition_vec.size) + + #N=np.count_nonzero(~np.isnan(h_shear)) + + ind = np.arange(N) # the x locations for the groups + width = 0.8 #1/N # the width of the bars: can also be len(x) sequence + width = 90 + ind=ind*100 +100 + arg_nan=np.argwhere(np.isnan(h_shape)) + #ind=ind[~np.isnan(h_shear)] + #N=ind.size + ind = ind.astype('float') + ind[arg_nan] = np.nan + + bottom2=np.zeros(ind.size) + bottom3=np.zeros(ind.size) + for i in range(ind.size): + #i = int(i/100 - 1) + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + + #ind=ind[~np.isnan(ind)] + #h_shear=h_shear[~np.isnan(h_shear)] + #h_shape=h_shape[~np.isnan(h_shape)] + #h_turb=h_turb[~np.isnan(h_turb)] + + + p1= plt.bar(ind,h_turb,width , color='pink') + p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') + p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) + #p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + + #plt.ylabel('Contribution Percentages') + #plt.title('Average Percentages') + plt.xlabel('Cloud Height') + plt.ylabel('Average Overlap') + plt.title('Average Contributions of Factors') + #plt.xticks(ind,mystring) + #plt.xticks(ind[0:1],condition_vec[0:1]) + #plt.xticks([0 , 9 , 19 ], ('100', '1000', '2000' ) ) + plt.yticks(np.arange(0, 20, 1)) + #plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) + + + pa=plt.plot(ind,h_ACT,'ko',linewidth=2) + + plt.legend((p1[0], p2[0],p3[0],pa[0]), ('Turbulence','Shear', 'Area Variability','Actual Overlap'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + + #plt.savefig('arm28800_factor_average1_emp1_061719.eps', dpi=300, bbox_inches='tight') + + + if m0==0: + plt.savefig('rico82800_factor_average1_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_factor_average1_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_factor_average1_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_factor_average1_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_factor_average1_061919.eps', dpi=300,bbox_inches='tight') + + """ + + ##################################################################################################################### + + + ##### loop over bin hts + for conditional_height in condition_vec: + + m=m+1 + #conditional_height=1500 + index=np.where( (conditional_height-binsize < ht) & (ht <= conditional_height) ) # indices of where condition holds true in ht vector + index_size=index[0].size + ht_sel=ht[index[0]] # taking the ht values according to indices above + overlap_ratio_sel=overlap_ratio[index[0]]; + #area_proj_sel=area_proj[index[0]] + + + + ############################################################ + ###### calculating overlap due to contributors + + #fract= (5*np.pi) / (6*np.sqrt(3)) -1 + #fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + #fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + #shear = abs(shear) + shear[shear<0]=0 + + fractalf = np.zeros(ht.size) + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + + FF = f_turb(ht,200);FF[ht<=100]=0; + shear_sum = abs(shear_sum) + shift_d = np.zeros(ht.size) + shift_d[ht>50] = shift_distance + + shift_d = shift_d + shape*cp**0.5/2 ### draw the picture + updraft = (shear_sum*ht)/shift_d + updraft[updraft<0.4] = 0.4 ### based on neggers 2015 + FS = (shear_sum*ht)/(updraft*cp**0.5) + #FS[updraft<0.1] = 0 + #FS[updraft<0.01] = 0 + #FS[FS>max(1/overlap_ratio)] = np.nan + #FS[np.argwhere(np.isnan(FS))] = max(FS) + + + + ########################################################################################################################### + + + shear = FS ; fractalf = FF + + #r_shear= 1/overlap_ratio[index[0]] - 1/overlap[index[0]] # index variables with index_greater[0] + #r_shear[r_shear<0]=0 + r_shear=shear[index[0]] + r_area=1/areaz[index[0]] -1 + #r_turb= (np.ones(index_size)*fractal) -1 + r_turb = fractalf[index[0]] + actual = 1/overlap_ratio[index[0]] + + + + r_total = ( r_shear + r_area + r_turb ) +1 + + + ######## + + residual = actual - r_total + #residual[residual<0]=0 + ####### binning data + + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + ACT_avg=np.mean(actual) + ACT_std=np.std(actual) + RES_avg=np.mean(residual) + RES_std=np.std(residual) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + h_shear[m]=S3_avg + h_shape[m]=A3_avg + h_turb[m]=T3_avg + h_ACT[m]=ACT_avg + h_RES[m]=RES_avg + h_total[m] = r3_avg + + + + ###################################################### + + + + + h_ACT=h_ACT -1 + h_ACT[h_ACT<0]=0 + ########################################################################################## + ###### stacked bar graph + #h_turb=f_turb(ht_bin,opt_t) + ## change variable + h_total = h_shape + h_shear +h_turb + + plt.figure() + + N= int(condition_vec.size) + + #N=np.count_nonzero(~np.isnan(h_shear)) + + ind = np.arange(N) # the x locations for the groups + width = 0.8 #1/N # the width of the bars: can also be len(x) sequence + width = 90 + ind=ind*100 +100 + arg_nan=np.argwhere(np.isnan(h_shape)) + #ind=ind[~np.isnan(h_shear)] + #N=ind.size + ind = ind.astype('float') + ind[arg_nan] = np.nan + + bottom2=np.zeros(ind.size) + bottom3=np.zeros(ind.size) + for i in range(ind.size): + #i = int(i/100 - 1) + bottom2[i]=h_turb[i]+h_shear[i] + bottom3[i]=h_turb[i]+h_shear[i]+h_shape[i] + + #ind=ind[~np.isnan(ind)] + #h_shear=h_shear[~np.isnan(h_shear)] + #h_shape=h_shape[~np.isnan(h_shape)] + #h_turb=h_turb[~np.isnan(h_turb)] + + + p1= plt.bar(ind,h_turb,width , color='pink') + p2 = plt.bar(ind, h_shear, width, bottom=h_turb ,color='blue') + p3 = plt.bar(ind, h_shape, width, bottom=bottom2, color='purple' ) + #p4 = plt.bar(ind, h_RES, width, bottom=bottom3, color='orange' ) + + #plt.ylabel('Contribution Percentages') + #plt.title('Average Percentages') + plt.xlabel('Cloud Height') + plt.ylabel('Average Overlap') + plt.title('Average Contributions of Factors') + #plt.xticks(ind,mystring) + #plt.xticks(ind[0:1],condition_vec[0:1]) + #plt.xticks([0 , 9 , 19 ], ('100', '1000', '2000' ) ) + plt.yticks(np.arange(0, 20, 1)) + #plt.legend((p1[0], p2[0],p3[0],p4[0]), ('Turbulence','Shear', 'Area Variability','Residual'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) + + + pa=plt.plot(ind,h_ACT,'ko',linewidth=2) + + plt.legend((p1[0], p2[0],p3[0],pa[0]), ('Turbulence','Shear', 'Area Variability','Actual Overlap'), loc='lower right', bbox_to_anchor=(1.50, 0.5),fontsize='small',ncol=1) + + #plt.savefig('arm28800_factor_average1_emp1_061719.eps', dpi=300, bbox_inches='tight') + + """ + if m0==0: + plt.savefig('rico82800_factor_average1_emp1_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_factor_average1_emp1_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_factor_average1_emp1_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_factor_average1_emp1_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_factor_average1_emp1_061919.eps', dpi=300,bbox_inches='tight') + + """ + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + diff --git a/scripts/calculating_contributions1.py b/scripts/calculating_contributions1.py new file mode 100644 index 0000000..2633dfe --- /dev/null +++ b/scripts/calculating_contributions1.py @@ -0,0 +1,400 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Apr 15 18:22:28 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files +""" +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') +""" + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +#ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + +""" +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] +""" +########################################################################### + +#################################### + +# script +filenames=[ricod] +ricofilenames=[ricotrack2016] +#bomexfilenames=[bomextrack36] +armfilenames=[armtrack522] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + +for file in filenames: + file_numb = file_numb+1 + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + file1_numb = file1_numb+1 + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + + + condition_vec=[1000]#, 500, 100, 50] # to go through multiple conditions quickly + + for conditional_height in condition_vec: + + #conditional_height=1500 + index_greater=np.where(ht >= conditional_height) # indices of where condition holds true in ht vector + index_greater_size=index_greater[0].size + ht_anvil=ht[index_greater[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_greater[0]]; + area_proj_anvil=area_proj[index_greater[0]] + + + print('Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_greater_size) + + ######################################## + + + + ### rico828 + """ + height=np.load('height_no_shear_rico828.npy') + volume=np.load('volume_no_shear_rico828.npy') + projar=np.load('projarea_no_shear_rico828.npy') + overlap=np.load('overlap_no_shear_rico828.npy') + areaz=np.load('area_z_ratio_rico828.npy') + """ + ### rico2016 + height=np.load('height_no_shear_rico2016.npy') + volume=np.load('volume_no_shear_rico2016.npy') + projar=np.load('projarea_no_shear_rico2016.npy') + overlap=np.load('overlap_no_shear_rico2016.npy') + areaz=np.load('area_z_ratio_rico2016.npy') + model=np.load('model_rico2016.npy') + + ############################################################ + + fractal= (6*np.sqrt(3)) / (5*np.pi) + + r_shear= 1/overlap_ratio[index_greater[0]] - 1/overlap[index_greater[0]] # index variables with index_greater[0] + r_shear[r_shear<0]=0 + r_area=1/areaz[index_greater[0]] -1 + r_turb= 1/(np.ones(index_greater_size)*fractal) -1 + + r_total = ( r_shear + r_area + r_turb ) +1 # correction: need to add 1 + + + """ + S=((r_shear-1)/r_total) + A=((r_area-1)/r_total) + T=((r_turb-1)/r_total) + """ + S3=r_shear + A3=r_area + T3=r_turb + + r3_avg=np.mean(r_total) + r3_std=np.std(r_total) + + S3_avg=np.mean(S3)#*100 + A3_avg=np.mean(A3)#*100 + T3_avg=np.mean(T3)#*100 + S3_std=np.std(S3) + A3_std=np.std(A3) + T3_std=np.std(T3) + + print('average r is %.2f' % r3_avg, ', r std is %.2f' % r3_std) + print('average r_shear is %.2f' % S3_avg, ', r_shear std is %.2f' % S3_std) + print('average r_area percentage is %.2f' % A3_avg, ', r_area std is %.2f' % A3_std) + print('average r_turbulence percentage is %.2f' % T3_avg, ', r_turbulence std is %.2f' % T3_std) + + + + ###################################################### + + print('----------------------------------------------------------------------------------') + conditional_height=100 + index_less=np.where(ht <= conditional_height) # indices of where condition holds true in ht vector + index_less_size=index_less[0].size + ht_anvil=ht[index_less[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_less[0]]; + area_proj_anvil=area_proj[index_less[0]] + print('Clouds with height less than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_less_size) + + + + + fractal= (6*np.sqrt(3)) / (5*np.pi) + + r_shear= 1/overlap_ratio[index_less[0]] - 1/overlap[index_less[0]] # index variables with index_less[0] + r_shear[r_shear<0]=0 + r_area=1/areaz[index_less[0]] -1 + r_turb= 1/(np.ones(index_less_size)*fractal) -1 + + r_total = ( r_shear + r_area + r_turb ) +1 + + + + S1=r_shear + A1=r_area + T1=r_turb + R1=r_total + r1_avg=np.mean(r_total) + r1_std=np.std(r_total) + + S1_avg=np.mean(S1)#*100 + A1_avg=np.mean(A1)#*100 + T1_avg=np.mean(T1)#*100 + S1_std=np.std(S1) + A1_std=np.std(A1) + T1_std=np.std(T1) + + print('average r is %.2f' % r1_avg, ', r std is %.2f' % r1_std) + print('average r_shear is %.2f' % S1_avg, ', r_shear std is %.2f' % S1_std) + print('average r_area percentage is %.2f' % A1_avg, ', r_area std is %.2f' % A1_std) + print('average r_turbulence percentage is %.2f' % T1_avg, ', r_turbulence std is %.2f' % T1_std) + + print('----------------------------------------------------------------------------------') + + + +############################################# + +print('----------------------------------------------------------------------------------') +#conditional_height=1500 +index_middle=np.where( (100 < ht) & (ht < 500)) # indices of where condition holds true in ht vector +index_middle_size=index_middle[0].size +ht_anvil=ht[index_middle[0]] # taking the ht values according to indices above +overlap_ratio_anvil=overlap_ratio[index_middle[0]]; +area_proj_anvil=area_proj[index_middle[0]] +print('Clouds with height between 100 and 1000 meters') +print('Clouds that satisfy the given condition: ',index_middle_size) + + + + +fractal= (6*np.sqrt(3)) / (5*np.pi) + +r_shear= 1/overlap_ratio[index_middle[0]] - 1/overlap[index_middle[0]] # index variables with index_middle[0] +r_shear[r_shear<0]=0 +r_area=1/areaz[index_middle[0]] -1 +r_turb= 1/(np.ones(index_middle_size)*fractal) -1 + +r_total = ( r_shear + r_area + r_turb ) +1 # correction: need to subtract 1 from each + + + +S2=r_shear +A2=r_area +T2=r_turb + +r2_avg=np.mean(r_total) +r2_std=np.std(r_total) + +S2_avg=np.mean(S2)#*100 +A2_avg=np.mean(A2)#*100 +T2_avg=np.mean(T2)#*100 +S2_std=np.std(S2) +A2_std=np.std(A2) +T2_std=np.std(T2) + +print('average r is %.2f' % r2_avg, ', r std is %.2f' % r2_std) +print('average r_shear is %.2f' % S2_avg, ', r_shear std is %.2f' % S2_std) +print('average r_area percentage is %.2f' % A2_avg, ', r_area std is %.2f' % A2_std) +print('average r_turbulence percentage is %.2f' % T2_avg, ', r_turbulence std is %.2f' % T2_std) + +print('----------------------------------------------------------------------------------') + + + + + +################################################################ + +N = 3 +""" +h_shear = ( 7.67, 54.94 , 71.41) +h_shape = ( 5.17, 27.77 , 19.46) +h_turb = (87.19, 17.29,9.13) +""" + +h_shear = ( S1_avg, S2_avg , S3_avg) +h_shape = ( A1_avg, A2_avg , A3_avg) +h_turb = (T1_avg, T2_avg, T3_avg) +ind = np.arange(N) # the x locations for the groups +width = 1/N # the width of the bars: can also be len(x) sequence + +p1 = plt.bar(ind, h_shear, width, color='blue') +p2 = plt.bar(ind, h_shape, width, bottom=h_shear, color='purple' ) +p3=plt.bar(ind,h_turb,width,bottom=(h_shape[0] + h_shear[0] , h_shape[1] + h_shear[1], h_shape[2]+h_shear[2]) , color='pink') + +#plt.ylabel('Contribution Percentages') +#plt.title('Average Percentages') +plt.ylabel('Average Overlap') +plt.title('Average Contributions of Factors') +plt.xticks(ind, ( 'H < 100m' , '100m < H < 1000m', 'H > 1000m')) +plt.yticks(np.arange(0, 6, 1)) +plt.legend((p1[0], p2[0],p3[0]), ('Shear', 'Area','Turbulence'), loc='lower right', bbox_to_anchor=(1.40, 0.5),fontsize='small',ncol=1) + + + +#plt.savefig('rico2016_factor_average_042319.eps', dpi=300, bbox_inches='tight') + + + + + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) diff --git a/scripts/check1.py b/scripts/check1.py new file mode 100644 index 0000000..afec457 --- /dev/null +++ b/scripts/check1.py @@ -0,0 +1,319 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Apr 16 10:36:00 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack360] +armfilenames=[armtrack522] +#conditional_height=1000 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +kt=0; +file_numb=-1 +file1_numb=-1 + +for file in filenames: + file_numb = file_numb+1 + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + file1_numb = file1_numb+1 + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + + + condition_vec=[100]#, 500, 100, 50] # to go through multiple conditions quickly + + for conditional_height in condition_vec: + + #conditional_height=1500 + index_greater=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index_greater_size=index_greater[0].size + ht_anvil=ht[index_greater[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_greater[0]]; + area_proj_anvil=area_proj[index_greater[0]] + + print('Total Number of Clouds in dataset is %.0f' % nr.size) + print('Condition: Clouds with height greater than',conditional_height,'meters') + print('Clouds that satisfy the given condition: ',index_greater_size) + + + + +""" +### combines npy files into one +### only use once, affect will be compounded, delete combined npy file then run again +fpath ="path_Of_my_final_Big_File" +npyfilespath ="/home/anthonys/Documents/Temp1" +os.chdir(npyfilespath) +npfiles= glob.glob("*.npy") +npfiles.sort() +all_arrays = [] +for i, npfile in enumerate(npfiles): + all_arrays.append(np.load(os.path.join(npyfilespath, npfile))) +np.save(fpath, np.concatenate(all_arrays,axis=0)) +""" +###### + +""" +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[5:] +for f in Bfilenames: + print(f) + + data = Dataset(f,'r') +step=1800 # 30*60 +time_array= np.arange(10800,36000+step,step) +""" +""" +###################################################### +### Concatenate data +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[5:] +arrays1=[];arrays2=[];arrays3=[] +for f in Bfilenames: + print(f) + + data = Dataset(f,'r') + #overlap_ratio=data.variables['chr'][:] + #arrays1.append(overlap_ratio) + #ht=data.variables['ht'][:] + #arrays2.append(ht) + cp=data.variables['cp'][:] + arrays3.append(cp) + +#Bomex_overlap_ratio=np.concatenate(arrays1,axis=0) +#Bomex_ht=np.concatenate(arrays2,axis=0) +Bomex_cp=np.concatenate(arrays3,axis=0) +""" +######## +""" +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/overlap_no_shear_bomex*.npy')) +#Bfilenames = Afilenames[5:] +Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_shear=np.concatenate(arrays,axis=0) + +####### + +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/area_z_ratio_bomex*.npy')) +#Bfilenames = Afilenames[5:] +Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_areaz=np.concatenate(arrays,axis=0) +""" +""" +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/bomex_overlap_convex*.npy')) +#Bfilenames = Afilenames[5:] +#Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +Bfilenames = Afilenames +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_overlap_convex=np.concatenate(arrays,axis=0) +""" + +""" +#### accessing multiple npy files easily +Afilenames = sorted(glob.glob('/home/anthonys/Documents/shift_avg_bomex*.npy')) +Bfilenames = Afilenames[5:] +#Bfilenames = [x for i,x in enumerate(Afilenames) if i!=14] # exclude 14th elt +Bfilenames = Afilenames +arrays=[] +for f in Bfilenames: + print(f) + + data = np.load(f) + arrays.append(data) + #print(data.size) +Bomex_shift_avg=np.concatenate(arrays,axis=0) +""" +#### need to save concatenated data +####### +######################################################################## + + +############################## +#################################################### +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) diff --git a/scripts/convexhull1.py b/scripts/convexhull1.py new file mode 100644 index 0000000..5182f7e --- /dev/null +++ b/scripts/convexhull1.py @@ -0,0 +1,208 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue Apr 2 10:18:45 2019 + +@author: anthonys +""" + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +conditional_height=100 + +file1_numb=-1 + +### accessing multiple datasets easily +begin=5 +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] + +file1numb=begin-1 + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + #cloud_numb=np.array([575]) # ricotrack828 + + + height_convex=np.zeros(cloud_numb.size) + vol_convex=np.zeros(cloud_numb.size) + projarea_convex=np.zeros(cloud_numb.size) + overlap_convex=np.zeros(cloud_numb.size) + ######################################################## convex hull + + m=0; + for e1 in cloud_numb: # may take a while to run + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] + location_matrix[:,1]=location[1] + location_matrix[:,2]=location[2] + hull_3d=ConvexHull(location_matrix, qhull_options='QJ') + height_convex[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + vol_convex[m]=dx*dy*dz*hull_3d.volume + bd_pts=hull_3d.points[hull_3d.vertices] + hull_2d=ConvexHull(bd_pts[:,1:], qhull_options='QJ') + projarea_convex[m]=dx*dy*hull_2d.volume # volume and area are named base in 3d, so the 2d volume is indeed area + overlap_convex[m]= vol_convex[m] / (height_convex[m]*projarea_convex[m]) + m=m+1 + + overlap_contra=1/overlap_ratio - 1/overlap_convex + + step=1800 # 30*60 + time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/bomex_overlap_convex" + #np.save(npyfilespath+str(time_array[file1_numb])+'.npy',overlap_convex) + + ### plotting in convex hull in 3d and 2d + """ + fig=plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*bd_pts[:,2], dy*bd_pts[:,1],dz*bd_pts[:,0], color='green'); + #ax.scatter3D(dx*location_matrix[:,2], dy*location_matrix[:,1],dz*location_matrix[:,0], color='blue'); + #ax.plot_trisurf(dx*bd_pts[:,2], dy*bd_pts[:,1],dz*bd_pts[:,0], color='grey'); + for simplex in hull_3d.simplices: + #fig=plt.figure() + #ax = plt.axes(projection='3d') + + ax.plot3D(dx*location_matrix[simplex,2], dy*location_matrix[simplex,1],dz*location_matrix[simplex,0], color='black'); + #ax.plot_trisurf(dx*location_matrix[simplex,2], dy*location_matrix[simplex,1],dz*location_matrix[simplex,0], color='grey'); + #plt.plot(points[simplex, 0], points[simplex, 1], 'k-') + + plt.title('3d Convex Hull') + plt.figure() + plt.plot(dx*bd_pts[:,2], dy*bd_pts[:,1], 'o') + for simplex in hull_2d.simplices: + plt.plot(dx*bd_pts[simplex, 2], dy*bd_pts[simplex, 1], 'k-') + plt.title('2d Convex Hull') + """ + + """ + ########################################################## + ### plot overlap + bins=dz + + plt.figure() + plt.hist2d(overlap_convex,height_convex,bins=bins,cmin=0.5) + plt.title('Height vs. Convex Hull Overlap ') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + colorbar.set_label('counts in bin') + + + plt.figure() + plt.hist2d(overlap_ratio,ht,bins=bins,cmin=0.5) + plt.title('Height vs. Actual Overlap') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/generate_data1.py b/scripts/generate_data1.py new file mode 100644 index 0000000..860ec69 --- /dev/null +++ b/scripts/generate_data1.py @@ -0,0 +1,643 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed May 22 14:46:53 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################### +conditional_height=0 +epsilon1=50 ##### helps find clds that are split by grid box +#arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +#file1_numb=-1 + +""" +datau = Dataset('/data/rico/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/rico/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/rico/w.nc','r') +time_t = datau.variables['time'][:] +step=3600;time_array= np.arange(step,216000+step,step) +case='rico' +""" +""" +datau = Dataset('/data/bomex/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/bomex/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/bomex/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(step,36000+step,step) +case='bomex' +""" +""" +datau = Dataset('/data/lasso/sims/20160830/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/lasso/sims/20160830/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/lasso/sims/20160830/w.nc','r') +""" +datau = Dataset('/data/arm/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/arm/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/arm/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(10800,52200+step,step) +case='arm' + +#begin=5 +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:8] +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[1:] +#Bfilenames = [Afilenames[22], Afilenames[55]] +#Afilenames = sorted(glob.glob('/data/lasso/sims/20160830/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = [Afilenames[23], Afilenames[41]] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:2] +Bfilenames = [Afilenames[10], Afilenames[17]] + +#file1_numb=begin-1 ## python: arrays start at index 0 +file2_numb = -1 +file3_numb = [10,17] + +################################ + + + +############################# +#### loop over trackfiles +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file2_numb = file2_numb+1 + file1_numb = file3_numb[file2_numb] + + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + ###################################################################### + #### wind and udraft calculations + + ### + access = np.where(time_t == time_array[file1_numb])[0][0] + u=datau.variables['u'][access,:,:,:] + xh=datau.variables['xh'][:] + v=datav.variables['v'][access,:,:,:] + yh=datav.variables['yh'][:] + w=dataw.variables['w'][access,:,:,:] + zh=dataw.variables['zh'][:] + ### + + uint=interp1d(xh,u,axis=2,fill_value='extrapolate') + vint=interp1d(yh,v,axis=1,fill_value='extrapolate') + wint=interp1d(zh,w,axis=0,fill_value='extrapolate') + + ut=uint(xt) + vt=vint(yt) + wt=wint(zt) + + #w=interp1d(zh,w,axis=0,fill_value='extrapolate') + #ut=u;vt=v;#wt=w; + + + ut1=np.sum(np.sum(ut,axis=1),axis=1)/(nx*ny) + vt1=np.sum(np.sum(vt,axis=1),axis=1)/(nx*ny) + #ut1=np.mean(np.mean(ut,axis=1),axis=1) + #vt1=np.mean(np.mean(vt,axis=1),axis=1) + #wt1=np.mean(np.mean(wt,axis=1),axis=1) + + + uz=ut1 + vz=vt1 + #wz=wt1 + + #uz=np.mean(u,axis=0) # avg among diff times + #vz=np.mean(v,axis=0) # avg among diff times + shear_calu=np.zeros(cb.size) + shear_calv=np.zeros(cb.size) + """ + for i in range(cb.size): + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + """ + + + #shear_cal = np.sqrt( shear_calu**2 + shear_calv**2 ) + + #shear_cal = abs(shear_calu + shear_calv) / 2 + + + + ####### + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + + + #s_u=abs(duz);s_v=abs(dvz) + s_u=duz;s_v=dvz; + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2;#Amean=abs(Amean) + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v);#Hmean=abs(Hmean) + #pyth= (s_u**2 + s_v**2)**0.5 + + shear0=np.zeros(cb.size) + shear00=np.zeros(cb.size) + for i in range(cb.size): ##### calculating shear + + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) + shear00[i] = sum(Amean[cb[i]:ct[i]+1]) + + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + + + shear_cal = abs(shear_calu + shear_calv) / 2 + + ########################################################################### + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + + ### not chopping so just set alpha=1 + alpha=np.arange(1,0,-1) # just 1 + + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + + + height_convex=np.zeros(cloud_numb.size) + vol_convex=np.zeros(cloud_numb.size) + projarea_convex=np.zeros(cloud_numb.size) + overlap_convex=np.zeros(cloud_numb.size) + + w_avg = np.zeros(index1_size) + wz_max = np.zeros(index1_size) + wz_cb = np.zeros(index1_size) + wz_ct = np.zeros(index1_size) + wz_avg = np.zeros(index1_size) + wz_min = np.zeros(index1_size) + + shift_max=np.zeros(cloud_numb.size) + shift_min=np.zeros(cloud_numb.size) + shift_avg=np.zeros(cloud_numb.size) + shift_distance=np.zeros(cloud_numb.size) + + m=-1; #m=0; + + #### loop over clds + for e1 in cloud_numb: # may take a while to run + + m = m+1 + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + #layers=height/dz + ### + + base=np.amin(location[0]);top=np.amax(location[0]); + #levels=range(base,top+1,1) + + #### test to find clds that are split by the grid box + x_unique=np.unique(location[2]) + y_unique=np.unique(location[1]) + xtest1=abs(np.mean(x_unique)-np.median(x_unique)) # median is resistant while mean is not + ytest1=abs(np.mean(y_unique)-np.median(y_unique)) + + #### reconnnects split cld , idea: moves part of cld to otherside + if xtest1 > epsilon1: + splitx=np.where(location[2] < nx/2) + location[2][splitx] = location[2][splitx] + nx + + if ytest1 > epsilon1: + splity=np.where(location[1] < ny/2) + location[1][splity] = location[1][splity] + ny + + + #sys.exit("Error message") + + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + COM=np.zeros((top-base+1,3)) + newlocation_matrix=np.zeros(location_matrix.shape) + cross_area_z=np.zeros(int(layers)) + #u, indices = np.unique(location[0], return_index=True) + #COM[:,0]=u + + ############################################################ + #### generate updraft speed data + basez=base;topz=top;basey=min(location[1]);topy=max(location[1]);basex=min(location[2]);topx=max(location[2]); + w_abs=abs(wt) + #wz_avg=np.sum(w_abs[basez:topz+1,:,:],axis=0) / (topz - basez+1) + #wy_avg=np.sum(wz_avg[basey:topy+1,:],axis=0) / (topy - basey+1) + #wx_avg=np.sum(wy_avg[basex:topx+1],axis=0) / (topx - basex+1) + ##wz_avg=np.mean(w_abs[min(location[0]):max(location[0])+1,:,:],axis=0) + ##wy_avg=np.mean(wz_avg[min(location[1]):max(location[1])+1,:],axis=0) + ##wx_avg=np.mean(wy_avg[min(location[2]):max(location[2])+1],axis=0) + #w_avg[m]=wx_avg + #print(w_avg[m]) + """ + wy_avg=np.sum(w_abs[:,basey:topy+1,:],axis=1) / (topy - basey+1) + wx_avg=np.sum(wy_avg[:,basex:topx+1],axis=1) / (topx - basex+1) + wz = wx_avg[basez:topz+1] + + wz_max[m] = np.amax(wz) + wz_cb[m] = wz[0] + wz_ct[m] = wz[-1] + wz_avg[m] = np.mean(wz) + wz_min[m] = np.amin(wz) + """ + ##################### + ### generate Convex hull data + if dz*layers >100: + hull_3d=ConvexHull(location_matrix, qhull_options='QJ') + height_convex[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + vol_convex[m]=dx*dy*dz*hull_3d.volume + bd_pts=hull_3d.points[hull_3d.vertices] + hull_2d=ConvexHull(bd_pts[:,1:], qhull_options='QJ') + projarea_convex[m]=dx*dy*hull_2d.volume # volume and area are named base in 3d, so the 2d volume is indeed area + overlap_convex[m]= vol_convex[m] / (height_convex[m]*projarea_convex[m]) + + ######################## + ##### find center of mass and area of each layer of cld + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + # height / dz = layers + + #COM[z-base,:]=[z,sum(location[1][findz[0]])/findz[0].size, sum(location[2][findz[0]])/findz[0].size] + COM[z-base,:]=[z,np.mean(location[1][findz[0]]), np.mean(location[2][findz[0]])] #find center of mass w/ arithmetic mean + + + area_z_ratio[m]= np.mean(cross_area_z)/np.amax(cross_area_z) + center_choice=[np.mean(COM[:,1]), np.mean(COM[:,2])] ### choosing pt to align COMs + movement=np.subtract(center_choice , COM[:,1:]) + for z in np.arange(base,top+1,1): ### shifting cld + findz=np.where(location[0] == z) + newlocation_matrix[findz,1:]=location_matrix[findz,1:] + movement[z-base,:] + + newlocation_matrix[:,0]=location_matrix[:,0] + + location[0][:]=newlocation_matrix[:,0] # change to calculate overlap w/ code below + location[1][:]=newlocation_matrix[:,1] + location[2][:]=newlocation_matrix[:,2] + + #####################################\ + ### calculate shift distance b/c => w = (wind diff * ht)/ shift_distance + movement1 = 25*COM[:,1:] ### having center at origin,spacing in x and y direction + shift_cld= np.sqrt(movement1[:,0]**2 + movement1[:,1]**2) + #shift_cld = (abs(movement[:,0]) + abs(movement[:,1]) ) / 2 + shift_max[m] = np.amax(shift_cld) + shift_min[m] = np.amin(shift_cld) + shift_avg[m] = np.mean(shift_cld) + shift_distance[m] = np.amax(shift_cld) - np.amin(shift_cld) + ######################################### + + ######## + + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] # fraction of cld height + #height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: ### probably dont need this loop since we are not chopping cld ht + + part_loc= part_loc +1 # to index later for diff ht levels + for i in range(location[0].size): + if dz*(location[0][i]-location[0][0]+1) <= partial: # finding all cells below chopped cld ht (take highest cell) + celltop=i + else: + break + #if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,location[0].size): + if location[0][celltop] +1 == location[0][j]: # to use partial cells + cellabove=j + elif location[0][celltop] +1 < location[0][j]: + break + #print('partial',partial) + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + if partial == height_c[m]: # difference=0, so stop at celltop + proj_area_loop1=np.zeros(celltop +1) + vol_loop1=np.zeros(celltop +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + """ + ### plotting in cld in 3d + + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2][0:celltop+1],dy*location[1][0:celltop+1], dz*location[0][0:celltop+1], c=dz*location[0][0:celltop+1] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + else: + proj_area_loop1=np.zeros(cellabove +1) + vol_loop1=np.zeros(cellabove +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + + for loc0 in range(location[0].size): ### calculating proj area and vol + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop < loc0 and loc0 <=cellabove: + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: # full cell vol + vol_loop1[loc0]=(dx*dy*dz) + elif celltop < loc0 and loc0 <=cellabove: # partial cell vol + vol_loop1[loc0]=(dx*dy*difference) + else: + break + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) # counting cells w/ ! id # & proj-ing + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + + + + #m = m+1 + + #mu1=np.mean(Total_dr) + #sigma1=np.std(Total_dr) + #Check1=[Total_dr >= mu1 + 1.96 *sigma1] + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + """ + #################################################### + ##### saving data for convex hull + #if dz*layers >100: + # overlap_contra=1/overlap_ratio - 1/overlap_convex + + + #step=1800 # 30*60 + #time_array= np.arange(step,36000+step,step) + #npyfilespath ="/home/anthonys/Documents/bomex_overlap_convex" + ### + npyfilespath ="/home/anthonys/Documents/" + + name1 = 'overlap_convex_' + + #np.save(npyfilespath+str(time_array[file1_numb])+'.npy',overlap_convex) + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',overlap_convex) + + ############################################################ + + #### save wind differentials and updraft vel. + + + #step=1800 # 30*60 + #time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='bomex' + + + name1='shearTB_' + name2='shear_sum_' + #name3='wavg1_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',shear_cal) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',shear00) + #np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',w_avg) + + name1='wz_max_' + name2='wz_min_' + name3='wz_avg_' + name4='wz_ct_' + name5='wz_cb_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',wz_max) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',wz_min) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',wz_avg) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',wz_ct) + np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',wz_cb) + + name1='shift_max_' + name2='shift_min_' + name3='shift_avg_' + name4='shift_distance' + #name5='area_z_ratio_' + + + ### + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',shift_max) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',shift_min) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',shift_avg) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',shift_distance) + #np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',area_z_ratio) + + + + ################################ + ### saving data + + + + #step=1800 # 30*60 + #time_array= np.arange(step,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='bomex' + ### + #step=3600 # 60*60 + #time_array= np.arange(step,216000+step,step) + #npyfilespath ="/home/anthonys/Documents/" + #case='rico' + ### + #step = 600 + #time_array = np.zeros(56) + #time_array[0:2] = [0,1200,6600] + #time_array[3:] = np.arange(7800,41400+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='lasso' + + name1='overlap_no_shear_' + name2='volume_no_shear_' + name3='projarea_no_shear_' + name4='height_no_shear_' + name5='area_z_ratio_' + + + ### + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',overlap_c) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',volume_c) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',projected_area_c) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',height_c) + np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',area_z_ratio) + + + #np.save(npyfilespath+str(time_array[20])+'.npy',area_z_ratio) + + + + ########################### + """ + + + + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + diff --git a/scripts/graph3d_1.py b/scripts/graph3d_1.py new file mode 100644 index 0000000..3eee71c --- /dev/null +++ b/scripts/graph3d_1.py @@ -0,0 +1,431 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 21 11:25:54 2019 + +@author: anthonys +""" + + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# def + +def overlap(s,h,l): + #return l / (l +s*h) + return 1 - (s*h / (l + s*h)) +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack36] +ricofilenames=[ricotrack828] +armfilenames=[armtrack522] +conditional_height=0 + + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=2000 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + #cloud_numb=np.array([575]) # ricotrack828 + + ##################################################### shear + + + + uz=np.mean(u,axis=0) # avg among diff times + vz=np.mean(v,axis=0) # avg among diff times + wz=np.mean(w,axis=0) + + wint=interp1d(zh,wz,axis=0) + wz1=wint(zt) + + + one=np.ones(wz1.size) + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + #s_u=duz/np.maximum(wz1,one) + #s_v=dvz/np.maximum(wz1,one) + s_u=abs(duz)/np.maximum(wz1,one) + s_v=abs(dvz)/np.maximum(wz1,one) + + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2 + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0=np.zeros(cb.size) + shear1=np.zeros(cb.size) + for i in range(cb.size): + """ + du=uz[ct[i]]-uz[cb[i]] + dv=vz[ct[i]]-vz[cb[i]] + #w1=np.mean(wz1[cb[i]:ct[i]+1]) + su=du #/max(w1,1) + sv=dv #/max(w1,1) + #Hmean=(2*su*sv) / max( (su + sv) , 1) + Amean = (su+sv)/2 + shear0[i]= Amean #Hmean + """ + """ + s_u=sum(duz[cb[i]:ct[i]+1]) + s_v=sum(dvz[cb[i]:ct[i]+1]) + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0[i] = Hmean + """ + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + #shear0[i] = np.mean(Hmean[cb[i]:ct[i]+1]) + #shear0[i] = Hmean[ct[i]] - Hmean[cb[i]] + + + bins=2*dz + + plt.figure() + plt.hist2d(overlap_ratio,abs(shear0),bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + #plt.ylim([0,10]) + #plt.ylim([min(shear0),max(shear0)]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + + + ######################################### width + + shear=np.zeros(cloud_numb.size) + """ + width=np.zeros(cloud_numb.size) + widthx=np.zeros(cloud_numb.size) + widthy=np.zeros(cloud_numb.size) + """ + k=5 + width_base=np.zeros(cloud_numb.size) + widthx_base=np.zeros(k) + widthy_base=np.zeros(k) + + width_top=np.zeros(cloud_numb.size) + widthx_top=np.zeros(k) + widthy_top=np.zeros(k) + + m=0 + for e1 in cloud_numb: # may take a while to run + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + """ + ### calculating width of a cld by taking a max of a max + widthx[m]=dx*(np.amax(location[2]) - np.amin(location[2]) + 1) + widthy[m]=dy*(np.amax(location[1]) - np.amin(location[1]) + 1) + + #width[m] = max(widthx[m], widthy[m]) + #width[m] = 0.5*widthx[m] + 0.5*widthy[m] # arithmetic mean + width[m] = ( widthx[m]*widthy[m] )**(1/2) # geometric mean + """ + ########################## + + if dz*k > ht[e1-1]: + k=int(ht[e1-1]/dz) + widthx_base=np.zeros(k) + widthy_base=np.zeros(k) + #widthx_top=np.zeros(k) + #widthy_top=np.zeros(k) + + ### want to take max of bottom layers + base=np.amin(location[0]) + + for i in range(base,base+k): + + L=np.where(location[0] == i) + + widthx_base[i-base]=dx*(np.amax(location[2][L]) - np.amin(location[2][L]) + 1) + widthy_base[i-base]=dy*(np.amax(location[1][L]) - np.amin(location[1][L]) + 1) + + + #width_base[m] =max(np.amax(widthx_base), np.amax(widthy_base)) + width_base[m] = ( np.amax(widthx_base)*np.amax(widthy_base) )**(0.5) + + """ + ### want to take max of top layers + top=np.amax(location[0]) + + for i in range(top-k,top): + + L=np.where(location[0] == i) + + widthx_top[i-top+k]=dx*(np.amax(location[2][L]) - np.amin(location[2][L]) + 1) + widthy_top[i-top+k]=dy*(np.amax(location[1][L]) - np.amin(location[1][L]) + 1) + + + #width_top[m] =max(np.amax(widthx_top), np.amax(widthy_top)) + width_top[m] = ( np.amax(widthx_top)*np.amax(widthy_top) )**(0.5) + + """ + + + + shear[m]=shear0[e1-1] + + + + ### plotting in cld in 3d + """ + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2], dy*location[1], dz*location[0], c=dz*location[0] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + #### ploting z vs. x or z vs. x in scatter plots + """ + plt.figure() + plt.plot(dx*location[2], dz*location[0],'go') + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + plt.figure() + plt.plot(dy*location[1], dz*location[0],'go') + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + """ + #### ploting z vs. x or z vs. x in 2d historgrams + """ + bins=dz + plt.figure() + plt.hist2d(dx*location[2],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + m=m+1 + """ + plt.figure() + plt.plot(overlap(abs(shear),ht_anvil,width_base,np.ones(5)),ht_anvil,'o') + plt.figure() + plt.plot(overlap_ratio_anvil,ht_anvil,'*') + """ + bins=dz + plt.figure() + plt.hist2d(overlap(abs(shear),ht_anvil,width_base),ht_anvil,bins=bins,cmin=0.5) + plt.title('Calculated Overlap vs. height') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(overlap_ratio_anvil,ht_anvil,bins=bins,cmin=0.5) + plt.title('Actual Overlap vs. height') + plt.xlim([0,1]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/graph3d_2.py b/scripts/graph3d_2.py new file mode 100644 index 0000000..264736d --- /dev/null +++ b/scripts/graph3d_2.py @@ -0,0 +1,262 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Mar 28 14:13:44 2019 + +@author: anthonys +""" + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# def + +def overlap(s,h,l): + #return l / (l +s*h) + return 1 - (s*h / (l + s*h)) +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack36] +ricofilenames=[ricotrack828] +armfilenames=[armtrack522] +conditional_height=2000 + +### choose which case and track file + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=2000 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + cloud_numb=np.array([533,860,1991,2004]) # ricotrack828 + + + + m=0 + for e1 in cloud_numb: # may take a while to run + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + + + + """ + ### plotting in cld in 3d + + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2], dy*location[1], dz*location[0], c=dz*location[0] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + #### ploting z vs. x or z vs. x in scatter plots + """ + plt.figure() + plt.plot(dx*location[2], dz*location[0],'go') + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + plt.figure() + plt.plot(dy*location[1], dz*location[0],'go') + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + """ + #### ploting z vs. x or z vs. x in 2d historgrams + + bins=dz + plt.figure() + plt.hist2d(dx*location[2],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1],dz*location[0],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title(str(cloud_numb[m])) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + m=m+1 + + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + diff --git a/scripts/overlap_anvil1.py b/scripts/overlap_anvil1.py new file mode 100644 index 0000000..4f750fe --- /dev/null +++ b/scripts/overlap_anvil1.py @@ -0,0 +1,212 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Feb 6 11:41:38 2019 + +@author: anthonys +""" + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +import collections +from collections import Counter +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script + +bomexfilenames=[bomextrack18] + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + #nrcloudlist=nrcloudarray.tolist() + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells + uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + volume=dx*dy*dz*count_elmts + + #A=np.where(nrcloudarray==158) + #Ma=np.amax(A[1]) + #Mi=np.amin(A[1]) + #H=Ma-Mi+1 + # height, projected area + """ + vert_res=25 + height=np.zeros(uni_elmts.size) + #locx=[] + projected_area=np.zeros(uni_elmts.size) + for e1 in uni_elmts: # ~13 min to run + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + height[e1-1]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #locx.append(location[2]+location[1]*nx) + projected_area[e1-1]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + """ + + + + #overlap=volume/(height*projected_area) + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/overlap_calculation.py b/scripts/overlap_calculation.py new file mode 100644 index 0000000..a2fffb4 --- /dev/null +++ b/scripts/overlap_calculation.py @@ -0,0 +1,200 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 7 11:50:04 2019 + +@author: anthonys +""" + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +import collections +from collections import Counter +############################################## + + +""" +def overlap_calculation(index,nrcloudarray,xt,yt,zt): + + + index7=np.asarray(index) + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells + uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + uninew=[];countnew=[] + for uni in range(uni_elmts.size): + for i in range(index7.size): + if uni_elmts[uni] == index7[i]: + uninew.append(index7[i]) + countnew.append(count_elmts[index7[i]]) + uninew1=np.asarray(uninew) + countnew1=np.asarray(countnew) + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + volume_c=dx*dy*dz*countnew1 + + + #vert_res=25 + height_c=np.zeros(uninew1.size) + projected_area_c=np.zeros(uninew1.size) + m=0; + for e1 in uninew1: # may take a while to run + location=np.where(nrcloudarray == e1+1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + m = m+1 + + + + overlap_c=volume_c/(height_c*projected_area_c) + + return overlap_c, volume_c, height_c, projected_area_c +""" + +def overlap_calculation(index1,nrcloudarray,xt,yt,zt): + + + index7=np.asarray(index1) + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells + uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + uninew=[];countnew=[] + for uni in range(uni_elmts.size): + for i in range(index7.size): + if uni_elmts[uni] == index7[i]: + uninew.append(index7[i]) + countnew.append(count_elmts[index7[i]]) + uninew1=np.asarray(uninew) + countnew1=np.asarray(countnew) + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + volume_c=dx*dy*dz*countnew1 + + + #vert_res=25 + height_c=np.zeros(uninew1.size) + projected_area_c=np.zeros(uninew1.size) + m=0; + #alpha=[1.0] #, 0.9, 0.8, 0.7, 0.6, 0.5,0.2] + #alpha=np.asarray(alpha) + alpha=np.arange(1,0.15,-0.05) + for e1 in uninew1: # may take a while to run + + + location=np.where(nrcloudarray == e1+1) # location of all cells with cloud # e1+1, e1 is the index and cloud # is index + 1 + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] + height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: + celltop=0 + part_loc= part_loc +1 + proj_area_loop1=[] + vol_loop1=[] + for i in range(location[0].size): + if dz*(location[0][i]-location[0][0]+1) <= partial: + celltop=i + if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) + for j in range(celltop,location[0].size): + if location[0][celltop] +1 == location[0][j]: + cellabove=j + #loc_loc0=-1 + for loc0 in range(location[0].size): + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + if celltop < loc0 and loc0 <=cellabove: + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: + vol_loop1.append(dx*dy*dz) + if celltop < loc0 and loc0 <=cellabove: + vol_loop1.append(dx*dy*difference) + #if dz*loc0 < parital: + proj_area_loop1=np.asarray(proj_area_loop1) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) + vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + plt.plot(overlap_changed,alpha,'o-') + #plt.xlim([0, 1]) + #plt.plot(overlap_changed,height_c[m],'o') + #plt.plot(overlap_ratio_new1,htnew1,'o') + m = m+1 + + + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + + + return overlap_c, volume_c, height_c, projected_area_c, height_diff + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/overlap_width_cv.py b/scripts/overlap_width_cv.py new file mode 100644 index 0000000..0b02326 --- /dev/null +++ b/scripts/overlap_width_cv.py @@ -0,0 +1,509 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Mar 27 17:03:07 2019 + +@author: anthonys +""" + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# def +""" +def overlap(s,h,l): + #return l / (l +s*h) + return 1 - (s*h / (l + s*h)) +""" +def overlap1(s,h,l,w): + alpha= 1 / (1+w) + 1 + return 1 - (alpha*0.5*s*h / (l + s*h)) + +def overlap2(s,h,l): + #return l / (l +s*h) + B=1/(1+(h/l)) + return 1 - (B*s*h / (l + B*s*h)) + +def overlap_inv1(s,h,l): + #return l / (l +s*h) + B=h/l + #return 1 + ( (B*s*h) / l) + return ( (B*s*h) / l) + +def opt_fun1(X,B): + #return l / (l +s*h) + #B=1*h/l + s,h,l = X + return ( (B*s*h) / l) + +def shearpar(X,gs): + h,l = X + return gs * (h/l) + + +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack360] +ricofilenames=[ricotrack828] +armfilenames=[armtrack522] +conditional_height=0 + + +fractal= (6*np.sqrt(3)) / (5*np.pi) + +### rico828 +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') + +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +""" +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=2000 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + + # selecting cld to plot explicitly + #cloud_numb=np.array([278,313,351]) #ricotrack2016 + #cloud_numb=np.array([137,371,431]) #ricotrack2016 + #cloud_numb=np.array([70,254,486]) #ricotrack2124 + #cloud_numb=np.array([196,199,242]) #ricotrack2124 + #cloud_numb=np.array([533]) # ricotrack828 + #cloud_numb=np.array([4320, 4526]) # ricotrack2016 + #cloud_numb=np.array([224]) # ricotrack900 + #cloud_numb=np.array([330]) # ricotrack1548 + #cloud_numb=np.array([575]) # ricotrack828 + + ##################################################### shear + + + + uz=np.mean(u,axis=0) # avg among diff times + vz=np.mean(v,axis=0) # avg among diff times + wz=np.mean(w,axis=0) + + UVz= (2*uz*vz)/(uz+vz) + #UVz= (uz**2 + vz **2)**0.5 + + wint=interp1d(zh,wz,axis=0) + wz1=wint(zt) + + + one=np.ones(wz1.size) + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + + #s_u=duz/np.maximum(wz1,one) + #s_v=dvz/np.maximum(wz1,one) + s_u=abs(duz)/np.maximum(wz1,one) + s_v=abs(dvz)/np.maximum(wz1,one) + + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2 + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v) + pyth= (s_u**2 + s_v**2)**0.5 + + shear0=np.zeros(cb.size) + w_cld=np.zeros(cb.size) + for i in range(cb.size): + """ + du=uz[ct[i]]-uz[cb[i]] + dv=vz[ct[i]]-vz[cb[i]] + #w1=np.mean(wz1[cb[i]:ct[i]+1]) + su=du #/max(w1,1) + sv=dv #/max(w1,1) + #Hmean=(2*su*sv) / max( (su + sv) , 1) + Amean = (su+sv)/2 + shear0[i]= Amean #Hmean + """ + """ + s_u=sum(duz[cb[i]:ct[i]+1]) + s_v=sum(dvz[cb[i]:ct[i]+1]) + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0[i] = Hmean + """ + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + + #shear0[i] = abs(UVz[ct[i]] - UVz[cb[i]]) + + + #shear0[i] = np.mean(Hmean[cb[i]:ct[i]+1]) + #shear0[i] = Hmean[ct[i]] - Hmean[cb[i]] + w_cld[i]=np.mean(wz1[cb[i]:ct[i]+1]) + + """ + bins=2*dz + + plt.figure() + plt.hist2d(overlap_ratio,abs(shear0),bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + #plt.ylim([0,10]) + #plt.ylim([min(shear0),max(shear0)]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + """ + + + + beta_find=( ((1/overlap)-1)*cv**(0.5) ) / (abs(shear0)*ht_anvil ) + + + + bins=dz + """ + plt.figure() + plt.hist2d(overlap1(abs(shear0),ht_anvil,(cv)**(1/2),w_cld),ht_anvil,bins=bins,cmin=0.5) + plt.title('Height vs. Calculated Overlap') + plt.xlim([0,1.0]) + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + plt.figure() + plt.hist2d(overlap(abs(shear0),ht_anvil,(cv)**(1/2)),ht_anvil,bins=bins,cmin=0.5) + plt.title('Height vs. Calculated Overlap') + plt.xlim([0,1]) + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + plt.figure() + plt.hist2d(overlap_ratio_anvil,ht_anvil,bins=bins,cmin=0.5) + plt.title('Height vs. Actual Overlap') + plt.xlim([0,1]) + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + """ + """ + plt.figure() + plt.hist2d(1/overlap1(abs(shear0),ht_anvil,(cv)**(1/2),w_cld),1/overlap_ratio,bins=bins,cmin=2.0) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.title('Model Comparison') + #plt.xlim([0,1.0]) + plt.xlim(left=0) + plt.ylim(bottom=0) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + """ + + + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + beta_find=( ((shear))*cv**(0.5) ) / (abs(shear0)*ht_anvil ) + l=cv**(1/2) + Model_inv=overlap_inv1(abs(shear0),ht_anvil,l) + bins=3*dz + plt.figure() + ###Note: cmin=5 here while we usually have cmin=2 , or ... cmin=2 and have bins=2*dz + plt.hist2d(Model_inv,1/overlap_ratio,bins=[4*dz,1*dz],cmin=3.0) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.title('Model Comparison') + #plt.xlim([0,1.0]) + plt.xlim(left=0) + plt.ylim(bottom=0) + plt.xlim([0,10]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + plt.figure() + ###Note: cmin=5 here while we usually have cmin=2 , or ... cmin=2 and have bins=2*dz + plt.hist2d(shear0,ht,bins=[1*dz,1*dz],cmin=3.0) + #plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.title('Ht vs. Shear') + #plt.xlim([0,1.0]) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,15]) + plt.xlabel('Shear') + plt.ylabel('Ht') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + + + + cmin=3.0 + + X1=(abs(shear0),ht_anvil,cv**0.5) + opt1, cov1 = curve_fit(opt_fun1, X1 , shear) + model_opt1=opt_fun1(X1,*opt1) + + plt.figure() + plt.hist2d(model_opt1, shear, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + + """ + + #### + #when cmin=3, some (outlier) clds are not shown, this clds have rinv > 5 + ## be careful here , only run once + non_out= np.where(model_opt1<5) + ##### + + X2=(abs(shear0[non_out]),ht_anvil[non_out],cv[non_out]**0.5) + opt2, cov2 = curve_fit(opt_fun1, X2 ,1/overlap[non_out]) + model_opt2=opt_fun1((abs(shear0[non_out]),ht_anvil[non_out],cv[non_out]**0.5),*opt2) + + #opt2=np.float64([2.4]) + + plt.figure() + plt.hist2d(opt_fun1(X2,*opt2), 1/overlap[non_out], bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + shear=opt_fun1(X1,*opt2) + #r_total = ( (1/(overlap)) + (1/areaz) + (1/fractal) ) -3 # correction: need to subtract 1 from each + #r_total = ( ((shear)) + (1/areaz) + (1/fractal) ) -3 # correction: need to subtract 1 from each + + + horizontal= shear + vertical= 1/overlap + + plt.figure() + plt.hist2d(horizontal, vertical, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + plt.xlim([0,5]) + plt.ylim([0,5]) + """ + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + diff --git a/scripts/parmfit1.py b/scripts/parmfit1.py new file mode 100644 index 0000000..7fadf47 --- /dev/null +++ b/scripts/parmfit1.py @@ -0,0 +1,380 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon May 20 11:32:06 2019 + +@author: anthonys +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import matplotlib.colors as colors +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +#import cProfile +from numpy import percentile +#import overlap_calculation +from scipy.stats import spearmanr +#from scipy.stats import hmean +from scipy.stats import gmean + + + +################################################ +start=time.time() + + +def shearpar(X,gs): + h,l = X + return gs * (h/l) + + +def shearpar2(X,gs): + h,l = X + return gs * (h/l)**2 + + +def turbpar(h,g): + return g*h + +def multi1(X,parm1,parm2,parm3): + h,l,V = X + return parm1*h+parm2*l+parm3*V + + +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + + +#################################################### + +### rico828 +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') + +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +model_inv=np.load('model_inv_rico2016.npy') +model_opt=np.load('model_opt_rico2016.npy') +model_opt2=np.load('model_opt2_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +""" + + + + + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +#Bfilenames = Afilenames[5:6] +Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + """ + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + """ + + + + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + """ + ### upper bound to turb + lam = np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + keep=np.argwhere(fractalf >1.5*lam-1) + fractalf[np.array(keep)]=1.5*lam-1 + """ + + ### upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + l=cv**0.5 + + """ + cmin=1 + l=cv**0.5 + V=volume + X1=(ht,l,V) + opt1, cov1 = curve_fit(multi1, X1 , shear) + model_opt1=multi1(X1,*opt1) + + plt.figure() + plt.hist2d(shear, model_opt1, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + cmin=1 + l=cv**0.5 + X1=(ht,l) + opt1, cov1 = curve_fit(shearpar, X1 , shear,p0=2) + model_opt1=shearpar(X1,*opt1) + + plt.figure() + plt.hist2d(ht/l, model_opt1, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + + + ht_sort=np.sort(ht) + ht_arg=np.argsort(ht) + fractalf_sort=np.zeros(fractalf.size) + count=-1 + for i in ht_arg: + count= count+1 + fractalf_sort[count]=fractalf[i] + + cmin=1 + l=cv**0.5 + X2=ht + opt2, cov2 = curve_fit(turbpar, X2 , fractalf) + model_opt2=turbpar(X2,*opt2) + + plt.figure() + plt.hist2d(ht,model_opt2, bins=dz , cmin=cmin) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + """ + + """ + ### curve fit binned data + opt_t, cov_t = curve_fit(f_turb , ht, fractalf) + + c=opt_t + model_turb=f_turb(ht,c) + + + bins=1*dz; + + plt.figure(); + plt.hist2d(ht,model_turb,bins=[1*dz,1*dz],cmin=1, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + + + plt.title('Effect of Turbulence'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + + plt.xlabel('ht') + plt.ylabel('Cal Overlap') + #plt.xlabel('Cloud Overlap') + #plt.ylabel('Cloud Height') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + """ + + plt.figure() + plt.plot(ht,fractalf,'o') + z= np.polyfit(ht, fractalf,3) + p=np.poly1d(z) + plt.plot(ht,p(ht),'o') + + + plt.figure() + plt.plot(fractalf,p(ht),'o') + plt.plot(fractalf,fractalf) + + + #plt.figure() + ##plt.plot(fractalf-p(ht),'o') # residual plot + + #plt.hist(fractalf-p(ht)) + + plt.figure() + plt.hist2d(ht,fractalf - p(ht), bins=25,cmin=1) # res plt + plt.clim(0,200) + plt.plot(ht,np.zeros(ht.size),'k',linewidth=3) + + z_t = z;p_t=p + + plt.figure() + plt.plot(ht/l,shear,'o') + z= np.polyfit(ht/l, shear,3) + p=np.poly1d(z) + plt.plot(ht/l,p(ht/l),'o') + + + plt.figure() + plt.plot(shear,p(ht/l),'o') + plt.plot(shear,shear) + + plt.figure() + plt.hist2d(ht/l,shear - p(ht/l), bins=25,cmin=1) # res plt + plt.clim(0,200) + plt.plot(ht/l,np.zeros(ht.size),'k',linewidth=3) + z_s = z;p_s=p + + + plt.figure() + plt.plot(ht,shape,'o') + z= np.polyfit(ht, shape,3) + p=np.poly1d(z) + plt.plot(ht,p(ht),'o') + + + plt.figure() + plt.plot(shape,p(ht),'o') + plt.plot(shape,shape) + + plt.figure() + plt.hist2d(ht,shape - p(ht), bins=25,cmin=1) # res plt + plt.clim(0,200) + plt.plot(ht,np.zeros(ht.size),'k',linewidth=3) + z_a = z;p_a=p + + + + p_c = p_s(ht/l) + p_t(ht) + p_a(ht) +1 + + + + plt.figure() + plt.plot(p_c,1/overlap_ratio,'o') + plt.plot(p_c,p_c) + + plt.figure() + plt.hist2d(p_c,1/overlap_ratio, bins=dz , cmin=3) + plt.plot(np.arange(0,100,1),'k',linewidth=3) + plt.xlim(left=0) + plt.ylim(bottom=0) + #plt.xlim([0,20]) + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + colorbar=plt.colorbar(extend='both'); + colorbar.set_label('count in bin') + plt.clim(0,200) + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) \ No newline at end of file diff --git a/scripts/percentcloud2.py b/scripts/percentcloud2.py new file mode 100644 index 0000000..b05203a --- /dev/null +++ b/scripts/percentcloud2.py @@ -0,0 +1,509 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 7 11:51:46 2019 + +@author: anthonys +""" +""" +calculates overlap ratio base on ht of cld from chopping the cld at the top + + +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation + +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +##### choose case and track file +# script +filenames=[ricod] +ricofilenames=[ricotrack828] +bomexfilenames=[bomextrack36] +armfilenames=[armtrack522] +conditional_height=1500 + +kt=0; +file_numb=-1 +file1_numb=-1 + +for file in filenames: + file_numb = file_numb+1 + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + file1_numb = file1_numb+1 + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + + + ### take cloud that satisfy conditional ht + + #conditional_height=1500 + index_anvil=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] # taking the ht values according to indices above + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + print('conditional height is',conditional_height,'meters') + + + + + + +############################################################################ + # calculate overlap of a cld that at some of its height chopped off at the top + + + index7=index_anvil[0] # to make easy on coder + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + #countnew1=count_elmts[index7] # dont need as vol is calculatd in for loop + + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + + #cloud_numb=np.array([533]) # choosing a particular cld + #vert_res=25 + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + m=0; + ###### choppong cld at a certain fractional ht + #alpha=np.arange(1,0,-1) # just 1 + alpha=np.arange(1,0.35,-0.1) # fraction + #alpha=np.array([0.7,0.5,0.3,0.1]) + + #Dist=np.zeros((cloud_numb.size , alpha.size -1)) + #Dcurve=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve2=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve3=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + + Total_dr=np.zeros((cloud_numb.size,alpha.size -1)) # multi dimensional array + mu=np.zeros(cloud_numb.size) + sigma=np.zeros(cloud_numb.size) + Keeptrack_tdr=np.zeros((cloud_numb.size,3)) #make abitrarily big + alpha_matrix=np.zeros((cloud_numb.size,alpha.size)) + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + + ##### loop for clouds + for e1 in cloud_numb: # may take a while to run + + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] # fraction of cld height + #height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: ### loop over fractional hts of cld + + part_loc= part_loc +1 # to index later for diff ht levels + for i in range(location[0].size): + if dz*(location[0][i]-location[0][0]+1) <= partial: # finding all cells below chopped cld ht (take highest cell) + celltop=i + else: + break + #if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,location[0].size): #### find top grid pts + if location[0][celltop] +1 == location[0][j]: # to use partial cells + cellabove=j + elif location[0][celltop] +1 < location[0][j]: + break + #print('partial',partial) + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + if partial == height_c[m]: # difference=0, so stop at celltop + proj_area_loop1=np.zeros(celltop +1) + vol_loop1=np.zeros(celltop +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + else: + proj_area_loop1=np.zeros(cellabove +1) + vol_loop1=np.zeros(cellabove +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + + for loc0 in range(location[0].size): + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop < loc0 and loc0 <=cellabove: + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: # full cell vol + vol_loop1[loc0]=(dx*dy*dz) + elif celltop < loc0 and loc0 <=cellabove: # partial cell vol + vol_loop1[loc0]=(dx*dy*difference) + else: + break + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) # counting cells w/ ! id # & proj-ing + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + + ### dist btw adjacent pts + #if part_loc>0: + # Dist[m,part_loc-1]= np.sqrt( (alpha[part_loc]-alpha[part_loc-1])**2 + (overlap_changed[part_loc]-overlap_changed[part_loc-1])**2 ) + + + ###derivative at each pt + #vol_grad=np.gradient(vol_changed) + #projA_grad=np.gradient(projected_area_changed) + #ht_grad=np.gradient(partial_heights) + #Dcurve2[m]=(vol_grad/volume_c[m])-(ht_grad/height_c[m])-(projA_grad/projected_area_c[m]) + #overlap_changed_grad=np.gradient(overlap_changed) + #alpha_grad=np.gradient(alpha) + #Dcurve[m]=alpha_grad/overlap_changed_grad + #Dcurve3[m]=np.gradient(alpha/overlap_changed) + + ## calculates change in r of a cld + dr=np.zeros(alpha.size -1) + for i in range(alpha.size -1 ) : + dr[i]= overlap_changed[i+1] - overlap_changed[i] # having abs lowers the high pt of the interval + Total_dr[m,i]=dr[i] + + + + alpha_matrix[m,:]=alpha + overlap_changed_matrix[m,:]=overlap_changed + Keeptrack_tdr[kt,:]=[file_numb,file1_numb,e1] + kt=kt+1 + """ + mu[m]=np.mean(dr) + sigma[m]=np.std(dr) + + ### prints index of matrix where change in r is outside the confidence interval + for i in range(alpha.size -1 ): + if abs(Total_dr[m,i]) >= mu[m]+1.96*sigma[m]: + print('index',(m,i)) #remeber indices start at zero + """ + ###putting alpha = partial_heights / height_c[m] b/c partial_heights = alpha * height_c[m] + plt.plot(overlap_changed,alpha,'o-',label=str(cloud_numb[m])) + plt.title('normalized height vs. overlap') + + #plt.plot(alpha,overlap_changed,'o-',label=str(cloud_numb[m])) + #plt.title('overlap vs. normalized height ') + #plt.xlim([1,0.2]) + + + + + plt.legend(loc='upper right', bbox_to_anchor=(1.40, 1.0), fontsize='small',ncol=2) + + + + + + + + m = m+1 + + #mu1=np.mean(Total_dr) + #sigma1=np.std(Total_dr) + #Check1=[Total_dr >= mu1 + 1.96 *sigma1] + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + + + + + + +""" +corr_spear, p_spear = spearmanr(overlap_changed_matrix.flatten(), alpha_matrix.flatten()) #spearman correlation measures monoticity of overlap and normalized ht +spearman=[corr_spear, p_spear] +print('spearman correlation:',corr_spear,', spearman p-value:',p_spear) + +avg_dr=np.mean(Total_dr, axis=1) # average dr for each cld +avg_avg_dr=np.mean(Total_dr.flatten()) # avg dr for trackfile, # approx mean of boxplot ? + + +### calculate interquartile range +#data=Total_dr.flatten() +q25, q75 = percentile(Total_dr.flatten(), 25), percentile(Total_dr.flatten(), 75) +iqr = q75 - q25 + +### calculate the outlier cutoff +cut_off = iqr * 1.5 +lower, upper = q25 - cut_off, q75 + cut_off +#outliers = [x for x in data if x < lower or x > upper] +outliers_great = [x for x in Total_dr.flatten() if x > upper] +### plot box and whisker plot +fig1, ax1 = plt.subplots() +ax1.set_title('Change in Overlap per chop') +ax1.boxplot(Total_dr.flatten())#,notch=True,bootstrap=1000) +### plot histogram +plt.figure() +plt.hist(Total_dr.flatten(), bins='auto') +plt.title('count of change in r vs. change in r per chop') +""" + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/percentcloud3.py b/scripts/percentcloud3.py new file mode 100644 index 0000000..21ad52d --- /dev/null +++ b/scripts/percentcloud3.py @@ -0,0 +1,413 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Feb 14 11:41:26 2019 + +@author: anthonys +""" + +""" +calculates overlap ratio base on ht of cld from chopping the cld at the bottom + + +""" + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script + +bomexfilenames=[bomextrack36] +ricofilenames=[ricotrack2016] +armfilenames=[armtrack522] +conditional_height=1500 + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + nrcloudarray = np.ma.getdata(nrcloud) + #conditional_height=1500 + index_anvil=np.where(ht > conditional_height) + index_anvil_size=index_anvil[0].size + ht_anvil=ht[index_anvil[0]] + overlap_ratio_anvil=overlap_ratio[index_anvil[0]]; + area_proj_anvil=area_proj[index_anvil[0]] + print('Clouds that satisfy the given condition: ',index_anvil_size) + + + """ + cbnew1=[];ctnew1=[];cbnew2=[];ctnew2=[];area_projnew1=[];area_projnew2=[]; + overlap_ratio_new1=[];overlap_ratio_new2=[];htnew1=[];htnew2=[]; + index1=[];index2=[]; + + for i in range(ht.size): + if ht[i] > conditional_height: #ht[i]*overlap_ratio[i] > 200: + cbnew1.append(cb[i]) + ctnew1.append(ct[i]) + area_projnew1.append(area_proj[i]) + overlap_ratio_new1.append(overlap_ratio[i]) + htnew1.append(ht[i]) + index1.append(i) + else: + cbnew2.append(cb[i]) + ctnew2.append(ct[i]) + area_projnew2.append(area_proj[i]) + overlap_ratio_new2.append(overlap_ratio[i]) + htnew2.append(ht[i]) + index2.append(i) + + cbnew1=np.asarray(cbnew1) + ctnew1=np.asarray(ctnew1) + cbnew2=np.asarray(cbnew2) + ctnew2=np.asarray(ctnew2) + area_projnew1=np.asarray(area_projnew1) + area_projnew2=np.asarray(area_projnew2) + overlap_ratio_new1=np.asarray(overlap_ratio_new1) + overlap_ratio_new2=np.asarray(overlap_ratio_new2) + htnew1=np.asarray(htnew1) + htnew2=np.asarray(htnew2) + """ + + + + #overlap_cal, volume_cal, height_cal, projected_area_cal, height_diff = overlap_calculation.overlap_calculation(index1,nrcloudarray,xt,yt,zt) + + + + #plt.figure() + #plt.plot(overlap_cal,height_cal,'o') + #plt.figure() + #plt.plot(overlap_ratio_new1,htnew1,'o') + + + +############################################################################ + # calculate overlap of a cld that at some of its height chopped off at the bottom + + + index7=index_anvil[0] + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + # volume + #unique_elements, counts_elements = np.unique(nrcloudarray, return_counts=True) # takes cloud # and how many cells, comment out saved 2 sec + #uni_elmts=unique_elements[1:];count_elmts=counts_elements[1:] # exclude zero + # dont need above as we dont need the for loops below + """ + uninew=[];countnew=[] + for uni in range(uni_elmts.size): + for i in range(index7.size): + if uni_elmts[uni] == index7[i]: # taking index of cloud w/ certain condition + uninew.append(index7[i]) + countnew.append(count_elmts[index7[i]]) + uninew1=np.asarray(uninew) + countnew1=np.asarray(countnew) + """ + cloud_numb=index7 +1 # index is off by 1 as array starts with zero + #countnew1=count_elmts[index7] # dont need as vol is calculatd in for loop + + + # percent of cloud ht should change countnew1=> change vol, ht, proj area + #volume_c=dx*dy*dz*countnew1 # calculated later + + #cloud_numb=np.array([533]) # choose a particular cld + #vert_res=25 + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + + m=0; + #alpha=[1.0] #, 0.9, 0.8, 0.7, 0.6, 0.5,0.2] + #alpha=np.asarray(alpha) + alpha=np.arange(1,0.15,-0.1) # fraction + + #Dcurve=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + for e1 in cloud_numb: # may take a while to run + + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + locz_size=location[0].size + #print('locz',locz_size) + height_c[m]=dz*(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z axis + #projected_area_c[m]=dx*dy*len(np.unique(location[2]+location[1]*nx)) #len of unique # of cells that get proj + partial_heights=alpha*height_c[m] # fraction of cld height + #height_diff=height_c[m]-partial_heights + + overlap_changed=np.zeros(partial_heights.size) + projected_area_changed=np.zeros(partial_heights.size) + vol_changed=np.zeros(partial_heights.size) + part_loc= -1 + for partial in partial_heights: + + part_loc= part_loc +1 + for i in range(locz_size-1,-1,-1): + if dz*(-location[0][i]+location[0][-1]+1) <= partial: # finding all cells above chopped cld ht + celltop=i # celltop is more like cellbottom + else: + break + #if partial - dz*(location[0][celltop]-location[0][0]+1) >0: + difference = partial - dz*(-location[0][celltop]+location[0][-1]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,-1,-1): + if location[0][celltop] -1 == location[0][j]: # to use partial cells + cellabove=j # cellabove is more like cellbelow + elif location[0][celltop] -1 > location[0][j]: + break + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + + ##################################### + """ + proj_area_loop1=[] + vol_loop1=[] + for loc0 in range(locz_size-1,-1,-1): + + #loc_loc0 = loc_loc0 +1 + if loc0 >= celltop : + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + elif celltop > loc0 and loc0 >=cellabove: + proj_area_loop1.append(location[2][loc0]+location[1][loc0]*nx) + if loc0 >= celltop: # full cell vol + vol_loop1.append(dx*dy*dz) + elif celltop > loc0 and loc0 >=cellabove: # partial cell vol + vol_loop1.append(dx*dy*difference) + else: + break + + proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + vol_loop1=np.asarray(vol_loop1) + + ########################## + """ + if partial == height_c[m]: + proj_area_loop1=np.zeros(locz_size - celltop) + vol_loop1=np.zeros(locz_size - celltop) + else: + proj_area_loop1=np.zeros(locz_size -cellabove ) + vol_loop1=np.zeros(locz_size -cellabove ) + + loc0_m= -1 + for loc0 in range(locz_size-1,-1,-1): + loc0_m= loc0_m+1 + #loc_loc0 = loc_loc0 +1 + if loc0 >= celltop : + proj_area_loop1[loc0_m]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop > loc0 and loc0 >=cellabove: + proj_area_loop1[loc0_m]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 >= celltop: # full cell vol + vol_loop1[loc0_m]=(dx*dy*dz) + elif celltop > loc0 and loc0 >=cellabove: # partial cell vol + vol_loop1[loc0_m]=(dx*dy*difference) + else: + break + + + + ###################### + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + #plt.figure() + #if e1==351: + + overlap_changed_grad=np.gradient(overlap_changed) + alpha_grad=np.gradient(alpha) + + #Dcurve[m]=abs(alpha_grad/overlap_changed_grad) + + plt.plot(overlap_changed,partial_heights/height_c[m],'o-',label=str(cloud_numb[m])) + plt.title('fractional height (cut at bottom) vs. overlap') + + plt.legend(loc='upper right', bbox_to_anchor=(1.40, 1.0), fontsize='small',ncol=2) + + + + + m = m+1 + + + + overlap_c=volume_c/(height_c*projected_area_c) + + + + + + + + + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + diff --git a/scripts/percentofcloud1.py b/scripts/percentofcloud1.py new file mode 100644 index 0000000..f5bd7b4 --- /dev/null +++ b/scripts/percentofcloud1.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Feb 4 11:56:08 2019 + +@author: anthonys +""" + + + + + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +import collections + +start=time.time() + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + + + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + +######## +# when |ct-cb|<1 ra -> rashear +def rashear(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/cb + return (1+multiple*multiplicand)**(-1) + +def raanvil(grad,ht,w,ct,cb,one): + multiple=1/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return (1+multiple*multiplicand)**(-1) + +# model +def ra(grad,ht,w,ct,cb,one): + multiple=(np.maximum(abs(grad)*ht,one))/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return ((1)+multiple*multiplicand)**(-1) + + + + + +#################################### + +# script + +bomexfilenames=[bomextrack18] + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + + cbnew1=[];ctnew1=[];cbnew2=[];ctnew2=[];area_projnew1=[];area_projnew2=[]; + overlap_ratio_new1=[];overlap_ratio_new2=[];htnew1=[];htnew2=[]; + for i in range(cb.size): + if abs(ct[i]-cb[i]+1) > 5: + cbnew1.append(cb[i]) + ctnew1.append(ct[i]) + area_projnew1.append(area_proj[i]) + overlap_ratio_new1.append(overlap_ratio[i]) + htnew1.append(ht[i]) + else: + cbnew2.append(cb[i]) + ctnew2.append(ct[i]) + area_projnew2.append(area_proj[i]) + overlap_ratio_new2.append(overlap_ratio[i]) + htnew2.append(ht[i]) + + + cbnew1=np.asarray(cbnew1) + ctnew1=np.asarray(ctnew1) + cbnew2=np.asarray(cbnew2) + ctnew2=np.asarray(ctnew2) + area_projnew1=np.asarray(area_projnew1) + area_projnew2=np.asarray(area_projnew2) + overlap_ratio_new1=np.asarray(overlap_ratio_new1) + overlap_ratio_new2=np.asarray(overlap_ratio_new2) + htnew1=np.asarray(htnew1) + htnew2=np.asarray(htnew2) + + + + + + + + + + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + bins=5; + """ + for z in range(zt.size): + hist1,edges = np.histogram(nrcloud[z,:,:],bins=bins) + """ + + + nrcloudarray = np.ma.getdata(nrcloud) + cld_maskarray = np.ma.getdata(cld_mask) + """ + cloudfrac = np.empty((zt.size)) + for z in range(zt.size): + cloudfrac[z] = np.sum((nrclouddata[z,:,:]))/(xt.size*yt.size) + """ + + """ + cvlayer=np.zeros(cfrac.size) + for i in range(cfrac.size): + cvlayer[i]=cfrac[i]/(dz+1) + """ + + """ + N=[] + for i in range(xt.size): + for j in range(yt.size): + #Z=sum(nrcloudarray[:,j,i]) + #N.append(Z) + for k in range(zt.size): + if nrcloudarray[k,j,i]>0: + N.append(1) + + Narray=np.asarray(N) + S=sum(Narray) + """ + + + count1=np.count_nonzero(nrcloudarray) + count2=np.count_nonzero(cld_maskarray) + + #nrcloudarray.index(1) + #nrcloudlist=np.tolist(nrcloudarray) + #nrcloudarray.index(1) + A=np.where(nrcloudarray==158) + + + + + + + + + + + + + + + + + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + diff --git a/scripts/shear_cal1.py b/scripts/shear_cal1.py new file mode 100644 index 0000000..d40e55b --- /dev/null +++ b/scripts/shear_cal1.py @@ -0,0 +1,526 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed May 29 10:55:59 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +import matplotlib.colors as colors +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +from scipy.stats import hmean +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + +from scipy.special import comb + + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + +############################################################################# + +# definitions +#def pyth(u,v): # magnitude +# return np.sqrt(u*u+v*v) + + + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + +def shear_amod(shear,h,l): + return shear * h / l + + +#################################### + +# script + +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +#kt=0; +#file_numb=-1 +#file1_numb=-1 + + + +### rico828 +""" +height=np.load('height_no_shear_rico828.npy') +volume=np.load('volume_no_shear_rico828.npy') +projar=np.load('projarea_no_shear_rico828.npy') +overlap=np.load('overlap_no_shear_rico828.npy') +areaz=np.load('area_z_ratio_rico828.npy') +areazg=np.load('rico_area_gmean82800.npy') +overlap_convex=np.load('overlap_convex_rico82800.npy') +""" +""" +### rico2016 +height=np.load('height_no_shear_rico2016.npy') +volume=np.load('volume_no_shear_rico2016.npy') +projar=np.load('projarea_no_shear_rico2016.npy') +overlap=np.load('overlap_no_shear_rico2016.npy') +areaz=np.load('area_z_ratio_rico2016.npy') +model=np.load('model_rico2016.npy') +overlap_convex=np.load('overlap_convex_rico201600.npy') +""" + +""" +### bomex 360 +height=np.load('height_no_shear_bomex360.npy') +volume=np.load('volume_no_shear_bomex360.npy') +projar=np.load('projarea_no_shear_bomex360.npy') +overlap=np.load('overlap_no_shear_bomex360.npy') +areaz=np.load('area_z_ratio_bomex360.npy') +""" +""" +### lasso 306 +height=np.load('height_no_shear_lasso306.npy') +volume=np.load('volume_no_shear_lasso306.npy') +projar=np.load('projarea_no_shear_lasso306.npy') +overlap=np.load('overlap_no_shear_lasso306.npy') +areaz=np.load('area_z_ratio_lasso306.npy') +""" + + +""" +datad = Dataset("/data/rico/rico.default.0000000.nc","r") +zh=datad.variables['zh'][:] +time_t=datad.variables['time'][:] +u=datad.variables['u'][:,:] +v=datad.variables['v'][:,:] +w=datad.variables['w'][:,:] +""" +#################################################################### +""" +datau = Dataset('/data/rico/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/rico/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/rico/w.nc','r') +time_t = datau.variables['time'][:] +step=3600;time_array= np.arange(step,216000+step,step) +case='rico' +""" +""" +datau = Dataset('/data/bomex/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/bomex/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/bomex/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(step,36000+step,step) +case='bomex' +""" + +datau = Dataset('/data/arm/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/arm/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/arm/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(10800,52200+step,step) +case='arm' + +conditional_height=50 + +#file1_numb=-1 +begin=5 +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[begin:] +#file3_numb = np.arange(5,19+1) +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#begin=22 +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +#Bfilenames = [Afilenames[22], Afilenames[55]] +#Bfilenames = [Afilenames[22]] +#file1_numb=begin-1 ## python: arrays start at index 0 +#file3_numb = [22,55] +#file3_numb = [22] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:2] +Bfilenames = [Afilenames[10], Afilenames[17]] +file3_numb = [10,17] + +file2_numb = -1 + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + #file1_numb = file1_numb+1 + file2_numb = file2_numb+1 + file1_numb = file3_numb[file2_numb] + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + ### + access = np.where(time_t == time_array[file1_numb])[0][0] ## slicing at correct spot + u=datau.variables['u'][access,:,:,:] + xh=datau.variables['xh'][:] + v=datav.variables['v'][access,:,:,:] + yh=datav.variables['yh'][:] + w=dataw.variables['w'][access,:,:,:] + zh=dataw.variables['zh'][:] + ### + + uint=interp1d(xh,u,axis=2,fill_value='extrapolate') + vint=interp1d(yh,v,axis=1,fill_value='extrapolate') + wint=interp1d(zh,w,axis=0,fill_value='extrapolate') + + ut=uint(xt) + vt=vint(yt) + wt=wint(zt) + + #w=interp1d(zh,w,axis=0,fill_value='extrapolate') + #ut=u;vt=v;#wt=w; + + + ut1=np.sum(np.sum(ut,axis=1),axis=1)/(nx*ny) + vt1=np.sum(np.sum(vt,axis=1),axis=1)/(nx*ny) + #ut1=np.mean(np.mean(ut,axis=1),axis=1) + #vt1=np.mean(np.mean(vt,axis=1),axis=1) + #wt1=np.mean(np.mean(wt,axis=1),axis=1) + + + uz=ut1 + vz=vt1 + #wz=wt1 + + """ + ### Bomex + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + areazg=np.load('Bomex_area_gmean.npy') + overlap_convex=np.load('Bomex_hull.npy') + print('Bomex') + """ + + l=cv**0.5 + + + + + + #uz=np.mean(u,axis=0) # avg among diff times + #vz=np.mean(v,axis=0) # avg among diff times + shear_calu=np.zeros(cb.size) + shear_calv=np.zeros(cb.size) + """ + for i in range(cb.size): + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + """ + + + #shear_cal = np.sqrt( shear_calu**2 + shear_calv**2 ) + #shear_cal = abs(shear_calu + shear_calv) / 2 + + + + ############################## + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + + + #s_u=abs(duz);s_v=abs(dvz) + s_u=duz;s_v=dvz; + + #Gmean=(s_u*s_v)**(0.5) + Amean=(s_u+s_v)/2;#Amean=abs(Amean) + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v);#Hmean=abs(Hmean) + pyth= (s_u**2 + s_v**2)**0.5 + + shear0=np.zeros(cb.size) + shear00=np.zeros(cb.size) + w_cld=np.zeros(cb.size) + for i in range(cb.size): #### wind differential + + #shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + shear00[i] = sum(Amean[cb[i]:ct[i]+1]) + + shear_calu[i] = (uz[ct[i]] - uz[cb[i]]) + shear_calv[i]= (vz[ct[i]] - vz[cb[i]]) + + shear_cal = abs(shear_calu + shear_calv) / 2 + + ####################### + #shear= (1/overlap_ratio) - (1/overlap) ### overlap form shear + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + ll = np.zeros(index1_size) + shear1_cal = np.zeros(index1_size) + shear2_cal = np.zeros(index1_size) + shear3_cal = np.zeros(index1_size) + w_avg = np.zeros(index1_size) + shear_overlap=np.zeros(index1_size) + + C_true_bar = np.zeros(index1_size) + alpha_overlap = np.zeros(index1_size) + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + + wz_max = np.zeros(index1_size) + wz_cb = np.zeros(index1_size) + wz_ct = np.zeros(index1_size) + wz_avg = np.zeros(index1_size) + wz_min = np.zeros(index1_size) + m=-1; #m=0; + + + #### calculating updraft + for e1 in cloud_numb: # may take a while to run + + m = m+1 + + ll[m]=l[e1-1] + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + + loc_mat_tran=np.matrix.transpose(location_matrix) + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + base=np.amin(location[0]);top=np.amax(location[0]); + z_array = np.arange(base, top+1,1) + ########### + ### shear + basez=base;topz=top;basey=min(location[1]);topy=max(location[1]);basex=min(location[2]);topx=max(location[2]); + w_abs=abs(wt) + #wz_avg=np.sum(w_abs[basez:topz+1,:,:],axis=0) / (topz - basez+1) # maybe avoid avg along z axis? use max up vel along z to get singl # + #wy_avg=np.sum(wz_avg[basey:topy+1,:],axis=0) / (topy - basey+1) + #wx_avg=np.sum(wy_avg[basex:topx+1],axis=0) / (topx - basex+1) + ##wz_avg=np.mean(w_abs[min(location[0]):max(location[0])+1,:,:],axis=0) + ##wy_avg=np.mean(wz_avg[min(location[1]):max(location[1])+1,:],axis=0) + ##wx_avg=np.mean(wy_avg[min(location[2]):max(location[2])+1],axis=0) + + wy_avg=np.sum(w_abs[:,basey:topy+1,:],axis=1) / (topy - basey+1) + wx_avg=np.sum(wy_avg[:,basex:topx+1],axis=1) / (topx - basex+1) + wz = wx_avg[basez:topz+1] + + wz_max[m] = np.amax(wz) + wz_cb[m] = wz[0] + wz_ct[m] = wz[-1] + wz_avg[m] = np.mean(wz) + wz_min[m] = np.amin(wz) + + + #w_avg[m]=wx_avg + #print(w_avg[m]) + + + + #shear1_cal[m]= shear_cal[e1-1]/ w_avg[m] ###shear_cal + + #shear2_cal[m] = shear0[e1-1] / w_avg[m] ### shearh + + #shear3_cal[m] = shear00[e1-1] / w_avg[m] ###sheara + #print(shear1_cal) + + + #shear_overlap[m] = shear[e1-1] + ######################### + ### hogan ,illington + """ + area_layer = np.zeros(z_array.size) + for z in z_array: + area_layer[z-base] = dx*dy*len(np.where( z == location[0] )[0]) + + + C_max = np.zeros(int(comb(z_array.size,2))) + C_rand = np.zeros(int(comb(z_array.size,2))) + C_true = np.zeros(int(comb(z_array.size,2))) + alpha_a = np.zeros(int(comb(z_array.size,2))) + loc_a_1 = -1 + for c_area1 in area_layer: + loc_a_1 = loc_a_1 + 1 + loc_a_2 = - 1 + for c_area2 in area_layer: + loc_a_2 = loc_a_2 + 1 + if loc_a_1 != loc_a_2: + dzed = dz*abs(loc_a_1 - loc_a_2) + C_max[loc_a_2] = max(c_area1,c_area2) + C_rand[loc_a_2] = c_area1 + c_area2 - c_area1*c_area2 + alpha_a[loc_a_2] = np.exp(-dzed / 200 ) + C_true[loc_a_2] = alpha_a[loc_a_2]*C_max[loc_a_2] + (1-alpha_a[loc_a_2])*C_rand[loc_a_2] + + #C_max_bar = np.mean(C_max) + #C_rand_bar = np.mean(C_rand) + C_true_bar[m] = np.mean(C_true) + alpha_overlap[m] = np.exp(-dz*layers / 200) + """ + + ################################################### + """ + fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + shear[shear<0]=0 + + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + + f_t=f_turb(ht,175); f_t[ht<=100]=0 + f_s=f_shear(ht/l,0.43);f_s[ht/l<=1]=0 + f_a=f_area(ht/l,0.2);f_a[ht/l<=1]=0 + + #r_total = f_t + f_s + f_a +1 + + ################################################## + """ + ################################ + ### saving data + """ + #step=1800 # 30*60 + #time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + #case='bomex' + + + name1='shearTB_' + name2='shear_sum_' + #name3='wavg1_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',shear_cal) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',shear00) + #np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',w_avg) + + name1='wz_max_' + name2='wz_min_' + name3='wz_avg_' + name4='wz_ct_' + name5='wz_cb_' + + + np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',wz_max) + np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',wz_min) + np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',wz_avg) + np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',wz_ct) + np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',wz_cb) + """ + ############################# + +############################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripts/shear_center_of_mass1.py b/scripts/shear_center_of_mass1.py new file mode 100644 index 0000000..f6f0316 --- /dev/null +++ b/scripts/shear_center_of_mass1.py @@ -0,0 +1,584 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Apr 4 11:47:11 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') + +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') +bomextrack234 = Dataset('/data/bomex/l.0023400.track.nc','r') +bomextrack252 = Dataset('/data/bomex/l.0025200.track.nc','r') +bomextrack270 = Dataset('/data/bomex/l.0027000.track.nc','r') +bomextrack288 = Dataset('/data/bomex/l.0028800.track.nc','r') +bomextrack306 = Dataset('/data/bomex/l.0030600.track.nc','r') +bomextrack324 = Dataset('/data/bomex/l.0032400.track.nc','r') +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + + + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + + +lassotrack306 = Dataset('/data/lasso/sims/20160611_micro/l.0030600.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script +filenames=[bomexd] +ricofilenames=[ricotrack2016] +bomexfilenames=[bomextrack216,bomextrack234,bomextrack252,bomextrack270,bomextrack288,bomextrack306,bomextrack324,bomextrack342,bomextrack360] +armfilenames=[armtrack522] +lassofilenames=[lassotrack306] +conditional_height=0 +epsilon1=50 #arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +conditional_height=0 + +file1_numb=-1 + +begin=5 +### accessing multiple datasets easily +Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +Bfilenames = Afilenames[begin:] +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#Bfilenames = Afilenames[22:23] + +file1_numb=begin-1 + +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + m=0; + + alpha=np.arange(1,0,-1) # just 1 + #alpha=np.arange(1,0.35,-0.1) # fraction + #alpha=np.array([0.7,0.5,0.3,0.1]) + + #Dist=np.zeros((cloud_numb.size , alpha.size -1)) + #Dcurve=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve2=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + #Dcurve3=np.zeros((cloud_numb.size,alpha.size)) # multi dimensional array + + #Total_dr=np.zeros((cloud_numb.size,alpha.size -1)) # multi dimensional array + #mu=np.zeros(cloud_numb.size) + #sigma=np.zeros(cloud_numb.size) + #Keeptrack_tdr=np.zeros((cloud_numb.size,3)) #make abitrarily big + #alpha_matrix=np.zeros((cloud_numb.size,alpha.size)) + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + + for e1 in cloud_numb: # may take a while to run + + + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + #layers=height/dz + ### + + base=np.amin(location[0]);top=np.amax(location[0]); + #levels=range(base,top+1,1) + + x_unique=np.unique(location[2]) + y_unique=np.unique(location[1]) + xtest1=abs(np.mean(x_unique)-np.median(x_unique)) # median is resistant while mean is not + ytest1=abs(np.mean(y_unique)-np.median(y_unique)) + + #xtest1=abs(np.mean(location[2])-np.median(location[2])) + #ytest1=abs(np.mean(location[1])-np.median(location[1])) + #x_small=np.extract(location[2] < 512,location[2]) + #x_large=np.extract(x_unique > 512,x_unique) + #y_small=np.extract(y_unique < 512,y_unique) + #y_large=np.extract(y_unique > 512,y_unique) + + if xtest1 > epsilon1: + splitx=np.where(location[2] < 512) + location[2][splitx] = location[2][splitx] + nx + + if ytest1 > epsilon1: + splity=np.where(location[1] < 512) + location[1][splity] = location[1][splity] + ny + + + #sys.exit("Error message") + + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + COM=np.zeros((top-base+1,3)) + newlocation_matrix=np.zeros(location_matrix.shape) + cross_area_z=np.zeros(int(layers)) + #u, indices = np.unique(location[0], return_index=True) + #COM[:,0]=u + + + + + + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + # height / dz = layers + + + #COM[z-base,:]=[z,sum(location[1][findz[0]])/findz[0].size, sum(location[2][findz[0]])/findz[0].size] + COM[z-base,:]=[z,np.mean(location[1][findz[0]]), np.mean(location[2][findz[0]])] #find center of mass w/ arithmetic mean + ### not quite (close) + """ + if z0: + difference = partial - dz*(location[0][celltop]-location[0][0]+1) # diff btw chopped cld ht and ht of clds w/ full cells + #print(difference == 0 ) + #print(difference) + for j in range(celltop,location[0].size): + if location[0][celltop] +1 == location[0][j]: # to use partial cells + cellabove=j + elif location[0][celltop] +1 < location[0][j]: + break + #print('partial',partial) + #print('top',celltop) + #print('above',cellabove) + #loc_loc0=-1 + if partial == height_c[m]: # difference=0, so stop at celltop + proj_area_loop1=np.zeros(celltop +1) + vol_loop1=np.zeros(celltop +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:celltop+1],dz*location[0][0:celltop+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + """ + ### plotting in cld in 3d + + fig = plt.figure() + ax = plt.axes(projection='3d') + ax.scatter3D(dx*location[2][0:celltop+1],dy*location[1][0:celltop+1], dz*location[0][0:celltop+1], c=dz*location[0][0:celltop+1] ,cmap='Paired'); + #cmap= single color:copper, cool, winter, multicolor: Dark2, Paired + #ax.plot_trisurf(location[2], location[1], location[0], cmap='viridis', edgecolor='none'); + plt.title(str(cloud_numb[m])) + plt.show() + """ + + else: + proj_area_loop1=np.zeros(cellabove +1) + vol_loop1=np.zeros(cellabove +1) + + """ + ##### 2d plot of cld + bins=dz + plt.figure() + plt.hist2d(dx*location[2][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('x');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.figure() + plt.hist2d(dy*location[1][0:cellabove+1],dz*location[0][0:cellabove+1],bins=bins,cmin=0.5) + plt.xlabel('y');plt.ylabel('z') + plt.title( 'Cloud Number %s with height %.f m'%(cloud_numb[m],partial)) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + + + for loc0 in range(location[0].size): + + #loc_loc0 = loc_loc0 +1 + if loc0 <= celltop : + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + elif celltop < loc0 and loc0 <=cellabove: + proj_area_loop1[loc0]=(location[2][loc0]+location[1][loc0]*nx) + if loc0 <= celltop: # full cell vol + vol_loop1[loc0]=(dx*dy*dz) + elif celltop < loc0 and loc0 <=cellabove: # partial cell vol + vol_loop1[loc0]=(dx*dy*difference) + else: + break + #if dz*loc0 < parital: + #proj_area_loop1=np.asarray(proj_area_loop1) + #print('loop1',proj_area_loop1.size) + projected_area_changed[part_loc]=dx*dy*len(np.unique(proj_area_loop1)) # counting cells w/ ! id # & proj-ing + #vol_loop1=np.asarray(vol_loop1) + vol_changed[part_loc]=sum(vol_loop1) + overlap_changed[part_loc]=vol_changed[part_loc]/(partial_heights[part_loc]*projected_area_changed[part_loc]) + if partial == height_c[m]: + overlap_c[m]=overlap_changed[part_loc] # make sure calculated overlap is correct for full ht + volume_c[m]=vol_changed[part_loc] + projected_area_c[m]=projected_area_changed[part_loc] + + + ### dist btw adjacent pts + #if part_loc>0: + # Dist[m,part_loc-1]= np.sqrt( (alpha[part_loc]-alpha[part_loc-1])**2 + (overlap_changed[part_loc]-overlap_changed[part_loc-1])**2 ) + + + ###derivative at each pt + #vol_grad=np.gradient(vol_changed) + #projA_grad=np.gradient(projected_area_changed) + #ht_grad=np.gradient(partial_heights) + #Dcurve2[m]=(vol_grad/volume_c[m])-(ht_grad/height_c[m])-(projA_grad/projected_area_c[m]) + #overlap_changed_grad=np.gradient(overlap_changed) + #alpha_grad=np.gradient(alpha) + #Dcurve[m]=alpha_grad/overlap_changed_grad + #Dcurve3[m]=np.gradient(alpha/overlap_changed) + """ + ## calculates change in r of a cld + dr=np.zeros(alpha.size -1) + for i in range(alpha.size -1 ) : + dr[i]= overlap_changed[i+1] - overlap_changed[i] # having abs lowers the high pt of the interval + Total_dr[m,i]=dr[i] + + """ + """ + alpha_matrix[m,:]=alpha + overlap_changed_matrix[m,:]=overlap_changed + Keeptrack_tdr[kt,:]=[file_numb,file1_numb,e1] + kt=kt+1 + """ + """ + mu[m]=np.mean(dr) + sigma[m]=np.std(dr) + + ### prints index of matrix where change in r is outside the confidence interval + for i in range(alpha.size -1 ): + if abs(Total_dr[m,i]) >= mu[m]+1.96*sigma[m]: + print('index',(m,i)) #remeber indices start at zero + """ + ###putting alpha = partial_heights / height_c[m] b/c partial_heights = alpha * height_c[m] + #plt.plot(overlap_changed,alpha,'o-',label=str(cloud_numb[m])) + #plt.title('normalized height vs. overlap') + + #plt.plot(alpha,overlap_changed,'o-',label=str(cloud_numb[m])) + #plt.title('overlap vs. normalized height ') + #plt.xlim([1,0.2]) + + + + #plt.legend(loc='upper right', bbox_to_anchor=(1.40, 1.0), fontsize='small',ncol=2) + + + + + + + + m = m+1 + + #mu1=np.mean(Total_dr) + #sigma1=np.std(Total_dr) + #Check1=[Total_dr >= mu1 + 1.96 *sigma1] + + overlap_c=volume_c/(height_c*projected_area_c) + + ################################ + ### + """ + + + step=1800 # 30*60 + time_array= np.arange(10800,36000+step,step) + npyfilespath ="/home/anthonys/Documents/" + case='bomex' + + + name1=overlap_no_shear_ + name2=volume_no_shear_ + name3=projarea_no_shear_ + name4=height_no_shear_ + name5=aera_z_ratio_ + + #step=3600 # 60*60 + #time_array= np.arange(10800,216000+step,step) + #npyfilespath ="/home/anthonys/Documents/" + #case=rico + + ### + #np.save(npyfilespath+ name1 + case +str(time_array[file1_numb])+'.npy',overlap_c) + #np.save(npyfilespath+ name2 + case +str(time_array[file1_numb])+'.npy',volume_c) + #np.save(npyfilespath+ name3 + case +str(time_array[file1_numb])+'.npy',projected_area_c) + #np.save(npyfilespath+ name4 + case +str(time_array[file1_numb])+'.npy',height_c) + #np.save(npyfilespath+ name5 + case +str(time_array[file1_numb])+'.npy',area_z_ratio_c) + + + #np.save(npyfilespath+str(time_array[20])+'.npy',area_z_ratio) + ### need to fix saving + """ + + ########################### + + +plt.plot(overlap_c,overlap_ratio,'o') +plt.plot(overlap_c,overlap_c) +#plt.title('Actual Overlap vs. Adjusted Overlap') +plt.title('Actual Overlap vs. Overlap with no shear') + + + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/shift_cld1.py b/scripts/shift_cld1.py new file mode 100644 index 0000000..cb700c3 --- /dev/null +++ b/scripts/shift_cld1.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jun 14 12:35:46 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from numpy import percentile +#import overlap_calculation +import sys + +from scipy.stats import spearmanr + + +start=time.time() + + + +############################################################### + + + + + +epsilon1=50 ##### helps find clds that are split by grid box +#arbitrarily set, most outliers are > 200, most nonoutliers clds are about 0 + +#file1_numb=-1 + +""" +datau = Dataset('/data/rico/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/rico/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/rico/w.nc','r') +time_t = datau.variables['time'][:] +step=3600;time_array= np.arange(step,216000+step,step) +case='rico' +""" +""" +datau = Dataset('/data/bomex/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/bomex/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/bomex/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(step,36000+step,step) +case='bomex' +""" +""" +datau = Dataset('/data/lasso/sims/20160830/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/lasso/sims/20160830/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/lasso/sims/20160830/w.nc','r') +""" + +datau = Dataset('/data/arm/u.nc','r') +#u=datau.variables['u'][:,:,:,:] +datav = Dataset('/data/arm/v.nc','r') +#v=datav.variables['v'][:,:,:,:] +dataw = Dataset('/data/arm/w.nc','r') +time_t = datau.variables['time'][:] +step=1800;time_array= np.arange(10800,52200+step,step) +case='arm' + + +conditional_height=50 +#file1_numb=-1 +begin=5 +### accessing multiple datasets easily +#Afilenames = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[begin:] +#file3_numb = np.arange(5,19+1) +#Afilenames = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +#begin=22 +#Bfilenames = Afilenames[22:23] +#Bfilenames = Afilenames[55:56] +#Bfilenames = [Afilenames[22], Afilenames[55]] +#Bfilenames = [Afilenames[22]] +#file1_numb=begin-1 ## python: arrays start at index 0 +#file3_numb = [22,55] +#file3_numb = [22] +Afilenames = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:2] +Bfilenames = [Afilenames[10], Afilenames[17]] +file3_numb = [10,17] + +file2_numb = -1 + + +############################# +#### loop over trackfiles +for file1 in Bfilenames: + print(file1) + + data = Dataset(file1,'r') + + file2_numb = file2_numb+1 + file1_numb = file3_numb[file2_numb] + + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + #index1=np.where( (400 < ht) & (ht < 500)) + index1=np.where(ht > conditional_height) # indices of where condition holds true in ht vector + index1_size=index1[0].size + ht=ht[index1[0]] # taking the ht values according to indices above + overlap_ratio=overlap_ratio[index1[0]]; + area_proj=area_proj[index1[0]] + print('Clouds that satisfy the given condition: ',index1_size) + print('conditional height is',conditional_height,'meters') + + + cloud_numb=index1[0] +1 # index is off by 1 as array starts with zero + + height_c=np.zeros(cloud_numb.size) + overlap_c=np.zeros(cloud_numb.size) + projected_area_c=np.zeros(cloud_numb.size) + volume_c=np.zeros(cloud_numb.size) + m=-1; + + alpha=np.arange(1,0,-1) # just 1 + + + + overlap_changed_matrix=np.zeros((cloud_numb.size,alpha.size)) + area_z_ratio=np.zeros(cloud_numb.size) + shift_max=np.zeros(cloud_numb.size) + shift_min=np.zeros(cloud_numb.size) + shift_avg=np.zeros(cloud_numb.size) + shift_distance=np.zeros(cloud_numb.size) + + for e1 in cloud_numb: # may take a while to run + + m=m+1 + location=np.where(nrcloudarray == e1) # location of all cells with cloud # e1 + layers=(np.amax(location[0]) - np.amin(location[0]) + 1) # height along z + #layers=height/dz + ### + + base=np.amin(location[0]);top=np.amax(location[0]); + #levels=range(base,top+1,1) + + x_unique=np.unique(location[2]) + y_unique=np.unique(location[1]) + xtest1=abs(np.mean(x_unique)-np.median(x_unique)) # median is resistant while mean is not + ytest1=abs(np.mean(y_unique)-np.median(y_unique)) + + #xtest1=abs(np.mean(location[2])-np.median(location[2])) + #ytest1=abs(np.mean(location[1])-np.median(location[1])) + #x_small=np.extract(location[2] < 512,location[2]) + #x_large=np.extract(x_unique > 512,x_unique) + #y_small=np.extract(y_unique < 512,y_unique) + #y_large=np.extract(y_unique > 512,y_unique) + + if xtest1 > epsilon1: + splitx=np.where(location[2] < 512) + location[2][splitx] = location[2][splitx] + nx + + if ytest1 > epsilon1: + splity=np.where(location[1] < 512) + location[1][splity] = location[1][splity] + ny + + + #sys.exit("Error message") + + + location_matrix=np.zeros((location[0].size,3)) + location_matrix[:,0]=location[0] # z coor + location_matrix[:,1]=location[1] # y coor + location_matrix[:,2]=location[2] # x coor + COM=np.zeros((top-base+1,3)) + newlocation_matrix=np.zeros(location_matrix.shape) + cross_area_z=np.zeros(int(layers)) + #u, indices = np.unique(location[0], return_index=True) + #COM[:,0]=u + + + for z in np.arange(base,top+1,1): + findz=np.where(location[0] == z) + cross_area_z[z-base]=dx*dy*len(findz[0]) + # height / dz = layers + + + #COM[z-base,:]=[z,sum(location[1][findz[0]])/findz[0].size, sum(location[2][findz[0]])/findz[0].size] + COM[z-base,:]=[z,np.mean(location[1][findz[0]]), np.mean(location[2][findz[0]])] #find center of mass w/ arithmetic mean + ### not quite (close) + """ + if z0] +turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) +turb[turb<0]=0 +fractalf[ht>100]=turb + + +## upper bound to turb +lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi +#C1=np.argwhere((1/overlap_ratio)>1.5*lam) +keep=np.argwhere(fractalf > lam) +fractalf[np.array(keep)] = lam + + +##fractalf = np.minimum(1.5*lam*np.ones(overlap_ratio.size),1/overlap_ratio) -1 ### trying only 3d Koch overpredicts + +#fractalf = np.minimum(((3*np.pi) / 4)*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + +#fractalf = np.minimum( (3*np.pi /4)*np.ones(overlap_ratio.size), 1/overlap_ratio ) +#fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) + +""" +fractal_ones=fractal*np.ones(overlap_ratio.size) +r_fractal= np.minimum(1/fractal_ones,1/overlap_ratio) +r_total = ( (1/(overlap)) + (1/areaz) + (r_fractal) ) -3 # correction: need to subtract 1 from each + +plt.figure() +plt.plot(r_fractal,1/overlap_ratio,'o') +plt.plot(np.arange(0,3,1),'k',linewidth=3) +plt.xlim(left=0) +plt.ylim(bottom=0) +""" + +#shape = 1 / np.exp( -ht/200 ) - 1 + +#r_total = ( (1/(overlap)) + (1/areaz) + (fractal) ) +#r_total = ( (shear) + (shape) + (fractalf) ) +1 + +#updraft_cb=np.mean(wz_cb)*np.zeros(ht.size) +#updraft_cb[ht>50] = wz_cb +#updraft_max=np.mean(wz_cb)*np.zeros(ht.size) +#updraft_max[ht>50] = wz_cb + + +FF = f_turb(ht,200);FF[ht<=100]=0; +shear_sum = abs(shear_sum) +shift_d = np.zeros(ht.size) +shift_d[ht>50] = shift_distance + +shift_d = shift_d + shape*cp**0.5/2 ### draw the picture +updraft = (shear_sum*ht)/shift_d +FS = (shear_sum*ht)/(updraft*cp**0.5) +FS[updraft<0.1] = 0 + +#shear = FS ; fractalf = FF + +r_total = ( (shear) + (shape) + (fractalf) ) +1 + +horizontal= r_total +vertical= 1/overlap_ratio + + +bins=dz; +cmin=10 +### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico +plt.figure(); +HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) +plt.plot(line,'k',linewidth=3) +#plt.plot(ht,FF,'ko') + +#plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) +#plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + +plt.title('Effect of All Contributors'); +#plt.title('Effect of Shear'); +#plt.title('Effect of Area Variability'); +#plt.title('Effect of Shear, Area Var.'); +#plt.title('Effect of Turbulence'); +#plt.title('Relating Overlap and Height'); +#plt.title('Overlap from Shear') +#plt.title('Overlap from Turbulence') + + +plt.xlabel('Calculated Overlap') +plt.ylabel('Actual Overlap') +#plt.xlabel('Numerical Overlap') +#plt.ylabel('Overlap from Eqn') +#plt.xlabel('Cloud Height') +#plt.ylabel('Calculated Overlap') + +#colorbar=plt.colorbar(extend='both'); +colorbar=plt.colorbar() +colorbar.set_label('count in bin') +#plt.clim(0,200) + +#plt.xlim([0,1]) +#plt.ylim([0,1]) +#plt.xlim(left=0) +#plt.ylim(bottom=0) +plt.xlim([0,14]) +plt.ylim([0,14]) #use cmin=5 +#plt.loglog(horizontal,vertical,'o') + + + + +#plt.savefig('arm41400_total_emp1_r_061719.eps', dpi=300,bbox_inches='tight') + +################################################################################### +binwidth=0.1 +###prob plot, histogram ,line plot +plt.figure() +#ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=10,density=True);#,log=True); # may want to use one w/ log & one standard +ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=np.arange(min(r_total*overlap_ratio), max(r_total*overlap_ratio) + binwidth, binwidth),density=True); +plt.yticks(np.arange(0,10,2)) + +""" +#plt.figure() +bincenters = 0.5*(binEdges[1:]+binEdges[:-1]) +plt.plot(bincenters,ybin,'k-',linewidth=2) +""" +plt.title('Accuracy of Model') +plt.xlabel('Relative Effect') +plt.ylabel('Probability Density') + + +#plt.savefig('arm41400_rel_effect_061119.eps', dpi=300,bbox_inches='tight') + +############################# +""" +plt.figure() +plt.hist2d(ht,vertical-horizontal,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis', norm=colors.LogNorm()); + +plt.plot(ht,np.zeros(ht.size),'k',linewidth=3) + + +plt.xlabel('Cloud Height') +plt.ylabel('Residual') + +colorbar=plt.colorbar() +colorbar.set_label('count in bin') +""" +################################################ + +""" +plt.figure() +# Density Plot and Histogram +sns.distplot(r_total*overlap_ratio, hist=True, kde=False, + bins=int(10), color = 'darkblue', + hist_kws={'edgecolor':'black'}, + kde_kws={'linewidth': 2}) +""" + +#plt.figure() +#sns.distplot(r_total*overlap_ratio) + + + +################################################################################## +""" +binwidth=500000 +###prob plot, histogram ,line plot +plt.figure() +horiz = (1/overlap) * cv +#ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=10,density=True);#,log=True); # may want to use one w/ log & one standard +ybin, binEdges, patches =plt.hist(horiz,bins=np.arange(min(horiz), max(horiz) + binwidth, binwidth),density=False); +#plt.yticks(np.arange(0,10,2)) + + +plt.title('Calculated Cloud Cover') +#plt.xlabel('Relative Effect') +#plt.ylabel('Probability Density') + + +cld_cover= sum(ybin*binwidth) +print(cld_cover) +""" +######################################################################################## +""" +plt.figure() + +plt.plot((1/overlap)-1,(1/overlap_ratio),'ob',label='Shear') +#plt.plot(line) +plt.plot((1/overlap)+(1/areaz)-2,(1/overlap_ratio),color='purple',marker='o',linestyle='none',label='Shear and Shape') +plt.plot((1/overlap)+(1/areaz)+(1/fractal)-3,(1/overlap_ratio),color='pink',marker='o',linestyle='None',label='Shear, Shape, and Fractal') +plt.plot(np.arange(0,10,1),'k',linewidth=3) +plt.xlabel('Inverse Calculated Overlap') +plt.ylabel('Inverse Actual Overlap') +plt.title('Inverse Overlap due to Contributions') +plt.legend(loc='lower right', bbox_to_anchor=(1.10, 0.0),fontsize='small',ncol=1) +#plt.savefig('rico2016_contributions_041619.eps', dpi=300, bbox_inches='tight') +""" +""" +plt.figure() +plt.subplot(2,2,1) +plt.hist2d(1/overlap -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.subplot(2,2,2) +plt.hist2d( 1/areaz -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) + +plt.subplot(2,2,3) +plt.hist2d(1/np.ones(overlap_ratio.size)*fractal -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) + +plt.subplot(2,2,4) +plt.hist2d(1/overlap + 1/areaz + 1/fractal -3,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +""" +################################################### +##subplots +""" +plt.figure() +fig, ax = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(9, 4));None + +plt.subplot(1,3,1) +plt.hist2d(1/overlap -1,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.clim(0,200) +plt.xlim(left=0) +plt.ylim(bottom=0) +plt.title('Shear') + +plt.subplot(1,3,2) +plt.hist2d( 1/overlap + 1/areaz -2,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.clim(0,200) +plt.xlim(left=0) +plt.ylim(bottom=0) +plt.title('Shear,Area') + +plt.subplot(1,3,3) +plt.hist2d(1/overlap + 1/areaz + 1/fractal -3,1/overlap_ratio,bins=bins,cmin=2,cmap='viridis'); +plt.plot(line,'k',linewidth=3) +plt.clim(0,200) +plt.xlim(left=0) +plt.ylim(bottom=0) +plt.title('All') + +#plt.suptitle('Inverse Overlap'); +colorbar=plt.colorbar(extend='both'); +colorbar.set_label('count in bin') +plt.clim(0,200) +fig.text(0.5, 0.004, 'Inverse Calculated Overlap', ha='center') +fig.text(0.06, 0.5, 'Inverse Actual Overlap', va='center', rotation='vertical') + +#plt.xlabel('Inverse Calculated Overlap') +#plt.ylabel('Inverse Actual Overlap') +#plt.xlim([0,1]) +#plt.ylim([0,1]) + + +#plt.savefig('rico2016_subplot_invoverlap_042219.eps', dpi=300, bbox_inches='tight') +""" +############################ +""" +plt.figure() + +plt.figure(); +plt.hist2d(1/overlap -1, 1/overlap_ratio,bins=bins,cmin=2,cmap='pink',alpha=0.3); #norm=colors.LogNorm(), normed: normalizes data +plt.hist2d(1/overlap + 1/areaz -2, 1/overlap_ratio,bins=bins,cmin=2,cmap='bone',alpha=0.3); +plt.hist2d(1/overlap -1 + 1/areaz + 1/fractal -3, 1/overlap_ratio,bins=bins,cmin=2,cmap='Blues',alpha=0.3); +#plt.plot(horizontal,horizontal) +#plt.plot(vertical,vertical) +plt.plot(line,'k',linewidth=3) +#plt.title('Actual Overlap vs. Area Ratio'); +plt.title('Inverse Overlap'); +colorbar=plt.colorbar(extend='both'); +colorbar.set_label('count in bin') +plt.clim(0,200) +plt.xlabel('Inverse Total Calculated Overlap') +plt.ylabel('Inverse Actual Overlap') +""" + +""" +plt.figure() +plt.scatter(1/overlap -1, 1/overlap_ratio,cmap='pink',alpha=0.3) +plt.scatter(1/overlap + 1/areaz -2, 1/overlap_ratio,cmap='bone',alpha=0.3); +plt.scatter(1/overlap -1 + 1/areaz + 1/fractal -3, 1/overlap_ratio,cmap='Blues',alpha=0.3); +plt.plot(np.arange(0,10,1),'k',linewidth=3) +""" + + + + + + + + + + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/tempfile2.py b/scripts/tempfile2.py new file mode 100644 index 0000000..38c821f --- /dev/null +++ b/scripts/tempfile2.py @@ -0,0 +1,1157 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jun 19 10:33:32 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +import matplotlib.colors as colors +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import seaborn as sns +from scipy import stats +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile +from scipy.stats import spearmanr +from scipy.stats import kendalltau +#import overlap_calculation + +plt.rcParams.update({'font.size': 16}) + +start=time.time() + + + +########################################################################### + +#### definitions +def f_turb(h,parm): + return (3*np.pi /4)* (h/(parm+h)) + +def f_shear(aspect,parm): + return parm*aspect**1 + +def f_area(aspect,parm): + return parm*aspect**1 + +def f_dsdz(aspect,shear): + return shear*aspect + +#################################### + + + +conditional_height=0 + +file1_numb=-1 + +### accessing multiple datasets easily +Afilenames2 = sorted(glob.glob('/data/bomex/*.track.nc')) +#Bfilenames = Afilenames[5:] +Afilenames0 = sorted(glob.glob('/data/rico/*.track.nc')) +#Bfilenames = Afilenames[7:] +Bfilenames = Afilenames0[22:23] +#Bfilenames = Afilenames[55:56] +Afilenames1 = sorted(glob.glob('/data/arm/*.track.nc')) +#Bfilenames = Afilenames[1:] +#Bfilenames = Afilenames[10:11] +#Bfilenames = Afilenames[17:18] +Cfilenames0 = [Afilenames0[22:23] , Afilenames0[55:56], Afilenames1[10:11], Afilenames1[17:18], Afilenames2[5:6]] + +#Zfilenames = [Afilenames0,Afilenames1,Afilenames2] + +m0=-1 + +for file1 in Cfilenames0: + m0=m0+1 + file1=file1[0] + print(file1) + + data = Dataset(file1,'r') + + file1_numb = file1_numb+1 + + ht=data.variables['ht'][:] + cb=data.variables['cb'][:] + ct=data.variables['ct'][:] + cv=data.variables['cv'][:] + cp=data.variables['cp'][:] + overlap_ratio=data.variables['chr'][:] + area_proj=data.variables['area_proj'][:] + nrcloud=data.variables['nrcloud'][:,:,:] + cfrac=data.variables['cfrac'][:] + zt=data.variables['z'][:] + xt=data.variables['x'][:] + yt=data.variables['y'][:] + nr=data.variables['nr'][:] + cld_mask=data.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + if m0 == 0: + height=np.load('height_no_shear_rico828.npy') + volume=np.load('volume_no_shear_rico828.npy') + projar=np.load('projarea_no_shear_rico828.npy') + overlap=np.load('overlap_no_shear_rico828.npy') + areaz=np.load('area_z_ratio_rico828.npy') + areazg=np.load('rico_area_gmean82800.npy') + overlap_convex=np.load('overlap_convex_rico82800.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_rico82800.npy') + shearTB = np.load('shearTB_rico82800.npy') + shear_sum = np.load('shear_sum_rico82800.npy') + wz_max = np.load('wz_max_rico82800.npy') + wz_cb = np.load('wz_cb_rico82800.npy') + shift_distance = np.load('shift_distancerico82800.npy') + cmin=3 + + elif m0==1: + height=np.load('height_no_shear_rico2016.npy') + volume=np.load('volume_no_shear_rico2016.npy') + projar=np.load('projarea_no_shear_rico2016.npy') + overlap=np.load('overlap_no_shear_rico2016.npy') + areaz=np.load('area_z_ratio_rico2016.npy') + model=np.load('model_rico2016.npy') + model_inv=np.load('model_inv_rico2016.npy') + model_opt=np.load('model_opt_rico2016.npy') + model_opt2=np.load('model_opt2_rico2016.npy') + overlap_convex=np.load('overlap_convex_rico201600.npy') + wavg1 = np.load('wavg1_rico201600.npy') + shearTB = np.load('shearTB_rico201600.npy') + shear_sum = np.load('shear_sum_rico201600.npy') + shift_distance = np.load('shift_distancerico201600.npy') + cmin=3 + + elif m0 ==2: + height=np.load('height_no_shear_arm28800.npy') + volume=np.load('volume_no_shear_arm28800.npy') + projar=np.load('projarea_no_shear_arm28800.npy') + overlap=np.load('overlap_no_shear_arm28800.npy') + areaz=np.load('area_z_ratio_arm28800.npy') + overlap_convex=np.load('overlap_convex_arm28800.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_arm28800.npy') + shearTB = np.load('shearTB_vel_arm28800.npy') + shear_sum = np.load('shear_sum_arm28800.npy') + shift_distance = np.load('shift_distancearm28800.npy') + cmin=3 + + elif m0==3: + height=np.load('height_no_shear_arm41400.npy') + volume=np.load('volume_no_shear_arm41400.npy') + projar=np.load('projarea_no_shear_arm41400.npy') + overlap=np.load('overlap_no_shear_arm41400.npy') + areaz=np.load('area_z_ratio_arm41400.npy') + overlap_convex=np.load('overlap_convex_arm41400.npy') + #shearh_vel = np.load('rico82800_shearh_vel.npy') + #sheara_vel = np.load('rico82800_sheara_vel.npy') + #wavg = np.load('rico82800_wavg.npy') + #shearTB_vel = np.load('rico82800_shearTB_vel.npy') + wavg1 = np.load('wavg1_arm41400.npy') + shearTB = np.load('shearTB_vel_arm41400.npy') + shear_sum = np.load('shear_sum_arm41400.npy') + shift_distance = np.load('shift_distancearm41400.npy') + cmin=3 + + elif m0==4: + ### Bomex_All + overlap_ratio=np.load('Bomex_overlap_ratio.npy') + height=np.load('Bomex_ht.npy') + overlap=np.load('Bomex_shear.npy') + areaz=np.load('Bomex_areaz.npy') + ht=height + cv=np.load('Bomex_cv.npy') + cp=np.load('Bomex_cp.npy') + overlap_convex=np.load('Bomex_hull.npy') + #shearh_vel = np.load('Bomex_shearh_vel.npy') + #sheara_vel = np.load('Bomex_sheara_vel.npy') + #wavg = np.load('Bomex_wavg.npy') + shearTB = np.load('Bomex_shearTB.npy') + shear_sum = np.load('Bomex_shear_sum.npy') + wz_max = np.load('Bomex_wz_max.npy') + wz_cb = np.load('Bomex_wz_cb.npy') + shift_distance = np.load('Bomex_shift_distance.npy') + cmin=5 + print('Bomex') + +######################################################################## + + + + + + + + line=np.arange(0,100,1) + + ########################################### + ###### calculating overlap due to contrabution + #fract= (5*np.pi) / (6*np.sqrt(3)) -1 + #fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + #fractalf = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + shape= (1/areaz) - 1 + shear= (1/overlap_ratio) - (1/overlap) + #shear = abs(shear) + shear[shear<0]=0 + + fractalf = np.zeros(ht.size) + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf[ht>100]=turb + + """ + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf > lam) + fractalf[np.array(keep)] = lam + """ + + + + FF = f_turb(ht,200);FF[ht<=100]=0; + shear_sum = abs(shear_sum) + shift_d = np.zeros(ht.size) + shift_d[ht>50] = shift_distance + + shift_d = shift_d + shape*cp**0.5/2 ### draw the picture + updraft = (shear_sum*ht)/shift_d + updraft[updraft<0.4] = 0.4 ### based on neggers 2015 + FS = (shear_sum*ht)/(updraft*cp**0.5) + #FS[updraft<0.1] = 0 + #FS[FS>max(1/overlap_ratio)] = np.nan + #FS[np.argwhere(np.isnan(FS))] = max(FS) + + + + #shear = FS ; fractalf = FF + + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + + ################################################################################################################# + """ + #shear = FS ; fractalf = FF + + horizontal= r_total -1 + vertical= 1/overlap_ratio -1 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,13]) + plt.ylim([0,13]) + + else: + plt.clim(1,10**3) + plt.xlim([0,10]) + plt.ylim([0,10]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_total_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_total_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_total_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_total_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_total_r_061919.eps', dpi=300,bbox_inches='tight') + + + + + #plt.savefig('arm41400_total_emp1_r_061719.eps', dpi=300,bbox_inches='tight') + """ + ################################################################################### + """ + binwidth=0.1 + ###prob plot, histogram ,line plot + plt.figure() + #ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=10,density=True);#,log=True); # may want to use one w/ log & one standard + ybin, binEdges, patches =plt.hist(r_total*overlap_ratio,bins=np.arange(min(r_total*overlap_ratio), max(r_total*overlap_ratio) + binwidth, binwidth),density=True); + plt.yticks(np.arange(0,10,2)) + + plt.title('Accuracy of Model') + plt.xlabel('Relative Effect') + plt.ylabel('Probability Density') + + + if m0==0: + plt.savefig('rico82800_rel_effect_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_rel_effect_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_rel_effect_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_rel_effect_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_rel_effect_061919.eps', dpi=300,bbox_inches='tight') + + + #plt.savefig('arm41400_rel_effect_061119.eps', dpi=300,bbox_inches='tight') + """ + ################################################################################# + """ + #shear = FS ; fractalf = FF + + horizontal= shear + vertical= 1/overlap_ratio -1 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + #plt.title('Effect of All Contributors'); + plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,10]) + plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + plt.xlim([0,8]) + plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_shear_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_shear_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_shear_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_shear_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_shear_r_061919.eps', dpi=300,bbox_inches='tight') + + + + + #plt.savefig('arm41400_total_emp1_r_061719.eps', dpi=300,bbox_inches='tight') + """ + ############################################################################################# + + ################################################################################# + """ + #shear = FS ; fractalf = FF + + horizontal= shape + vertical= 1/overlap_ratio -1 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,10]) + plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + plt.xlim([0,8]) + plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + + + #plt.savefig('arm41400_total_emp1_r_061719.eps', dpi=300,bbox_inches='tight') + """ + ####################################################################################################### + """ + #shear = FS ; fractalf = FF + + horizontal= shear+shape + vertical= 1/overlap_ratio -1 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,10]) + plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + plt.xlim([0,8]) + plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_shear_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_shear_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_shear_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_shear_shape_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_shear_shape_r_061919.eps', dpi=300,bbox_inches='tight') + """ + + + ####################################################################################### + """ + #shear = FS ; fractalf = FF + + horizontal= fractalf + vertical= 1/overlap_ratio -1 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + plt.title('Effect of Turbulence'); + #plt.title('Relating Overlap and Height'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,10]) + plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + plt.xlim([0,8]) + plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_turb_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_turb_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_turb_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_turb_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_turb_r_061919.eps', dpi=300,bbox_inches='tight') + """ + ################################################################################### + """ + #shear = FS ; fractalf = FF + + horizontal= 1/overlap_ratio + vertical= ht + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + #plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + plt.title('Cloud Height vs. Overlap'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Actual Overlap') + plt.ylabel('Cloud Height') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + #plt.xlim([0,10]) + #plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + #plt.xlim([0,8]) + #plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_ht_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_ht_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_ht_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_ht_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_ht_r_061919.eps', dpi=300,bbox_inches='tight') + """ + + ################################################################################### + """ + #shear = FS ; fractalf = FF + + horizontal= 1/overlap_ratio + vertical= cp**0.5 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + #plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=3) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=3) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + plt.title('Cloud Width vs. Overlap'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Actual Overlap') + plt.ylabel('Cloud Width') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Eqn') + #plt.xlabel('Cloud Height') + #plt.ylabel('Calculated Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + #plt.xlim([0,10]) + #plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + #plt.xlim([0,8]) + #plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_width_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_width_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_width_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_width_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_width_r_061919.eps', dpi=300,bbox_inches='tight') + """ + ########################################################################################## + """ + #fract= (5*np.pi) / (6*np.sqrt(3)) -1 + fractal= (5*np.pi) / (6*np.sqrt(3)) # -1 + fractalf_comb = np.minimum(fractal*np.ones(overlap_ratio.size),1/overlap_ratio) -1 + + + + #fractalf = np.zeros(ht.size) + overlap_convex=overlap_convex[overlap_convex>0] + turb= (1/overlap_ratio[ht>100]) - (1/overlap_convex) + turb[turb<0]=0 + fractalf_comb[ht>100]=turb + + + ## upper bound to turb + lam = (3*np.pi)/4 #np.pi * np.sqrt(3) / 2 #(15/8)*np.sqrt(3/8)*np.pi + #C1=np.argwhere((1/overlap_ratio)>1.5*lam) + keep=np.argwhere(fractalf_comb > lam) + fractalf_comb[np.array(keep)] = lam + + + #shear = FS ; fractalf = FF + + horizontal= ht + vertical= fractalf_comb + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + #plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=5) + plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=5) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Overlap vs. Cloud Height'); + #plt.title('Overlap from Shear') + plt.title('Overlap from Turbulence') + + + #plt.xlabel('Calculated Overlap') + #plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Equation') + plt.xlabel('Cloud Height') + plt.ylabel('Numerical Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + #plt.xlim([0,10]) + #plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + #plt.xlim([0,8]) + #plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_turb_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_turb_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_turb_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_turb_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_turb_fit_r_061919.eps', dpi=300,bbox_inches='tight') + """ + + ######################################################################################################################### + + """ + #shear = FS ; fractalf = FF + + horizontal= shear + vertical= FS + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=5) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=5) + + #plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Overlap vs. Cloud Height'); + plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + #plt.xlabel('Calculated Overlap') + #plt.ylabel('Actual Overlap') + plt.xlabel('Numerical Overlap') + plt.ylabel('Overlap from Equation') + #plt.xlabel('Cloud Height') + #plt.ylabel('Numerical Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,6]) + plt.ylim([0,6]) + + else: + plt.clim(1,10**3) + plt.xlim([0,4]) + plt.ylim([0,4]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + + if m0==0: + plt.savefig('rico82800_shear_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_shear_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_shear_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_shear_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_shear_fit_r_061919.eps', dpi=300,bbox_inches='tight') + + + """ + ############################################################################################## + + shear = FS ; fractalf = FF + r_total = ( (shear) + (shape) + (fractalf) ) +1 + + horizontal= r_total -1 + vertical= 1/overlap_ratio - 1 + + + bins=dz; + #cmin=3 + ### cmin=3 for rico , concat bomex cmin=10 , concat bomex has many more cld's than 1 timestep of rico + plt.figure(); + HIST2d=plt.hist2d(horizontal,vertical,bins=[1*dz,1*dz],cmin=cmin, cmap='viridis' , norm=colors.LogNorm()); #norm=colors.LogNorm() + #plt.plot(horizontal,horizontal) + #plt.plot(vertical,vertical) + plt.plot(line,'k',linewidth=3) + #plt.plot(ht,FF,'ko') + + #plt.plot(np.linspace(0,100,ht.size),np.zeros(ht.size),'k',linewidth=5) + #plt.plot(np.linspace(100,max(ht)+25,ht.size),f_turb(np.linspace(100,max(ht)+25,ht.size),200),'k',linewidth=5) + + plt.title('Effect of All Contributors'); + #plt.title('Effect of Shear'); + #plt.title('Effect of Area Variability'); + #plt.title('Effect of Shear, Area Var.'); + #plt.title('Effect of Turbulence'); + #plt.title('Overlap vs. Cloud Height'); + #plt.title('Overlap from Shear') + #plt.title('Overlap from Turbulence') + + + plt.xlabel('Calculated Overlap') + plt.ylabel('Actual Overlap') + #plt.xlabel('Numerical Overlap') + #plt.ylabel('Overlap from Equation') + #plt.xlabel('Cloud Height') + #plt.ylabel('Numerical Overlap') + + #colorbar=plt.colorbar(extend='both'); + colorbar=plt.colorbar() + colorbar.set_label('count in bin') + + if m0==4: ### bomex + plt.clim(1,10**4) + plt.xlim([0,10]) + plt.ylim([0,10]) + + else: + plt.clim(1,10**3) + plt.xlim([0,8]) + plt.ylim([0,8]) + + + + #plt.xlim([0,1]) + #plt.ylim([0,1]) + #plt.xlim(left=0) + #plt.ylim(bottom=0) + + #plt.loglog(horizontal,vertical,'o') + + """ + if m0==0: + plt.savefig('rico82800_total_emp1_r_061919.eps', dpi=300,bbox_inches='tight') + + elif m0==1: + plt.savefig('rico201600_total_emp1_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==2: + plt.savefig('arm28800_total_emp1_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0==3: + plt.savefig('arm41400_total_emp1_r_061919.eps', dpi=300,bbox_inches='tight') + + + elif m0 ==4: + plt.savefig('bomexAll_total_emp1_r_061919.eps', dpi=300,bbox_inches='tight') + """ + + +############################################### +end= time.time() +print('Run Time in Seconds:', end-start) + + + + diff --git a/scripts/windshear1.py b/scripts/windshear1.py new file mode 100644 index 0000000..e134588 --- /dev/null +++ b/scripts/windshear1.py @@ -0,0 +1,568 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 23 16:06:23 2019 + +@author: anthonys +""" + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil + + +start=time.time() + +############################################################################# + +armd= Dataset("arm.default.0000000.nc","r") +armql=Dataset("arm.ql.0000000.nc","r") +armqlcore=Dataset("arm.qlcore.0000000.nc","r") +ricod= Dataset("rico.default.0000000.nc","r") +ricoql=Dataset("rico.ql.0000000.nc","r") +ricoqlcore=Dataset("rico.qlcore.0000000.nc","r") + +#data = pkgutil.get_data("conf", "fielddump.ql.00.05.track.nc") + + +#print(bomexd.variables.keys()) +#print(bomexd.variables['area']) +#print(bomexd.variables['area'][:][:]) +#print(bomexd.variables) +#print(bomexd.variables.values()) +######################################################################### +# Define variables and importing files +bomexd = Dataset("bomex.default.0000000.nc","r") +area = bomexd.variables["area"][:,:] # fractional area contained in mask +areah = bomexd.variables['areah'][:,:] +time_t=bomexd.variables['time'][:] + +z=bomexd.variables['z'][:] # full level ht +zh=bomexd.variables['zh'][:] # half level height +ql=bomexd.variables['ql'][:,:] + +thl=bomexd.variables['thl'][:,:] # liquid water potential temp +qlfrac=bomexd.variables['qlfrac'][:,:] # cloud fraction +qlcover=bomexd.variables['qlcover'][:] # projected cloud cover + +u2=bomexd.variables['u2'][:,:] #moment 2 of u vel, weighted ave of intenties of pixels in seq of images +u3=bomexd.variables['u3'][:,:] +u4=bomexd.variables['u4'][:,:] + +ugrad=bomexd.variables['ugrad'][:,:] # gradient (shear) of the u velocity +vgrad=bomexd.variables['vgrad'][:,:] +u=bomexd.variables['u'][:,:] # vel in u direction +v=bomexd.variables['v'][:,:] # vel in v direction +w=bomexd.variables['w'][:,:] # vertical velocities + + + +b=bomexd.variables['b'][:,:] # buoyancy +rho=bomexd.variables['rho'][:,:] # full level density +rhoh=bomexd.variables['rhoh'][:,:] # half level density +phydro=bomexd.variables['phydro'][:,:] # full level hydrostatic pressure + + +bomexql=Dataset("bomex.ql.0000000.nc","r") +qlfrac1=bomexql.variables['qlfrac'][:,:] +z1=bomexql.variables['z'][:] +zh1=bomexql.variables['zh'][:] + + +bomexqlcore=Dataset("bomex.qlcore.0000000.nc","r") +qlfrac2=bomexqlcore.variables['qlfrac'][:,:] +z2=bomexqlcore.variables['z'][:] +zh2=bomexqlcore.variables['zh'][:] + + +bomextrack=Dataset("l.0001800.track.nc","r") +cv=bomextrack.variables['cv'][:] # cloud cover by volume +cp=bomextrack.variables['cp'][:] # cloud cover by area +area_proj=bomextrack.variables['area_proj'][:] # projected cloud area +cloudsize=np.sqrt(area_proj) +area_proj_conn=bomextrack.variables['area_proj_conn'][:] # connected projected cloud area +ht=bomextrack.variables['ht'][:] # height +zt=bomextrack.variables['z'][:] +xt=bomextrack.variables['x'][:] +yt=bomextrack.variables['y'][:] +cld_mask=bomextrack.variables['cld_mask'][:,:,:] # +cfrac=bomextrack.variables['cfrac'][:] # cloud fraction:percentage of each pixel in gridbox in model that is covered w/ clouds +nrcloud=bomextrack.variables['nrcloud'][:,:,:] # cloud number, masks (inte array) +nr=bomextrack.variables['nr'][:] # number density rain ? +cb=bomextrack.variables['cb'][:] # cloud base +ct=bomextrack.variables['ct'][:] # cloud top, # ct - cb , height difference +overlap_ratio=bomextrack.variables['chr'][:] # overlap ratio based on cloud height +cfv=bomextrack.variables['cfv'][:,:] # cv for cloud layer/field, cloud field projected area +cfp=bomextrack.variables['cfp'][:,:] # cp for cloud layer/field, cloud field vol per ht +# cfr=cfv/cfp # overall ratio +# rav=bomextrack.variables['rav'][:] # average ratio + +nz=zt.size;nx=xt.size;ny=yt.size; # sizes of dimensions + + + + +bomextrack1=Dataset("l.0003600.track.nc","r") +""" +cv1=bomextrack1.variables['cv'][:] +cp1=bomextrack1.variables['cp'][:] +""" + +bomextrack2=Dataset("l.0005400.track.nc","r") +""" +cv2=bomextrack.variables['cv'][:] +cp2=bomextrack.variables['cp'][:] +area_proj2=bomextrack.variables['area_proj'][:] +cloudsize2=np.sqrt(area_proj) +ht2=bomextrack.variables['ht'][:] +""" + + + +bomexw=Dataset('w.nc','r') + +########################################################################### + +def pyth(u,v): + return np.sqrt(u*u+v*v) + + +def r1(x): + return 1/(1+abs(x)) + +def r2(x): + return 1/(1+x*x) + +def rpow(x): + return 1/(1+(abs(x))**(0.2)) + + +def rb(u,w,h,b): + return 1/(1+abs((u/w)*(h/b))) + +def rbpow(u,w,h,b): + return 1/(1+abs((u**0.2/w**0.2)*(h**0.2/b**0.2))) + + +def rexp(x): + return np.exp(-abs(x)) + + + +def rb1(grad,ht,w,one,width): + return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + +def ra0(grad,ht,w,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + return (1+multiple)**(-1) + + + +def ra(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/ct + return (1+multiple*multiplicand)**(-1) + + + + +#################################### + +filenames=[bomexd]#, ricod, armd] + +for file in filenames: + zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + + + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + #r=1/(1+abs(ugrad2(zt))) + #plt.plot(ugrad2(zt),r1(ugrad2(zt))) + + #plt.plot(grad,r1(grad)) + #plt.title('r vs. gradient ') + plt.plot(1/r1(grad),grad) + plt.title('gradient vs. 1/r') + + + ## + gradint=interp1d(zt,grad,axis=0) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + #plt.plot(gradint(ztnew),overlap_ratio,'o') + ## + + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew), bins=bins,cmin=0.5) + #colorbar = plt.colorbar() + #colorbar.set_label('counts in bin') + + + + # using rb1 + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + + plt.plot(1/rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'o') + plt.title('gradient vs. 1/ratio') + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.plot(gradint(ztnew),rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),'o') + #plt.title('ratio vs. grad') + + + + # using ra + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + + plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'o') + plt.title('gradient vs. 1/ratio') + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + #plt.plot(gradint(ztnew),ra0(gradint(ztnew),ht,wnew2(ztnew),one),'o') + #plt.title('ratio vs. grad') + #plt.hist2d(gradint(ztnew),overlap_ratio,bins=bins,cmin=0.5) + + ############################################################ +# shear vs. 1/ overlap with hist2d grid +""" + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + + + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + #r=1/(1+abs(ugrad2(zt))) + #plt.plot(ugrad2(zt),r1(ugrad2(zt))) + + #plt.plot(grad,r1(grad)) + #plt.title('r vs. gradient ') + plt.plot(1/r1(grad),grad) + plt.title('gradient vs. 1/r') + + + ## + gradint=interp1d(zt,grad,axis=0) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + #plt.plot(gradint(ztnew),overlap_ratio,'o') + ## + + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew), bins=bins,cmin=0.5) + #colorbar = plt.colorbar() + #colorbar.set_label('counts in bin') + + + + # using rb(u,w,h,b) + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'o') + plt.title('gradient vs. 1/ratio') + bins=15 + plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + +""" + +################################################################################### + +""" +# seems like vert updraft vel has little affect on ratio + plt.figure() + for t in range(time_t.size): + wnew1=w[t,:] + + + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + #r=1/(1+abs(ugrad2(zt))) + #plt.plot(ugrad2(zt),r1(ugrad2(zt))) + + + + + ## + wint=interp1d(zh,wnew1,axis=0) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + #plt.plot(gradint(ztnew),overlap_ratio,'o') + ## + + bins=15 + plt.hist2d(wint(ztnew), overlap_ratio, bins=bins,cmin=10.5) + #plt.plot(wint(ztnew),overlap_ratio,'o') + #colorbar = plt.colorbar() + #colorbar.set_label('counts in bin') +""" + + +""" + # using rb(u,w,h,b) + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + plt.plot(gradint(ztnew),rb(gradint(ztnew),one,ht,cb),'o') + plt.title('rb vs. gradient ') + bins=15 + plt.hist2d(gradint(ztnew), overlap_ratio, bins=bins,cmin=0.5) + + # plt.plot(zt,wnew2(zt)) # w is small ~0 +""" + + +""" + # plotting grad vs. w + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + #ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + #plt.plot(gradint(ztnew),rb(gradint(ztnew),one,ht,cb),'o') + #plt.title('rb vs. gradient ') + plt.plot(wnew2(zt),gradint(zt)) + plt.title('grad vs. w') +""" +################################################################################ +""" + plt.figure() + for t in range(time_t.size): + vgrad1=vgrad[t,:] + vgrad2=interp1d(zh,vgrad1) + #plt.figure() + #plt.plot(zt, ugrad2(zt)) + r=1/(1+abs(vgrad2(zt))) + plt.plot(vgrad2(zt),r) + plt.title('r vs. gradient of v') +""" + + + + +""" + for t in range(time_t.size): + plt.figure() + ugrad1=ugrad[t,:] + ugrad2=interp1d(zh,ugrad1) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1) + plt.plot(wnew2(zt),ugrad2(zt)) + plt.title('gradient of u vs. w') +""" + + +""" +plt.figure() +plt.plot(cb,ht) # cb= width of cld base? +plt.title('ht vs. cb') + +plt.figure() +plt.plot(cb,ct) +plt.title('ct vs. cb') +plt.show() +""" + +""" +# r(u,w,ht,cb) +ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + +plt.figure() +for t in range(time_t.size): + ugrad1=ugrad[t,:] + ugrad2=interp1d(zh,ugrad1) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1) + + plt.plot(wnew2(ztnew),ugrad2(ztnew)) + + #rb=1/(1+(ugrad2(ztnew)/wnew2(ztnew))*(ht/cb)) + + #plt.plot(ugrad2(ztnew),rb) + #plt.title('rb vs. gradient of u') +""" + +""" +# r(u,w,ht,cb) with w=1 +ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + +plt.figure() +for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + zh=bomexd.variables['zh'][:] + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1) + + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + plt.plot(grad,rb(grad,wnew2(z),ht,cb)) + plt.title('rb vs. gradient of u') + +""" + +""" +# plots of overlap_ratio (track file) vs. grad of u +for t in range(time_t.size): + ugrad1=ugrad[t,:] + ugrad2=interp1d(zh,ugrad1) + ztnew=np.linspace(zt[0],zt[-1],int(overlap_ratio.size)) + plt.figure() + #plt.plot(ugrad2(ztnew),overlap_ratio) + bins=15 + plt.hist2d(ugrad2(ztnew), overlap_ratio, bins=bins,cmin=0.5) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + plt.title('ratio vs. gradient of u') + + """ + + + + + + + + +############################################################################# +# shows that ct>=cb +# plt.plot(cb,ct,'o');plt.plot(cb,cb,'-');None +# ct -cb incr as r decr *(inv rel) +#plt.plot(ct-cb,overlap_ratio,'o');None +# linear relationship +#plt.plot(ct-cb,ht,'o');None +# inv relationship +# plt.plot(ht,overlap_ratio,'o');None +# inv relationship +# plt.plot(area_proj,overlap_ratio,'o');None + + + + + +#################################################################### +#savfig('filename.pdf') +#savfig('filename.png') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + diff --git a/scripts/windshear2.py b/scripts/windshear2.py new file mode 100644 index 0000000..4fe9a48 --- /dev/null +++ b/scripts/windshear2.py @@ -0,0 +1,410 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jan 25 15:33:07 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil + + +start=time.time() + +############################################################################# +""" +armd= Dataset("arm.default.0000000.nc","r") +armql=Dataset("arm.ql.0000000.nc","r") +armqlcore=Dataset("arm.qlcore.0000000.nc","r") +ricod= Dataset("rico.default.0000000.nc","r") +ricoql=Dataset("rico.ql.0000000.nc","r") +ricoqlcore=Dataset("rico.qlcore.0000000.nc","r") +""" +#data = pkgutil.get_data("conf", "fielddump.ql.00.05.track.nc") + + +#print(bomexd.variables.keys()) +#print(bomexd.variables['area']) +#print(bomexd.variables['area'][:][:]) +#print(bomexd.variables) +#print(bomexd.variables.values()) +######################################################################### +# Define variables and importing files +""" +bomexd = Dataset("bomex.default.0000000.nc","r") +area = bomexd.variables["area"][:,:] # fractional area contained in mask +areah = bomexd.variables['areah'][:,:] +time_t=bomexd.variables['time'][:] + +z=bomexd.variables['z'][:] # full level ht +zh=bomexd.variables['zh'][:] # half level height +ql=bomexd.variables['ql'][:,:] + +thl=bomexd.variables['thl'][:,:] # liquid water potential temp +qlfrac=bomexd.variables['qlfrac'][:,:] # cloud fraction +qlcover=bomexd.variables['qlcover'][:] # projected cloud cover + +u2=bomexd.variables['u2'][:,:] #moment 2 of u vel, weighted ave of intenties of pixels in seq of images +u3=bomexd.variables['u3'][:,:] +u4=bomexd.variables['u4'][:,:] + +ugrad=bomexd.variables['ugrad'][:,:] # gradient (shear) of the u velocity +vgrad=bomexd.variables['vgrad'][:,:] +u=bomexd.variables['u'][:,:] # vel in u direction +v=bomexd.variables['v'][:,:] # vel in v direction +w=bomexd.variables['w'][:,:] # vertical velocities + + + +b=bomexd.variables['b'][:,:] # buoyancy +rho=bomexd.variables['rho'][:,:] # full level density +rhoh=bomexd.variables['rhoh'][:,:] # half level density +phydro=bomexd.variables['phydro'][:,:] # full level hydrostatic pressure + + +bomexql=Dataset("bomex.ql.0000000.nc","r") +qlfrac1=bomexql.variables['qlfrac'][:,:] +z1=bomexql.variables['z'][:] +zh1=bomexql.variables['zh'][:] + + +bomexqlcore=Dataset("bomex.qlcore.0000000.nc","r") +qlfrac2=bomexqlcore.variables['qlfrac'][:,:] +z2=bomexqlcore.variables['z'][:] +zh2=bomexqlcore.variables['zh'][:] + + +bomextrack=Dataset("l.0001800.track.nc","r") +cv=bomextrack.variables['cv'][:] # cloud cover by volume +cp=bomextrack.variables['cp'][:] # cloud cover by area +area_proj=bomextrack.variables['area_proj'][:] # projected cloud area +cloudsize=np.sqrt(area_proj) +area_proj_conn=bomextrack.variables['area_proj_conn'][:] # connected projected cloud area +ht=bomextrack.variables['ht'][:] # height +zt=bomextrack.variables['z'][:] +xt=bomextrack.variables['x'][:] +yt=bomextrack.variables['y'][:] +cld_mask=bomextrack.variables['cld_mask'][:,:,:] # +cfrac=bomextrack.variables['cfrac'][:] # cloud fraction:percentage of each pixel in gridbox in model that is covered w/ clouds +nrcloud=bomextrack.variables['nrcloud'][:,:,:] # cloud number, masks (inte array) +nr=bomextrack.variables['nr'][:] # number density rain ? +cb=bomextrack.variables['cb'][:] # cloud base +ct=bomextrack.variables['ct'][:] # cloud top, # ct - cb , height difference +overlap_ratio=bomextrack.variables['chr'][:] # overlap ratio based on cloud height +cfv=bomextrack.variables['cfv'][:,:] # cv for cloud layer/field, cloud field projected area +cfp=bomextrack.variables['cfp'][:,:] # cp for cloud layer/field, cloud field vol per ht +# cfr=cfv/cfp # overall ratio +# rav=bomextrack.variables['rav'][:] # average ratio + +nz=zt.size;nx=xt.size;ny=yt.size; # sizes of dimensions + + + + +bomextrack1=Dataset("l.0003600.track.nc","r") + +cv1=bomextrack1.variables['cv'][:] +cp1=bomextrack1.variables['cp'][:] + + +bomextrack2=Dataset("l.0005400.track.nc","r") + +cv2=bomextrack.variables['cv'][:] +cp2=bomextrack.variables['cp'][:] +area_proj2=bomextrack.variables['area_proj'][:] +cloudsize2=np.sqrt(area_proj) +ht2=bomextrack.variables['ht'][:] + + + + +bomexw=Dataset('w.nc','r') +bomexqt=Dataset('/data/bomex/qt.nc','r') + +""" +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +def r1(x): + return 1/(1+abs(x)) + + + +def rb1(grad,ht,w,one,width): + return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + +def ra0(grad,ht,w,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + return (1+multiple)**(-1) + + +""" +def ra1(grad,ht,w,cv,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/(cv)**(0.5) + return (1+multiple*multiplicand)**(-1) +""" + +def ra2(grad,ht,w,ct,cv,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/(cv)**(0.5) + return (1+multiple*multiplicand)**(-1) +######## +# when |ct-cb|<1 ra -> rashear +def rashear(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/cb + return (1+multiple*multiplicand)**(-1) + +def raanvil(grad,ht,w,ct,cb,one): + multiple=1/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return (1+multiple*multiplicand)**(-1) + + +# model +def ra(grad,ht,w,ct,cb,one): + multiple=(np.maximum(abs(grad)*ht,one))/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/cb + return ((1)+multiple*multiplicand)**(-1) +############ +def raalt(grad,ht,w,ct,cb,one): + term1=abs(grad*ht)/(np.maximum(abs(w),one)*cb) + term2=abs(ct-cb)/cb + return ((1) + term1 + term2)**(-1) + + +#################################### + +# script + +bomexfilenames=[bomextrack216] + + + +for file in filenames: + zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + + + + # using ra + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #plt.figure() + #plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=40 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + #plt.plot(ra1(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + #plt.title('grad vs. ratio') + ##plt.hist2d(gradint(ztnew),overlap_ratio,bins=bins,cmin=0.5) + ############################################################## + plt.hist2d(rashear(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),bins=bins,cmin=0.5) + plt.title('shear vs. ratio') + #plt.hist2d(rashear(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew)*ht,bins=bins,cmin=0.5) + #plt.title('shear*ht vs. ratio') + #plt.hist2d(raanvil(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),abs(ct-cb),bins=bins,cmin=0.5) + #plt.title('ct-cb vs. ratio') + #plt.hist2d(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),ht,bins=bins,cmin=0.5) + #plt.title('ht vs. ratio') + ##plt.plot(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),ht,'o') + #plt.hist2d(overlap_ratio,ht,bins=bins,cmin=0.5) + + #z=np.polyfit(overlap_ratio,ht,1) + #plt.plot(overlap_ratio,z[0]*overlap_ratio +z[1]) + ############################################################### + + + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + """ + # using rb1 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + plt.plot(rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + plt.title('grad vs. ratio') + """ + + + + + + """ + # using ra0 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + plt.plot(ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + plt.title('grad vs. ratio') + + """ + + + + + + +#################################################################### +#savfig('filename.pdf') +#savfig('filename.png') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + diff --git a/scripts/windshear3.py b/scripts/windshear3.py new file mode 100644 index 0000000..45674dc --- /dev/null +++ b/scripts/windshear3.py @@ -0,0 +1,375 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Jan 28 12:00:15 2019 + +@author: anthonys +""" + +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jan 25 15:33:07 2019 + +@author: anthonys +""" + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +#from scipy.io import netcdf +#import scipy as sp +import glob +import os +import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil + + +start=time.time() + +############################################################################# +""" +armd= Dataset("arm.default.0000000.nc","r") +armql=Dataset("arm.ql.0000000.nc","r") +armqlcore=Dataset("arm.qlcore.0000000.nc","r") +ricod= Dataset("rico.default.0000000.nc","r") +ricoql=Dataset("rico.ql.0000000.nc","r") +ricoqlcore=Dataset("rico.qlcore.0000000.nc","r") +""" +#data = pkgutil.get_data("conf", "fielddump.ql.00.05.track.nc") + + +#print(bomexd.variables.keys()) +#print(bomexd.variables['area']) +#print(bomexd.variables['area'][:][:]) +#print(bomexd.variables) +#print(bomexd.variables.values()) +######################################################################### +# Define variables and importing files +""" +bomexd = Dataset("bomex.default.0000000.nc","r") +area = bomexd.variables["area"][:,:] # fractional area contained in mask +areah = bomexd.variables['areah'][:,:] +time_t=bomexd.variables['time'][:] + +z=bomexd.variables['z'][:] # full level ht +zh=bomexd.variables['zh'][:] # half level height +ql=bomexd.variables['ql'][:,:] + +thl=bomexd.variables['thl'][:,:] # liquid water potential temp +qlfrac=bomexd.variables['qlfrac'][:,:] # cloud fraction +qlcover=bomexd.variables['qlcover'][:] # projected cloud cover + +u2=bomexd.variables['u2'][:,:] #moment 2 of u vel, weighted ave of intenties of pixels in seq of images +u3=bomexd.variables['u3'][:,:] +u4=bomexd.variables['u4'][:,:] + +ugrad=bomexd.variables['ugrad'][:,:] # gradient (shear) of the u velocity +vgrad=bomexd.variables['vgrad'][:,:] +u=bomexd.variables['u'][:,:] # vel in u direction +v=bomexd.variables['v'][:,:] # vel in v direction +w=bomexd.variables['w'][:,:] # vertical velocities + + + +b=bomexd.variables['b'][:,:] # buoyancy +rho=bomexd.variables['rho'][:,:] # full level density +rhoh=bomexd.variables['rhoh'][:,:] # half level density +phydro=bomexd.variables['phydro'][:,:] # full level hydrostatic pressure + + +bomexql=Dataset("bomex.ql.0000000.nc","r") +qlfrac1=bomexql.variables['qlfrac'][:,:] +z1=bomexql.variables['z'][:] +zh1=bomexql.variables['zh'][:] + + +bomexqlcore=Dataset("bomex.qlcore.0000000.nc","r") +qlfrac2=bomexqlcore.variables['qlfrac'][:,:] +z2=bomexqlcore.variables['z'][:] +zh2=bomexqlcore.variables['zh'][:] + + +bomextrack=Dataset("l.0001800.track.nc","r") +cv=bomextrack.variables['cv'][:] # cloud cover by volume +cp=bomextrack.variables['cp'][:] # cloud cover by area +area_proj=bomextrack.variables['area_proj'][:] # projected cloud area +cloudsize=np.sqrt(area_proj) +area_proj_conn=bomextrack.variables['area_proj_conn'][:] # connected projected cloud area +ht=bomextrack.variables['ht'][:] # height +zt=bomextrack.variables['z'][:] +xt=bomextrack.variables['x'][:] +yt=bomextrack.variables['y'][:] +cld_mask=bomextrack.variables['cld_mask'][:,:,:] # +cfrac=bomextrack.variables['cfrac'][:] # cloud fraction:percentage of each pixel in gridbox in model that is covered w/ clouds +nrcloud=bomextrack.variables['nrcloud'][:,:,:] # cloud number, masks (inte array) +nr=bomextrack.variables['nr'][:] # number density rain ? +cb=bomextrack.variables['cb'][:] # cloud base +ct=bomextrack.variables['ct'][:] # cloud top, # ct - cb , height difference +overlap_ratio=bomextrack.variables['chr'][:] # overlap ratio based on cloud height +cfv=bomextrack.variables['cfv'][:,:] # cv for cloud layer/field, cloud field projected area +cfp=bomextrack.variables['cfp'][:,:] # cp for cloud layer/field, cloud field vol per ht +# cfr=cfv/cfp # overall ratio +# rav=bomextrack.variables['rav'][:] # average ratio + +nz=zt.size;nx=xt.size;ny=yt.size; # sizes of dimensions + + + + +bomextrack1=Dataset("l.0003600.track.nc","r") + +cv1=bomextrack1.variables['cv'][:] +cp1=bomextrack1.variables['cp'][:] + + +bomextrack2=Dataset("l.0005400.track.nc","r") + +cv2=bomextrack.variables['cv'][:] +cp2=bomextrack.variables['cp'][:] +area_proj2=bomextrack.variables['area_proj'][:] +cloudsize2=np.sqrt(area_proj) +ht2=bomextrack.variables['ht'][:] + + + + +bomexw=Dataset('w.nc','r') +bomexqt=Dataset('/data/bomex/qt.nc','r') + +""" +################################################################################ +# importing files +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') + + + + +########################################################################### + +def pyth(u,v): + return np.sqrt(u*u+v*v) + + +def r1(x): + return 1/(1+abs(x)) + + +def rb1(grad,ht,w,one,width): + return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + +def ra0(grad,ht,w,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + return (1+multiple)**(-1) + +def ra1(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=1/ct + return (1+multiple*multiplicand)**(-1) + +def ra2(grad,ht,w,ct,cv,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/(cv)**(0.5) + return (1+multiple*multiplicand)**(-1) + +def ra(grad,ht,w,ct,cb,one): + multiple=(abs(grad)*ht)/np.maximum(abs(w),one) + multiplicand=np.maximum(abs(ct-cb),one)/ct + return (1+multiple*multiplicand)**(-1) + + +#################################### + + + + +filenames=[bomexd]#, ricod, armd] +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144] + + + + +for file in filenames: + zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + ugrad=file.variables['ugrad'][:,:] + vgrad=file.variables['vgrad'][:,:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + if file == bomexd: + for file1 in bomexfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + elif file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + elif file == armd: + for file1 in armfilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + + + + + + # using ra + plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + #plt.figure() + #plt.plot(1/ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + plt.plot(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),gradint(ztnew),'-') + plt.title('grad vs. ratio') + ##plt.hist2d(gradint(ztnew),overlap_ratio,bins=bins,cmin=0.5) + #plt.hist2d(ra(gradint(ztnew),ht,wnew2(ztnew),ct,cb,one),ct-cb,bins=bins,cmin=0.5) + #plt.title('ct vs. ratio') + + + + + """ + # using rb1 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + plt.plot(rb1(gradint(ztnew),ht,wnew2(ztnew),one,np.sqrt(cv)),gradint(ztnew),'-') + plt.title('grad vs. ratio') + """ + + + + + + """ + # using ra0 + #plt.figure() + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv=pyth(unew,vnew) + grad=np.gradient(uv) + #ugrad1=ugrad[t,:] + #ugrad2=interp1d(zh,ugrad1) + gradint=interp1d(zt,grad,axis=0) + wnew1=w[t,:] + wnew2=interp1d(zh,wnew1,axis=0) + #rb=1/(1+(ugrad2(ztnew)/1)*(ht/cb)) + + ztnew=np.linspace(zt[0],zt[-1],int(ht.size)) + one=np.ones(ztnew.size) # let w=1 m/s, a way avoid dividing by zero + plt.figure() + #plt.plot(1/ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + #plt.title('gradient vs. 1/ratio') + bins=15 + #plt.hist2d(1/overlap_ratio, gradint(ztnew),bins=bins,cmin=0.5) + #plt.xlim([1,1.8]) + ### this is for a better intuitive sense of what is going on + plt.plot(ra0(gradint(ztnew),ht,wnew2(ztnew),one),gradint(ztnew),'-') + plt.title('grad vs. ratio') + + """ + + + +#################################################################### +#savfig('filename.pdf') +#savfig('filename.png') + + + +end= time.time() +print('Run Time in Seconds:', end-start) + + + diff --git a/scripts/windshear4.py b/scripts/windshear4.py new file mode 100644 index 0000000..7b17bc7 --- /dev/null +++ b/scripts/windshear4.py @@ -0,0 +1,299 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Mon Mar 4 11:11:48 2019 + +@author: anthonys +""" + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +def rb1(grad,ht,w,one,width): + #return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + return 1/ ( (abs(grad)*ht) / (width*np.maximum(abs(w),one) ) +1 ) + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack342] +ricofilenames=[ricotrack828] +armfilenames=[armtrack126] +conditional_height=2000 + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + uv=np.zeros((time_t.size, zt.size)) + grad=np.zeros((time_t.size, zt.size)) + for t in range(time_t.size): + unew=u[t,:] + vnew=v[t,:] + uv[t]=pyth(unew,vnew) + grad[t]=np.gradient(uv[t]) + + uv_z=np.mean(uv, axis=0) # average among different times + grad_z=np.mean(grad, axis=0) # average among different times + + #uv_diff=np.zeros(zt.size -1) + #for i in range(zt.size -1): + # uv_diff[i] = uv_z[i+1] - uv_z[i] + + + shear0 = ( uv_z[ct] - uv_z[cb] ) / 1 + shear1 = uv_z[ct] - uv_z[cb-1] # need to subtract 1 from cb OR add 1 to ct + shear2 = uv_z[ct+1] - uv_z[cb] # need to subtract 1 from cb OR add 1 to ct + shear3 = np.zeros(cb.size) + #shear4 = np.zeros(cb.size) + s1 = np.zeros(cb.size) + A_T=np.zeros(cb.size) + s2=np.zeros(cb.size) + s3= ( ( (dz*ct)**2 - (dz*cb)**2 ) / ht**2 )**(1/4) + for i in range(cb.size): + shear3[i] = sum(grad_z[cb[i]:ct[i]+1]) / 1 + #shear4[i] = sum(uv_diff[cb[i]+1:ct[i]+1]) + if uv_z[ct[i]] >= uv_z[cb[i]]: + s1[i]=2*dz*sum(uv_z[cb[i]:ct[i]+1]) / (ht[i]*ht[i]) + A_T[i]=dz*sum(uv_z[cb[i]:ct[i]+1]) + s2[i]= ( uv_z[ct[i]] - uv_z[cb[i]] )**2 / (2*dz*sum(uv_z[cb[i]:ct[i]+1])) + elif uv_z[ct[i]] < uv_z[cb[i]]: + s1[i]=-2*dz*sum(uv_z[cb[i]:ct[i]+1]) / (ht[i]*ht[i]) + A_T[i]=-dz*sum(uv_z[cb[i]:ct[i]+1]) + + index_shear=np.where(ht > 0) + ht_shear=ht[index_shear[0]] # taking the ht values according to indices above + overlap_ratio_shear=overlap_ratio[index_shear[0]]; + s1_shear= s1[index_shear[0]] + s2_shear= s2[index_shear[0]] + + ### plot shear vs. overlap + bins=dz + + plt.figure() + plt.hist2d(overlap_ratio,shear3,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + plt.figure() + plt.hist2d(overlap_ratio,shear0,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + plt.figure() + plt.hist2d(overlap_ratio_shear,s1_shear,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + plt.figure() + plt.hist2d(overlap_ratio_shear,s2_shear,bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + """ + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripts/windshear5.py b/scripts/windshear5.py new file mode 100644 index 0000000..7e45586 --- /dev/null +++ b/scripts/windshear5.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Thu Mar 21 12:33:14 2019 + +@author: anthonys +""" + + + + + +#from netCDF4 import Dataset +import numpy as np +#import struct +#import netCDF4 +from netCDF4 import Dataset +#import netCDF4 as nc +#import collections +import matplotlib.pyplot as plt +plt.rcParams.update({'figure.max_open_warning': 0}) +#from scipy.io import netcdf +#import scipy as sp +#import glob +#import os +#import sys +from mpl_toolkits import mplot3d +from scipy.optimize import curve_fit +from scipy.interpolate import interp1d +import time +#import pkgutil +#import collections +#from collections import Counter +from scipy.spatial import ConvexHull +import cProfile + +#import overlap_calculation + +start=time.time() + + +############################################################################# + +# definitions +def pyth(u,v): # magnitude + return np.sqrt(u*u+v*v) + + +def rb1(grad,ht,w,one,width): + #return 1/(abs(grad)*ht*(1/width*np.maximum(abs(w),one))+1) + return 1/ ( (abs(grad)*ht) / (width*np.maximum(abs(w),one) ) +1 ) + + + +################################################################################ +# importing files + +bomexd = Dataset("/data/bomex/bomex.default.0000000.nc","r") +bomexql = Dataset("/data/bomex/bomex.ql.0000000.nc","r") +bomexqlcore = Dataset("/data/bomex/bomex.qlcore.0000000.nc","r") +bomextrack18 = Dataset('/data/bomex/l.0001800.track.nc','r') +bomextrack36 = Dataset('/data/bomex/l.0003600.track.nc','r') +bomextrack54 = Dataset('/data/bomex/l.0005400.track.nc','r') +bomextrack72 = Dataset('/data/bomex/l.0007200.track.nc','r') +bomextrack90 = Dataset('/data/bomex/l.0009000.track.nc','r') +bomextrack108 = Dataset('/data/bomex/l.0010800.track.nc','r') +bomextrack126 = Dataset('/data/bomex/l.0012600.track.nc','r') +bomextrack144 = Dataset('/data/bomex/l.0014400.track.nc','r') +bomextrack162 = Dataset('/data/bomex/l.0016200.track.nc','r') +bomextrack180 = Dataset('/data/bomex/l.0018000.track.nc','r') +bomextrack198 = Dataset('/data/bomex/l.0019800.track.nc','r') +bomextrack216 = Dataset('/data/bomex/l.0021600.track.nc','r') + +bomextrack342 = Dataset('/data/bomex/l.0034200.track.nc','r') +bomextrack360 = Dataset('/data/bomex/l.0036000.track.nc','r') + + +ricod = Dataset("/data/rico/rico.default.0000000.nc","r") +ricoql = Dataset("/data/rico/rico.ql.0000000.nc","r") +ricoqlcore = Dataset("/data/rico/rico.qlcore.0000000.nc","r") +ricotrack36 = Dataset('/data/rico/l.0003600.track.nc','r') +ricotrack72 = Dataset('/data/rico/l.0007200.track.nc','r') +ricotrack108 = Dataset('/data/rico/l.0010800.track.nc','r') +ricotrack144 = Dataset('/data/rico/l.0014400.track.nc','r') +ricotrack180 = Dataset('/data/rico/l.0018000.track.nc','r') +ricotrack216 = Dataset('/data/rico/l.0021600.track.nc','r') +ricotrack252 = Dataset('/data/rico/l.0025200.track.nc','r') +ricotrack288 = Dataset('/data/rico/l.0028800.track.nc','r') +ricotrack324 = Dataset('/data/rico/l.0032400.track.nc','r') +ricotrack360 = Dataset('/data/rico/l.0036000.track.nc','r') +ricotrack396 = Dataset('/data/rico/l.0039600.track.nc','r') + +ricotrack612 = Dataset('/data/rico/l.0061200.track.nc','r') +ricotrack828 = Dataset('/data/rico/l.0082800.track.nc','r') +ricotrack900 = Dataset('/data/rico/l.0090000.track.nc','r') +ricotrack1008 = Dataset('/data/rico/l.0100800.track.nc','r') +ricotrack1116 = Dataset('/data/rico/l.0111600.track.nc','r') +ricotrack1224 = Dataset('/data/rico/l.0122400.track.nc','r') +ricotrack1332 = Dataset('/data/rico/l.0133200.track.nc','r') +ricotrack1440 = Dataset('/data/rico/l.0144000.track.nc','r') +ricotrack1548 = Dataset('/data/rico/l.0154800.track.nc','r') +ricotrack1656 = Dataset('/data/rico/l.0165600.track.nc','r') +ricotrack1764 = Dataset('/data/rico/l.0176400.track.nc','r') +ricotrack1872 = Dataset('/data/rico/l.0187200.track.nc','r') +ricotrack1980 = Dataset('/data/rico/l.0198000.track.nc','r') + +ricotrack2016 = Dataset('/data/rico/l.0201600.track.nc','r') +ricotrack2052 = Dataset('/data/rico/l.0205200.track.nc','r') +ricotrack2088 = Dataset('/data/rico/l.0208800.track.nc','r') +ricotrack2124 = Dataset('/data/rico/l.0212400.track.nc','r') +ricotrack2160 = Dataset('/data/rico/l.0216000.track.nc','r') + + + +armd = Dataset("/data/arm/arm.default.0000000.nc","r") +armql = Dataset("/data/arm/arm.ql.0000000.nc","r") +armqlcore = Dataset("/data/arm/arm.qlcore.0000000.nc","r") +armtrack108 = Dataset('/data/arm/l.0010800.track.nc','r') +armtrack126 = Dataset('/data/arm/l.0012600.track.nc','r') +armtrack144 = Dataset('/data/arm/l.0014400.track.nc','r') +armtrack162 = Dataset('/data/arm/l.0016200.track.nc','r') +armtrack180 = Dataset('/data/arm/l.0018000.track.nc','r') +armtrack198 = Dataset('/data/arm/l.0019800.track.nc','r') +armtrack216 = Dataset('/data/arm/l.0021600.track.nc','r') +armtrack234 = Dataset('/data/arm/l.0023400.track.nc','r') +armtrack252 = Dataset('/data/arm/l.0025200.track.nc','r') +armtrack270 = Dataset('/data/arm/l.0027000.track.nc','r') +armtrack288 = Dataset('/data/arm/l.0028800.track.nc','r') + +armtrack504 = Dataset('/data/arm/l.0050400.track.nc','r') +armtrack522 = Dataset('/data/arm/l.0052200.track.nc','r') + + +filenames=[bomexd, ricod, armd] + +bomexfilenames=[bomextrack18, bomextrack36, bomextrack54, bomextrack72, bomextrack90, bomextrack108, bomextrack126, bomextrack144, bomextrack162, bomextrack180, bomextrack198, bomextrack216] +ricofilenames=[ricotrack36, ricotrack72, ricotrack108, ricotrack144, ricotrack180, ricotrack216, ricotrack252, ricotrack288, ricotrack324, ricotrack360, ricotrack396] +armfilenames=[armtrack108, armtrack126, armtrack144, armtrack162, armtrack180, armtrack198, armtrack216, armtrack234, armtrack252, armtrack270, armtrack288] + +########################################################################### + +#################################### + +# script +filenames=[ricod] +bomexfilenames=[bomextrack342] +ricofilenames=[ricotrack828] +armfilenames=[armtrack126] +conditional_height=2000 + + + +for file in filenames: + #zt=file.variables['z'][:] + zh=file.variables['zh'][:] + time_t=file.variables['time'][:] + u=file.variables['u'][:,:] + v=file.variables['v'][:,:] + w=file.variables['w'][:,:] + + + + if file == ricod: + for file1 in ricofilenames: + ht=file1.variables['ht'][:] + cb=file1.variables['cb'][:] + ct=file1.variables['ct'][:] + cv=file1.variables['cv'][:] + cp=file1.variables['cp'][:] + overlap_ratio=file1.variables['chr'][:] + area_proj=file1.variables['area_proj'][:] + nrcloud=file1.variables['nrcloud'][:,:,:] + cfrac=file1.variables['cfrac'][:] + zt=file1.variables['z'][:] + xt=file1.variables['x'][:] + yt=file1.variables['y'][:] + nr=file1.variables['nr'][:] + cld_mask=file1.variables['cld_mask'][:,:,:] + + + nrcloudarray = np.ma.getdata(nrcloud) # unmask array + dx=xt[1]-xt[0];dy=yt[1]-yt[0];dz=zt[1]-zt[0]; + gridarea=dx*dy + gridvol=dx*dy*dz + nx=xt.size;ny=yt.size;nz=zt.size; + + + uz=np.mean(u,axis=0) # avg among diff times + vz=np.mean(v,axis=0) # avg among diff times + wz=np.mean(w,axis=0) + + wint=interp1d(zh,wz,axis=0) + wz1=wint(zt) + + + one=np.ones(wz1.size) + + duz=np.gradient(uz) # central diff in uz + dvz=np.gradient(vz) + + s_u=duz/np.maximum(wz1,one) + s_v=dvz/np.maximum(wz1,one) + + #Gmean=(s_u*s_v)**(0.5) + #Amean=(s_u+s_v)/2 + #H=Gmean**2/Amean + Hmean=(2*s_u*s_v) / (s_u + s_v) + shear0=np.zeros(cb.size) + shear1=np.zeros(cb.size) + for i in range(cb.size): + """ + du=uz[ct[i]]-uz[cb[i]] + dv=vz[ct[i]]-vz[cb[i]] + w1=np.mean(wz1[cb[i]:ct[i]+1]) + su=du/max(w1,1) + sv=dv/max(w1,1) + Hmean=(2*su*sv) / max( (su + sv) , 1) + shear0[i]=Hmean + """ + shear0[i] = sum(Hmean[cb[i]:ct[i]+1]) # since max(w,1)=1 s_u,s_v = duz, dvz + + #shear0[i] = np.mean(Hmean[cb[i]:ct[i]+1]) + #shear0[i] = Hmean[ct[i]] - Hmean[cb[i]] + bins=2*dz + + plt.figure() + plt.hist2d(overlap_ratio,abs(shear0),bins=bins,cmin=0.5) + plt.title('shear vs. overlap') + #plt.ylim([min(shear0),max(shear0)]) + colorbar = plt.colorbar() + colorbar.set_label('counts in bin') + + + + + + + + + + +################################### + +end= time.time() +print('Run Time in Seconds:', end-start) + + + + + + + + + + + + + + + + + + + + + + + +