import numpy as np
import netCDF4 as nc
import matplotlib.pyplot as plt
%matplotlib inline
fPAR=nc.Dataset('/results2/SalishSea/nowcast-green.201905/01apr16/SalishSea_1h_20160401_20160401_carp_T.nc')
fPAR.variables.keys()
dict_keys(['nav_lat', 'nav_lon', 'bounds_lon', 'bounds_lat', 'area', 'deptht', 'deptht_bounds', 'PAR', 'time_centered', 'time_centered_bounds', 'time_counter', 'time_counter_bounds', 'sigma_theta', 'e3t', 'Fraser_tracer', 'dissolved_inorganic_carbon', 'total_alkalinity', 'dissolved_oxygen'])
fk=nc.Dataset('/results2/SalishSea/nowcast-green.201905/01apr16/SalishSea_1h_20160401_20160401_grid_W.nc')
fk.variables.keys()
dict_keys(['nav_lat', 'nav_lon', 'bounds_lon', 'bounds_lat', 'area', 'depthw', 'depthw_bounds', 'vovecrtz', 'time_centered', 'time_centered_bounds', 'time_counter', 'time_counter_bounds', 'vert_eddy_diff', 'vert_eddy_visc', 'dissipation'])
fk.close()
with nc.Dataset('/ocean/eolson/MEOPAR/NEMO-forcing/grid/mesh_mask201702_noLPE.nc') as mesh:
navlon=mesh.variables['nav_lon'][:,:]
navlat=mesh.variables['nav_lat'][:,:]
tmask=mesh.variables['tmask'][0,:,:,:]
z=mesh.variables['gdept_1d'][0,:]
zw=mesh.variables['gdepw_1d'][0,:]
ii=250
jj=500
plt.contour(tmask[0,:,:])
plt.plot(ii,jj,'r*')
[<matplotlib.lines.Line2D at 0x7f1a151d0880>]
plt.plot(fPAR.variables['PAR'][:,:,jj,ii]); # not land!
dailyPAR=np.mean(fPAR.variables['PAR'][:,:,jj,ii],0)
np.shape(dailyPAR)
(40,)
plt.plot(dailyPAR,-1*z,'r-')
plt.xlabel('PAR');
plt.ylabel('Depth(m)');
LL=0.1 # choose 10% light level
xx=dailyPAR>LL*dailyPAR[0]
xx
masked_array(data=[ True, True, True, True, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False], mask=False, fill_value=True)
# want the w-index between the last true value and the first false value:
# w0 T0 w1 T1 w2 T2
# T T F
# in case above, correct index would be 2: sum of Trues
kk=np.sum(xx)
print(kk)
5
kprof=np.mean(fk.variables['vert_eddy_diff'][:,:,jj,ii],0)
plt.plot(kprof,-1*zw,'r-')
plt.xlabel('k');
plt.ylabel('Depth(m)');
kprof[5]
0.0003141591
def getVEDEuph(ii,jj,LL,fileK,filePAR):
dailyPAR=np.mean(fPAR.variables['PAR'][:,:,jj,ii],0)
kk=np.sum(dailyPAR>LL*dailyPAR[0])
kprof=np.mean(fk.variables['vert_eddy_diff'][:,:,jj,ii],0)
return kprof[kk]
getVEDEuph(ii,jj,LL,fk,fPAR)
0.0003141591