from netCDF4 import Dataset
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import xarray as xr
from xgcm import Grid
import numpy as np
import cmocean
import warnings
warnings.filterwarnings("ignore")
print('done')
done
%cd /glade/scratch/eyankovsky/Backscatter_tests_with_Scott/Half_degree/Jansen_EBT_test2/
fs = xr.open_dataset('static.nc', decode_times=False)
os = xr.open_dataset('ocean.stats.nc', decode_times=False)
av= xr.open_dataset('averages_00031502.nc', decode_times=False)
%cd /glade/p/univ/unyu0004/gmarques/NeverWorld2/baselines/nw2_0.03125deg_N15_baseline_hmix5/
fs_hr = xr.open_dataset('static.nc', decode_times=False)
av_hr = xr.open_dataset('averages_00002502.nc', decode_times=False)
%cd /glade/p/univ/unyu0004/eyankovsky/NeverWorld_analysis/
/glade/scratch/eyankovsky/Backscatter_tests_with_Scott/Half_degree/Jansen_EBT_test2 /glade/campaign/univ/unyu0004/NeverWorld2/nw2_0.03125deg_N15_baseline_hmix5 /glade/p/univ/unyu0004/eyankovsky/NeverWorld_analysis
print(av.p_ebt)
<xarray.DataArray 'p_ebt' (time: 100, zl: 15, yh: 280, xh: 120)> [50400000 values with dtype=float32] Coordinates: * xh (xh) float64 0.25 0.75 1.25 1.75 2.25 ... 58.25 58.75 59.25 59.75 * yh (yh) float64 -69.75 -69.25 -68.75 -68.25 ... 68.75 69.25 69.75 * zl (zl) float64 1.023e+03 1.023e+03 1.023e+03 ... 1.028e+03 1.028e+03 * time (time) float64 3.15e+04 3.151e+04 3.151e+04 ... 3.199e+04 3.2e+04 Attributes: long_name: Equivalent barotropic modal strcuture units: nondim cell_methods: area:mean zl:mean yh:mean xh:mean time: mean cell_measures: area: area_t time_avg_info: average_T1,average_T2,average_DT
av.p_ebt[-1,:,30,40].plot()
[<matplotlib.lines.Line2D at 0x2b4341922410>]
plt.plot(av.h[-1,:,30,40].cumsum(),av.p_ebt[-1,:,30,40]**2)
[<matplotlib.lines.Line2D at 0x2b433c101bd0>]
h = np.array(av['h'][:,:,:,:]);
h.shape
(100, 15, 280, 120)
av
<xarray.Dataset> Dimensions: (nv: 2, time: 100, xh: 120, xq: 121, yh: 280, yq: 281, zi: 16, zl: 15) Coordinates: * xh (xh) float64 0.25 0.75 1.25 1.75 ... 58.25 58.75 59.25 59.75 * yh (yh) float64 -69.75 -69.25 -68.75 -68.25 ... 68.75 69.25 69.75 * zl (zl) float64 1.023e+03 1.023e+03 ... 1.028e+03 1.028e+03 * time (time) float64 3.15e+04 3.151e+04 ... 3.199e+04 3.2e+04 * nv (nv) float64 1.0 2.0 * xq (xq) float64 0.0 0.5 1.0 1.5 2.0 ... 58.0 58.5 59.0 59.5 60.0 * yq (yq) float64 -70.0 -69.5 -69.0 -68.5 ... 68.5 69.0 69.5 70.0 * zi (zi) float64 1.022e+03 1.023e+03 ... 1.028e+03 1.028e+03 Data variables: KHTH_t (time, zl, yh, xh) float32 ... GMwork (time, yh, xh) float32 ... SSU (time, yh, xq) float32 ... SSV (time, yq, xh) float32 ... u (time, zl, yh, xq) float32 ... v (time, zl, yq, xh) float32 ... h (time, zl, yh, xh) float32 ... e2 (time, zi, yh, xh) float32 ... e (time, zi, yh, xh) float32 ... uh (time, zl, yh, xq) float32 ... vh (time, zl, yq, xh) float32 ... PV (time, zl, yq, xq) float32 ... dudt (time, zl, yh, xq) float32 ... dvdt (time, zl, yq, xh) float32 ... CAu (time, zl, yh, xq) float32 ... CAv (time, zl, yq, xh) float32 ... rvxu (time, zl, yq, xh) float32 ... rvxv (time, zl, yh, xq) float32 ... gKEu (time, zl, yh, xq) float32 ... gKEv (time, zl, yq, xh) float32 ... PFu (time, zl, yh, xq) float32 ... PFv (time, zl, yq, xh) float32 ... diffu (time, zl, yh, xq) float32 ... diffv (time, zl, yq, xh) float32 ... du_dt_visc (time, zl, yh, xq) float32 ... dv_dt_visc (time, zl, yq, xh) float32 ... u_BT_accel (time, zl, yh, xq) float32 ... v_BT_accel (time, zl, yq, xh) float32 ... KE (time, zl, yh, xh) float32 ... dKE_dt (time, zl, yh, xh) float32 ... PE_to_KE (time, zl, yh, xh) float32 ... KE_BT (time, zl, yh, xh) float32 ... KE_CorAdv (time, zl, yh, xh) float32 ... KE_adv (time, zl, yh, xh) float32 ... KE_visc (time, zl, yh, xh) float32 ... KE_horvisc (time, zl, yh, xh) float32 ... Rd_dx (time, yh, xh) float32 ... Rd1 (time, yh, xh) float32 ... p_ebt (time, zl, yh, xh) float32 ... average_T1 (time) float64 3.15e+04 3.150e+04 ... 3.199e+04 3.2e+04 average_T2 (time) float64 3.150e+04 3.151e+04 3.152e+04 ... 3.2e+04 3.2e+04 average_DT (time) float64 5.0 5.0 5.0 5.0 5.0 5.0 ... 5.0 5.0 5.0 5.0 5.0 time_bnds (time, nv) float64 3.15e+04 3.150e+04 ... 3.2e+04 3.2e+04 Attributes: filename: averages_00031502.nc title: NeverWorld2 associated_files: area_t: static.nc grid_type: regular grid_tile: N/A
array([ 0.25, 0.75, 1.25, 1.75, 2.25, 2.75, 3.25, 3.75, 4.25, 4.75, 5.25, 5.75, 6.25, 6.75, 7.25, 7.75, 8.25, 8.75, 9.25, 9.75, 10.25, 10.75, 11.25, 11.75, 12.25, 12.75, 13.25, 13.75, 14.25, 14.75, 15.25, 15.75, 16.25, 16.75, 17.25, 17.75, 18.25, 18.75, 19.25, 19.75, 20.25, 20.75, 21.25, 21.75, 22.25, 22.75, 23.25, 23.75, 24.25, 24.75, 25.25, 25.75, 26.25, 26.75, 27.25, 27.75, 28.25, 28.75, 29.25, 29.75, 30.25, 30.75, 31.25, 31.75, 32.25, 32.75, 33.25, 33.75, 34.25, 34.75, 35.25, 35.75, 36.25, 36.75, 37.25, 37.75, 38.25, 38.75, 39.25, 39.75, 40.25, 40.75, 41.25, 41.75, 42.25, 42.75, 43.25, 43.75, 44.25, 44.75, 45.25, 45.75, 46.25, 46.75, 47.25, 47.75, 48.25, 48.75, 49.25, 49.75, 50.25, 50.75, 51.25, 51.75, 52.25, 52.75, 53.25, 53.75, 54.25, 54.75, 55.25, 55.75, 56.25, 56.75, 57.25, 57.75, 58.25, 58.75, 59.25, 59.75])
array([-69.75, -69.25, -68.75, ..., 68.75, 69.25, 69.75])
array([1022.6 , 1022.81, 1023.2 , 1023.74, 1024.32, 1024.9 , 1025.47, 1026. , 1026.48, 1026.9 , 1027.27, 1027.58, 1027.82, 1027.99, 1028.1 ])
array([31502.5, 31507.5, 31512.5, 31517.5, 31522.5, 31527.5, 31532.5, 31537.5, 31542.5, 31547.5, 31552.5, 31557.5, 31562.5, 31567.5, 31572.5, 31577.5, 31582.5, 31587.5, 31592.5, 31597.5, 31602.5, 31607.5, 31612.5, 31617.5, 31622.5, 31627.5, 31632.5, 31637.5, 31642.5, 31647.5, 31652.5, 31657.5, 31662.5, 31667.5, 31672.5, 31677.5, 31682.5, 31687.5, 31692.5, 31697.5, 31702.5, 31707.5, 31712.5, 31717.5, 31722.5, 31727.5, 31732.5, 31737.5, 31742.5, 31747.5, 31752.5, 31757.5, 31762.5, 31767.5, 31772.5, 31777.5, 31782.5, 31787.5, 31792.5, 31797.5, 31802.5, 31807.5, 31812.5, 31817.5, 31822.5, 31827.5, 31832.5, 31837.5, 31842.5, 31847.5, 31852.5, 31857.5, 31862.5, 31867.5, 31872.5, 31877.5, 31882.5, 31887.5, 31892.5, 31897.5, 31902.5, 31907.5, 31912.5, 31917.5, 31922.5, 31927.5, 31932.5, 31937.5, 31942.5, 31947.5, 31952.5, 31957.5, 31962.5, 31967.5, 31972.5, 31977.5, 31982.5, 31987.5, 31992.5, 31997.5])
array([1., 2.])
array([ 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. , 5.5, 6. , 6.5, 7. , 7.5, 8. , 8.5, 9. , 9.5, 10. , 10.5, 11. , 11.5, 12. , 12.5, 13. , 13.5, 14. , 14.5, 15. , 15.5, 16. , 16.5, 17. , 17.5, 18. , 18.5, 19. , 19.5, 20. , 20.5, 21. , 21.5, 22. , 22.5, 23. , 23.5, 24. , 24.5, 25. , 25.5, 26. , 26.5, 27. , 27.5, 28. , 28.5, 29. , 29.5, 30. , 30.5, 31. , 31.5, 32. , 32.5, 33. , 33.5, 34. , 34.5, 35. , 35.5, 36. , 36.5, 37. , 37.5, 38. , 38.5, 39. , 39.5, 40. , 40.5, 41. , 41.5, 42. , 42.5, 43. , 43.5, 44. , 44.5, 45. , 45.5, 46. , 46.5, 47. , 47.5, 48. , 48.5, 49. , 49.5, 50. , 50.5, 51. , 51.5, 52. , 52.5, 53. , 53.5, 54. , 54.5, 55. , 55.5, 56. , 56.5, 57. , 57.5, 58. , 58.5, 59. , 59.5, 60. ])
array([-70. , -69.5, -69. , ..., 69. , 69.5, 70. ])
array([1022.495, 1022.705, 1023.005, 1023.47 , 1024.03 , 1024.61 , 1025.185, 1025.735, 1026.24 , 1026.69 , 1027.085, 1027.425, 1027.7 , 1027.905, 1028.045, 1028.155])
[50400000 values with dtype=float32]
[3360000 values with dtype=float32]
[3388000 values with dtype=float32]
[3372000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50400000 values with dtype=float32]
[53760000 values with dtype=float32]
[53760000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[51001500 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50580000 values with dtype=float32]
[50820000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50820000 values with dtype=float32]
[50580000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[50400000 values with dtype=float32]
[3360000 values with dtype=float32]
[3360000 values with dtype=float32]
[50400000 values with dtype=float32]
array([31500., 31505., 31510., 31515., 31520., 31525., 31530., 31535., 31540., 31545., 31550., 31555., 31560., 31565., 31570., 31575., 31580., 31585., 31590., 31595., 31600., 31605., 31610., 31615., 31620., 31625., 31630., 31635., 31640., 31645., 31650., 31655., 31660., 31665., 31670., 31675., 31680., 31685., 31690., 31695., 31700., 31705., 31710., 31715., 31720., 31725., 31730., 31735., 31740., 31745., 31750., 31755., 31760., 31765., 31770., 31775., 31780., 31785., 31790., 31795., 31800., 31805., 31810., 31815., 31820., 31825., 31830., 31835., 31840., 31845., 31850., 31855., 31860., 31865., 31870., 31875., 31880., 31885., 31890., 31895., 31900., 31905., 31910., 31915., 31920., 31925., 31930., 31935., 31940., 31945., 31950., 31955., 31960., 31965., 31970., 31975., 31980., 31985., 31990., 31995.])
array([31505., 31510., 31515., 31520., 31525., 31530., 31535., 31540., 31545., 31550., 31555., 31560., 31565., 31570., 31575., 31580., 31585., 31590., 31595., 31600., 31605., 31610., 31615., 31620., 31625., 31630., 31635., 31640., 31645., 31650., 31655., 31660., 31665., 31670., 31675., 31680., 31685., 31690., 31695., 31700., 31705., 31710., 31715., 31720., 31725., 31730., 31735., 31740., 31745., 31750., 31755., 31760., 31765., 31770., 31775., 31780., 31785., 31790., 31795., 31800., 31805., 31810., 31815., 31820., 31825., 31830., 31835., 31840., 31845., 31850., 31855., 31860., 31865., 31870., 31875., 31880., 31885., 31890., 31895., 31900., 31905., 31910., 31915., 31920., 31925., 31930., 31935., 31940., 31945., 31950., 31955., 31960., 31965., 31970., 31975., 31980., 31985., 31990., 31995., 32000.])
array([5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])
array([[31500., 31505.], [31505., 31510.], [31510., 31515.], [31515., 31520.], [31520., 31525.], [31525., 31530.], [31530., 31535.], [31535., 31540.], [31540., 31545.], [31545., 31550.], [31550., 31555.], [31555., 31560.], [31560., 31565.], [31565., 31570.], [31570., 31575.], [31575., 31580.], [31580., 31585.], [31585., 31590.], [31590., 31595.], [31595., 31600.], [31600., 31605.], [31605., 31610.], [31610., 31615.], [31615., 31620.], [31620., 31625.], [31625., 31630.], [31630., 31635.], [31635., 31640.], [31640., 31645.], [31645., 31650.], [31650., 31655.], [31655., 31660.], [31660., 31665.], [31665., 31670.], [31670., 31675.], [31675., 31680.], [31680., 31685.], [31685., 31690.], [31690., 31695.], [31695., 31700.], [31700., 31705.], [31705., 31710.], [31710., 31715.], [31715., 31720.], [31720., 31725.], [31725., 31730.], [31730., 31735.], [31735., 31740.], [31740., 31745.], [31745., 31750.], [31750., 31755.], [31755., 31760.], [31760., 31765.], [31765., 31770.], [31770., 31775.], [31775., 31780.], [31780., 31785.], [31785., 31790.], [31790., 31795.], [31795., 31800.], [31800., 31805.], [31805., 31810.], [31810., 31815.], [31815., 31820.], [31820., 31825.], [31825., 31830.], [31830., 31835.], [31835., 31840.], [31840., 31845.], [31845., 31850.], [31850., 31855.], [31855., 31860.], [31860., 31865.], [31865., 31870.], [31870., 31875.], [31875., 31880.], [31880., 31885.], [31885., 31890.], [31890., 31895.], [31895., 31900.], [31900., 31905.], [31905., 31910.], [31910., 31915.], [31915., 31920.], [31920., 31925.], [31925., 31930.], [31930., 31935.], [31935., 31940.], [31940., 31945.], [31945., 31950.], [31950., 31955.], [31955., 31960.], [31960., 31965.], [31965., 31970.], [31970., 31975.], [31975., 31980.], [31980., 31985.], [31985., 31990.], [31990., 31995.], [31995., 32000.]])
Layer = np.array(os['Layer']);
Interface = np.array(os['Interface']); drho=np.diff(Interface)
indexlat = 230 #190,230,40
indexlon = 30 #30
# #computing EKE for high-res case:
# u_hr = av_hr.u[:,:,indexlat*16,indexlon*16]-av_hr.u[:,:,indexlat*16,indexlon*16].mean('time')
# v_hr = av_hr.v[:,:,indexlat*16,indexlon*16]-av_hr.v[:,:,indexlat*16,indexlon*16].mean('time')
# EKE_hr = (((u_hr**2).values+(v_hr**2).values)*0.5).mean(axis=0)
# EKE_hr.shape
# u_hr = av_hr.u[:,:,indexlat*16,indexlon*16]
# v_hr = av_hr.v[:,:,indexlat*16,indexlon*16]
# KE_hr = (u_hr.values**2+v_hr.values**2).mean(axis=0)*0.5
# #computing EKE for low-res case:
# u = av.u[:,:,indexlat,indexlon]-av.u[:,:,indexlat,indexlon].mean('time')
# v = av.v[:,:,indexlat,indexlon]-av.v[:,:,indexlat,indexlon].mean('time')
# EKE_lr = (((u**2).values+(v**2).values)*0.5).mean(axis=0)
# EKE_lr.shape
#Unparameterized 1/2 degree run:
%cd /glade/p/univ/unyu0004/eyankovsky/MEKE_testing/default_noparameterization
av_unparam=xr.open_dataset('averages_00031502.nc',decode_times=False)
# u = av_unparam.u[:,:,indexlat,indexlon]-av_unparam.u[:,:,indexlat,indexlon].mean('time')
# v = av_unparam.v[:,:,indexlat,indexlon]-av_unparam.v[:,:,indexlat,indexlon].mean('time')
# EKE_unparam = (((u**2).values+(v**2).values)*0.5).mean(axis=0)
# EKE_unparam.shape
/glade/p/univ/unyu0004/eyankovsky/MEKE_testing/default_noparameterization
h = np.array(av['h'][:,:,indexlat,indexlon]);
eta = np.zeros([100,len(Layer)+1]);
h_unparam = np.array(av_unparam['h'][:,:,indexlat,indexlon]);
eta_unparam = np.zeros([100,len(Layer)+1]);
hhr = np.array(av_hr['h'][0:20,:,indexlat*16,indexlon*16]);
etahr = np.zeros([20,len(Layer)+1]);
for i in range(1,len(Layer)+1):
for j in range(0,20):
etahr[j,i]=np.nansum(hhr[j,0:i])
for j in range(0,100):
eta[j,i]=np.nansum(h[j,0:i])
for j in range(0,100):
eta_unparam[j,i]=np.nansum(h_unparam[j,0:i])
print(i)
eta[:,:-1]=(eta[:,1:]+eta[:,:-1])/2.
eta_unparam[:,:-1]=(eta_unparam[:,1:]+eta_unparam[:,:-1])/2.
etahr[:-1]=(etahr[1:]+etahr[:-1])/2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(3, 6),dpi=150)
# #plt.style.use('default')
# #plt.plot(av.p_ebt[0,:,230,30],av.p_ebt[0,:,230,30].zl)
# #plt.plot(av.p_ebt[0,:,40,30],av.p_ebt[0,:,230,30].zl)
# plt.plot(av.p_ebt[:,:,indexlat,indexlon].mean('time'),-np.nanmean(eta,axis=0)[0:-1],'seagreen')
# plt.plot(av.p_ebt[:,:,indexlat,indexlon].mean('time')**2,-np.nanmean(eta,axis=0)[0:-1],color='orange')
# plt.plot(EKE_hr/np.nanmax(EKE_hr),-np.nanmean(etahr,axis=0)[0:-1],'--',color='k')
# plt.plot(EKE_unparam/np.nanmax(EKE_unparam),-np.nanmean(eta_unparam,axis=0)[0:-1],'--',color='tomato')
# plt.plot(EKE_lr/np.nanmax(EKE_lr),-np.nanmean(eta,axis=0)[0:-1],'--',color='royalblue')
# #plt.plot(av.p_ebt[:,:,40,30].mean('time'),av.p_ebt[0,:,230,30].zl)
# plt.grid()
# plt.legend(['$\Psi_{EBT}$','$\Psi_{EBT}^2$','High-res. EKE','Low-res. Unparam. EKE','Low-res. Param. EKE'])
# #plt.gca().invert_yaxis()
# #plt.plot([0, 0],[0, -4000],'--',color=[0,0,0])
# plt.xlim(0, 1)
# plt.ylim(-3500,0);
# plt.xlabel('Amplitude')
# plt.ylabel('Depth')
# plt.title('Subtropics (25$^\circ$N, 15$^\circ$E)')
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(3, 6),dpi=150)
#plt.style.use('default')
#plt.plot(av.p_ebt[0,:,230,30],av.p_ebt[0,:,230,30].zl)
#plt.plot(av.p_ebt[0,:,40,30],av.p_ebt[0,:,230,30].zl)
plt.plot(av.p_ebt[:,:,indexlat,indexlon].mean('time'),-np.nanmean(eta,axis=0)[0:-1],'-o',color='purple',markersize=4)
plt.plot(av.p_ebt[:,:,indexlat,indexlon].mean('time')**2,-np.nanmean(eta,axis=0)[0:-1],'-o',color='orchid',markersize=4)
#plt.plot(av.p_ebt[:,:,indexlat,indexlon].mean('time')**4,-np.nanmean(eta,axis=0)[0:-1],color='gold')
#plt.plot(av.p_ebt[:,:,indexlat,indexlon].mean('time')**6,-np.nanmean(eta,axis=0)[0:-1],color='violet')
etahr[:,-2]=eta[0:20,-2]
#plt.plot(EKE_hr/np.nanmax(EKE_hr),-np.nanmean(etahr,axis=0)[0:-1],'--',color='k')
#plt.plot(KE_hr/np.nanmax(KE_hr),-np.nanmean(etahr,axis=0)[0:-1],color='k')
#plt.plot(EKE_unparam/np.nanmax(EKE_unparam),-np.nanmean(eta_unparam,axis=0)[0:-1],'--',color='tomato')
#plt.plot(EKE_lr/np.nanmax(EKE_lr),-np.nanmean(eta,axis=0)[0:-1],'--',color='royalblue')
#plt.plot(av.p_ebt[:,:,40,30].mean('time'),av.p_ebt[0,:,230,30].zl)
plt.grid()
plt.legend(['$\phi(z)$','$\phi(z)^2$'])
#plt.gca().invert_yaxis()
#plt.plot([0, 0],[0, -4000],'--',color=[0,0,0])
plt.xlim(0, 1)
plt.ylim(-3500,0);
plt.xlabel('Magnitude')
plt.ylabel('Depth')
#plt.title('ACC (50$^\circ$S, 15$^\circ$E)')
plt.title('Northwest (45$^\circ$N, 15$^\circ$E)')
#plt.title('Subtropics (25$^\circ$N, 15$^\circ$E)')
Text(0.5, 1.0, 'Northwest (45$^\\circ$N, 15$^\\circ$E)')