import matplotlib.pyplot as plt
import xarray as xr
import cmocean.cm as cmo
import numpy as np
import my_functions as my
import gsw
from matplotlib.dates import date2num
import matplotlib.dates as mdates
import my_plot_params
dat_saz = xr.open_dataset('../data/dat_saz_6H.nc')
dat_pfz = xr.open_dataset('../data/dat_pfz_6H.nc')
dat_miz = xr.open_dataset('../data/dat_miz_6H.nc')
mld_05 = my.calc_mld(dat_saz.density.values, dat_saz.depth.values, den_lim=0.03)
for i, data in enumerate([dat_saz, dat_pfz, dat_miz]):
data['mld_03'] = (('time'), my.calc_mld(data.density.values, data.depth.values, den_lim=0.03))
mld = data['mld_03'].astype(int).values
mld_15 = (data['mld_03'].values*1.5).astype(int)
QI = np.ndarray(mld.shape)
for i, val in enumerate(mld):
den_mld = data['density'].isel(time=i)[:val].values
den_mld_mean = data['density'].isel(time=i)[:val].mean().values
rmse_mld = np.std(den_mld[den_mld>0]-den_mld_mean)
val_15 = mld_15[i]
den_mld_15 = data['density'].isel(time=i)[:val_15].values
den_mld_mean_15 = data['density'].isel(time=i)[:val_15].mean().values
rmse_mld_15 = np.std(den_mld_15[den_mld_15>0]-den_mld_mean_15)
QI[i] = 1 - (rmse_mld/rmse_mld_15)
good = QI>0.8
ok = ((QI<0.8) & (QI>0.5))
bad = QI<0.5
good = data.sel(time=good)
ok = data.sel(time=ok)
bad = data.sel(time=bad)
print('good: '+str(100*len(good.time)/len(data.time)))
print('ok: ' +str(100*len(ok.time) /len(data.time)))
print('bad: ' +str(100*len(bad.time) /len(data.time)))
good: 65.04065040650407 ok: 22.22222222222222 bad: 12.737127371273713 good: 86.58892128279884 ok: 13.119533527696793 bad: 0.2915451895043732 good: 85.96059113300493 ok: 11.576354679802956 bad: 2.4630541871921183
fig,ax = plt.subplots(1,3,figsize=[12, 7])
prof=[15,19,20]
dat = bad
for i,val in enumerate(prof):
ax[i].plot(dat.density.isel(time=i), dat.depth)
xmin=dat.density.isel(time=i).min()-0.05
xmax=dat.density.isel(time=i).max()+0.05
ax[i].hlines(y=dat.mld_03.isel(time=i), xmin=xmin, xmax=xmax, colors='orange')
ax[i].text(xmax-0.2, dat.mld_03.isel(time=i)-4, 'MLD', color='orange', fontweight='bold', fontsize=18)
ax[i].set_ylim(120, 0)
ax[i].set_xlabel('Density')
ax[0].set_ylabel('Depth (m)')
plt.savefig('../figs_submission2/MLD_03_QI_bad_profiles.png')
return np.mean(np.sqrt((data-data_mean)**2))
rho_mld =
QI = 1 - ( rmse() )
dat_saz
<xarray.Dataset> Dimensions: (time: 369, depth: 1000) Coordinates: * time (time) datetime64[ns] 2018-12-10T03:00:00 ... 2019-03-12T03:... * depth (depth) int64 0 1 2 3 4 5 6 7 ... 993 994 995 996 997 998 999 Data variables: (12/25) temp (time, depth) float64 ... salt (time, depth) float64 ... lat (time) float64 -43.01 -43.01 -43.0 ... -43.06 -43.05 -43.07 lon (time) float64 7.793 7.768 7.791 7.796 ... 7.845 7.812 7.84 density (time, depth) float64 ... mld_01 (time) float64 18.5 16.33 13.5 56.0 ... 23.0 12.0 14.0 16.09 ... ... v10 (time) float64 -5.411 -7.296 -5.422 ... -5.715 -7.256 -8.585 emp (time) float64 -1.539e-07 -5.5e-07 ... -5.452e-09 -1.584e-10 qnet (time) float64 29.03 114.1 336.4 -24.47 ... 479.6 -19.01 -53.45 taux (time) float64 0.01897 0.006262 0.154 ... 0.02407 0.0184 tauy (time) float64 0.04108 0.07468 0.04125 ... 0.07386 0.1034 wind_dir (time) float64 145.8 163.8 117.5 104.8 ... 139.6 150.3 157.1
array(['2018-12-10T03:00:00.000000000', '2018-12-10T09:00:00.000000000', '2018-12-10T15:00:00.000000000', ..., '2019-03-11T15:00:00.000000000', '2019-03-11T21:00:00.000000000', '2019-03-12T03:00:00.000000000'], dtype='datetime64[ns]')
array([ 0, 1, 2, ..., 997, 998, 999])
[369000 values with dtype=float64]
[369000 values with dtype=float64]
array([-43.006263, -43.011623, -42.997761, ..., -43.064249, -43.05387 , -43.069294])
array([7.793245, 7.76753 , 7.790743, ..., 7.844832, 7.812302, 7.840295])
[369000 values with dtype=float64]
array([18.5 , 16.333333, 13.5 , ..., 12. , 14. , 16.090909])
array([33, 23, 17, ..., 21, 19, 20])
array([55.5, 45. , 25. , ..., 75.5, 72.5, 67.6])
array([34.41897 , 34.399728, 34.388702, ..., 34.302915, 34.268899, 34.295981])
array([ 9.854524, 10.048495, 10.095912, ..., 10.898697, 10.894768, 10.914142])
array([34.41897 , 34.409349, 34.402466, ..., 34.295981, 34.28244 , 34.289265])
array([ 9.854524, 9.95151 , 9.999644, ..., 10.914142, 10.904455, 10.902536])
array([13.954661, 25.123945, 26.949689, ..., 2.248325, -4.720416, 0.429084])
array([11.837689, 16.45183 , 24.952173, ..., 10.186199, 18.526326, 21.81248 ])
array([ 1.51495 , 6.22869 , 3.456568, ..., -70.858184, -38.217139, -75.687212])
array([ 1.720327, 66.312018, 280.994889, ..., 538.043446, 5.398018, 0. ])
array([1.594394e-07, 5.600857e-07, 1.637079e-08, ..., 3.205024e-10, 3.564480e-09, 3.296686e-10])
array([ 5.580817e-09, 1.004437e-08, 1.077692e-08, ..., 8.985727e-10, -1.887843e-09, 1.712921e-10])
array([ 3.677113, 2.112693, 10.403774, ..., 4.871303, 4.14196 , 3.621836])
array([-5.41138 , -7.295569, -5.422169, ..., -5.714827, -7.255525, -8.584786])
array([-1.538585e-07, -5.500414e-07, -5.593868e-09, ..., 5.780704e-10, -5.452323e-09, -1.583765e-10])
array([ 29.027627, 114.116483, 336.353319, ..., 479.619786, -19.013212, -53.445648])
array([0.01897 , 0.006262, 0.154004, ..., 0.033293, 0.02407 , 0.018404])
array([0.041084, 0.074675, 0.041248, ..., 0.045821, 0.073858, 0.103399])
array([145.803313, 163.849737, 117.527321, ..., 139.555818, 150.279258, 157.125601])