P06 CTD χpod analysis#
import dcpy
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import seawater as sw
import eddydiff as ed
import xarray as xr
Read CTD χpod data and convert to netCDF#
ed.sections.to_netcdf(
infile="/home/deepak/work/eddydiff/datasets/P06/P06.mat",
outfile="/home/deepak/work/eddydiff/datasets/P06/p06-try-again.nc",
transect_name="P06",
)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-102-a748ec0f2bb7> in <module>
2 infile="/home/deepak/work/eddydiff/datasets/P06/P06.mat",
3 outfile="/home/deepak/work/eddydiff/datasets/P06/p06-try-again.nc",
----> 4 transect_name="P06",
5 )
~/work/eddydiff/eddydiff/sections.py in to_netcdf(infile, outfile, transect_name)
24 import seawater as sw
25
---> 26 mat = loadmat(infile, squeeze_me=True)["grd"]
27
28 ctd = xr.Dataset()
KeyError: 'grd'
matold = loadmat("/home/deepak/work/eddydiff/datasets/P06/P06-means.mat")
matold.keys()
dict_keys(['__header__', '__version__', '__globals__', 'lat', 'lon', 'dnum', 'TPvar', 'eps', 'chi', 'KT', 'dTdz', 'N2', 't', 's', 'P', 'Jq', 'dist'])
ed.sections.to_netcdf(
infile="/home/deepak/work/eddydiff/datasets/P06/P06-new.mat",
outfile="/home/deepak/work/eddydiff/datasets/P06/p06-new.nc",
transect_name="P06",
)
Read transect + ancillary datasets#
import eddydiff as ed
p06 = xr.open_dataset("/home/deepak/work/eddydiff/datasets/P06/p06.nc")
bathy = p06.bathy.copy()
p06 = p06.where(p06["KT"] < 3e-3)
p06["bathy"] = bathy
p06["KtTz"] = p06.KT * p06.dTdz
p06
eccograd, argograd, cole, aber = ed.read_all_datasets(kind="monthly", transect=p06)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/ipykernel_launcher.py:3: FutureWarning: The autoclose argument is no longer used by xarray.open_dataset() and is now ignored; it will be removed in a future version of xarray. If necessary, you can control the maximum number of simultaneous open files with xarray.set_options(file_cache_maxsize=...).
This is separate from the ipykernel package so we can avoid doing imports until
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
argograd.Smean.plot(x="cast", yincrease=False)
<matplotlib.collections.QuadMesh at 0x7f173e54d470>
/home/deepak/anaconda3/lib/python3.6/site-packages/_pytest/fixtures.py:847: DeprecationWarning: The `convert` argument is deprecated in favor of `converter`. It will be removed after 2019/01.
params = attr.ib(convert=attr.converters.optional(tuple))
/home/deepak/anaconda3/lib/python3.6/site-packages/_pytest/fixtures.py:849: DeprecationWarning: The `convert` argument is deprecated in favor of `converter`. It will be removed after 2019/01.
ids = attr.ib(default=None, convert=_ensure_immutable_ids)
plots#
np.log10(p06.eps).plot(x="cast")
p06.rho.plot.contour(
colors="k",
x="cast",
yincrease=False,
levels=pd.qcut(p06.rho.values.ravel(), 20, retbins=True)[1],
)
plt.gca().fill_between(p06.cast, 6100, -p06.bathy, color="k", zorder=10)
plt.gcf().set_size_inches(10, 10 / 1.6)
p06["T"].plot(x="cast", cmap=mpl.cm.RdYlBu)
p06.rho.plot.contour(
colors="k",
x="cast",
yincrease=False,
levels=pd.qcut(p06.rho.values.ravel(), 20, retbins=True)[1],
)
plt.gca().fill_between(p06.cast, 6100, -p06.bathy, color="k", zorder=10)
plt.gcf().set_size_inches(10, 10 / 1.6)
import sciviscolor as svc
svc.cm.
p06
%matplotlib inline
### p06['KT'].attrs['long_name'] = '$K_T$'
p06["KT"].attrs["units"] = "m$^2$/s"
p06["P"].attrs["long_name"] = "Pressure"
p06["P"].attrs["units"] = "dbar"
p06["lon"].attrs["long_name"] = "Longitude"
p06["lon"].attrs["units"] = "deg. East"
logKT = np.log10(p06["KT"])
logKT.attrs = p06.KT.attrs
logKT.attrs["long_name"] = "log$_{10}$ $K_T$"
logKT.plot(x="lon", y="P", cmap=mpl.cm.RdYlBu_r, robust=True)
(p06.sigma_4 - 1000).plot.contour(
colors="k",
x="lon",
y="P",
yincrease=False,
labels=False,
levels=pd.qcut(p06.sigma_4.values.ravel() - 1000, 15, retbins=True)[1],
)
plt.gca().fill_between(p06.lon, 6100, -p06.bathy, color="k", zorder=10)
plt.gcf().set_size_inches(10, 10 / 2.5)
plt.gca().set_title(
"Potential density contours and log $K_T$ for the P06 GOSHIP section"
)
plt.savefig("../images/p06-kt.png", bbox_inches="tight")
/home/deepak/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py:1000: UserWarning: The following kwargs were not used by contour: 'labels'
s)
bins = [
1024.6,
1025.6,
1025.8,
1026.0,
1026.25,
1026.5,
1026.75,
1027.0,
1027.1,
1027.2,
1027.3,
1027.4,
1027.5,
1027.6,
1027.7,
1027.8,
1027.9,
]
dcpy.oceans.TSplot(p06.S, p06["T"], p06.pres, rho_levels=bins)
Calculate#
nbins = 18
p06["rho"] = p06["sigma_0"]
eccograd["ρmean"] = eccograd["sigma_0"]
eccoKe = ed.process_transect_1d(p06, eccograd, "ECCO", nbins=nbins)
ed.plot_bar_Ke(eccoKe, Ke_log=True)
argoKe = ed.process_transect_1d(p06, argograd, "ARGO", nbins=nbins)
ed.plot_bar_Ke(argoKe, Ke_log=True)
Calculate 2#
import eddydiff as ed
p06 = xr.open_dataset("/home/deepak/work/eddydiff/datasets/P06/p06-new.nc")
##### get lat, lon, dist from older version
p06old = xr.open_dataset("/home/deepak/work/eddydiff/datasets/P06/p06.nc")
p06old = p06old.where(p06old.time.notnull(), drop=True)
p06 = p06.where(p06.time.notnull(), drop=True)
p06.update(
p06old[["lon", "lat", "bathy"]]
.swap_dims({"cast": "time"})
.reindex(time=p06.time.values, method="nearest")
.drop("cast")
.swap_dims({"time": "cast"})
)
####
bathy = p06.bathy.copy()
p06 = p06.where(p06["KT"] < 1e-3)
p06["bathy"] = bathy
p06["KtTz"] = p06.KT * p06.dTdz
p06
if "eccograd" not in locals():
eccograd, argograd, cole, aber = ed.read_all_datasets(kind="monthly", transect=p06)
# use sigma_0
p06["rho"] = p06["sigma_0"]
eccograd["ρmean"] = eccograd["sigma_0"]
bins = [
1024.6,
1025.6,
1025.8,
1026.0,
1026.5,
1026.9,
1027.0,
1027.1,
1027.2,
1027.3,
1027.4,
1027.5,
1027.6,
1027.7,
1027.8,
1027.9,
]
trdens, bins = ed.bin_to_density_space(p06, bins=bins)
eccograd["dist"] = p06.dist
eccodens, _ = ed.bin_to_density_space(eccograd.rename({"ρmean": "rho"}), bins)
newKe = xr.Dataset()
newKe["KT"] = trdens.KT.mean(dim="cast")
newKe["chi"] = trdens.chi.mean(dim="cast")
newKe["KtTz"] = trdens.KtTz.mean(dim="cast")
newKe["dTiso"] = np.abs(eccodens.dTiso.mean(dim="cast"))
newKe["dTmdz"] = np.abs(eccodens.dTdz.mean(dim="cast"))
newKe["dTdz"] = trdens.dTdz.mean(dim="cast")
newKe["Ke"] = (newKe["chi"] / 2 - np.abs(newKe["KtTz"] * newKe["dTmdz"])) / (
newKe["dTiso"] ** 2
)
df = newKe.to_dataframe()
df.index = np.round(newKe.to_dataframe().index, 3)
ed.plot_bar_Ke(df)
proposal version#
bins = [
1024.6,
1025.6,
1025.8,
1026.0,
1026.15,
1026.3,
1026.45,
1026.6,
1026.8,
1027.0,
1027.1,
1027.2,
1027.3,
1027.4,
1027.5,
1027.6,
1027.7,
1027.8,
1027.9,
]
ed.plot_bar_Ke(newKe.to_dataframe())
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
The above really awesome plot results after a few tweaks.
Doing things in σ_0.
Handcrafted density bins using the T-S diagram as guide. This is really important. Had to fiddle around slightly to not get negative values. Biggest improvement is that I can now resolve thermocline and coarsen the abyss. This is necessary because the big signal is in the thermocline and the abyssal values need to account for topography. Automatically choosing bins by pandas.cut/pandas.qcut would put too many bins down deep and fewer in the thermocline.
Throwing out all KT > 1e-3. This is really important. Will need to QC the values coming out of the CTD_chipod analysis code.
Redid (vectorized) the bin-averaging by cast. This is a better way to do it I think. Have to use pandas so I can groupby using multiple variables.
I tried fitting straight lines to the bin-averaged ECCO field to get dTiso but this seems to under-estimate values. Currently I bin-average dTiso and use that. This might not be crazy because it mirrors what I do with χ and we know that χ has to go along with the appropriate local gradients. i.e. if high χ coincides with high dTiso locally, we want the averaged dTiso to be biased high since averaged χ will be biased high.
f, ax = plt.subplots(2, 2, constrained_layout=True)
Trms = trdens["T"].std(dim="cast")
Trms.name = "RMS potential temp."
Trms.attrs["units"] = "°C"
Trms.plot(ax=ax[0, 0], y="rho", yincrease=False)
newKe.Ke.where(newKe.Ke > 0).plot(marker=".", ax=ax[0, 1], y="rho", yincrease=False)
ax[0, 0].set_ylabel("$σ_0$ [kg/m$^3$]")
ax[0, 1].set_ylabel("$σ_0$ [kg/m$^3$]")
ax[0, 1].set_xlabel("$K_e [m^2/s^2]$ ")
ax[1, 0].plot(newKe.Ke.where(newKe.Ke > 0), trdens.P.mean(dim="cast"), ".-")
ax[1, 0].plot(cole.diffusivity.mean(dim="cast"), cole.P)
ax[1, 0].legend(["χpod estimate", "Cole et al. (2015)"])
ax[1, 0].invert_yaxis()
ax[1, 0].set_ylabel("Pressure [dbar]")
ax[1, 0].set_xlabel("$K_e [m^2/s]$ ")
dcpy.oceans.TSplot(
p06.S,
p06["T"],
rho_levels=bins,
hexbin=False,
ax=ax[1, 1],
size=1,
plot_distrib=False,
)
f.suptitle(p06.transect_name)
f.set_size_inches(8, 10)
plt.savefig("../images/p06.png", bbox_inches="tight")
/home/deepak/work/python/xarray/xarray/core/nanops.py:142: RuntimeWarning: Mean of empty slice
return np.nanmean(a, axis=axis, dtype=dtype)
f, ax = plt.subplots(1, 2, constrained_layout=True)
zvec = trdens.P.mean(dim="cast")
rhovec = newKe.rho
ax[0].plot(newKe.Ke, zvec, ".-")
ax[0].plot(cole.diffusivity.mean(dim="cast"), cole.P)
ax[0].invert_yaxis()
ax[0].set_ylabel("Pressure [dbar]")
ax[0].set_xlabel("Transect-wide mean $K_e [m^2/s]$ ")
ax[0].spines["right"].set_visible(True)
ax[0].spines["top"].set_visible(True)
# https://matplotlib.org/gallery/subplots_axes_and_figures/fahrenheit_celsius_scales.html
ax_z = ax[0]
ax_rho = ax_z.twinx()
ax_rho.set_yticks(ax_z.get_yticks())
ax_rho.invert_yaxis()
ax_rho.set_yticklabels(
[
str(np.round(rr - 1000, 2))
for rr in np.interp(ax_z.get_yticks(), zvec, rhovec.values)
]
)
ax_rho.set_ylabel("$σ_0$ [kg/m$^3$]")
ax_rho.set_ylim(ax_z.get_ylim())
ax[0].plot(
[
aber.mean(dim="cast").K_OC_LAT,
aber.mean(dim="cast").K_OC_PSI,
aber.mean(dim="cast").K_OC_SST,
],
[0, 0, 0],
"ro",
)
ax[0].legend(
["χpod estimate", "Cole et al. (2015)", "Abernathey & Marshall (2013)"],
loc="lower right",
)
dcpy.oceans.TSplot(
p06.S, p06.T, 0, rho_levels=bins, ax=ax[1], size=1, hexbin=False, plot_distrib=False
)
f.suptitle(p06.transect_name)
f.set_size_inches(8, 5)
# plt.savefig("../images/p06-Ke.png", bbox_inches="tight")
/home/deepak/work/python/xarray/xarray/core/nanops.py:142: RuntimeWarning: Mean of empty slice
return np.nanmean(a, axis=axis, dtype=dtype)
newKe.Ke.where(newKe.Ke > 0).isel(
cast=slice(240)
) # .coarsen(cast=5).mean().plot(x="cast", norm=mpl.colors.LogNorm(0.1, 5e3), robust=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-259-9f6bb7b7d953> in <module>
----> 1 newKe.Ke.where(newKe.Ke > 0).isel(cast=slice(240)) #.coarsen(cast=5).mean().plot(x="cast", norm=mpl.colors.LogNorm(0.1, 5e3), robust=True)
~/work/python/xarray/xarray/core/dataarray.py in isel(self, indexers, drop, missing_dims, **indexers_kwargs)
1051 # lists, or zero or one-dimensional np.ndarray's
1052
-> 1053 variable = self._variable.isel(indexers, missing_dims=missing_dims)
1054
1055 coords = {}
~/work/python/xarray/xarray/core/variable.py in isel(self, indexers, missing_dims, **indexers_kwargs)
1062
1063 key = tuple(indexers.get(dim, slice(None)) for dim in self.dims)
-> 1064 return self[key]
1065
1066 def squeeze(self, dim=None):
~/work/python/xarray/xarray/core/variable.py in __getitem__(self, key)
702 array `x.values` directly.
703 """
--> 704 dims, indexer, new_order = self._broadcast_indexes(key)
705 data = as_indexable(self._data)[indexer]
706 if new_order:
~/work/python/xarray/xarray/core/variable.py in _broadcast_indexes(self, key)
541
542 if all(isinstance(k, BASIC_INDEXING_TYPES) for k in key):
--> 543 return self._broadcast_indexes_basic(key)
544
545 self._validate_indexers(key)
~/work/python/xarray/xarray/core/variable.py in _broadcast_indexes_basic(self, key)
569 dim for k, dim in zip(key, self.dims) if not isinstance(k, integer_types)
570 )
--> 571 return dims, BasicIndexer(key), None
572
573 def _validate_indexers(self, key):
~/work/python/xarray/xarray/core/indexing.py in __init__(self, key)
376 new_key.append(k)
377
--> 378 super().__init__(new_key)
379
380
~/work/python/xarray/xarray/core/indexing.py in __init__(self, key)
329 if type(self) is ExplicitIndexer:
330 raise TypeError("cannot instantiate base ExplicitIndexer objects")
--> 331 self._key = tuple(key)
332
333 @property
TypeError: descriptor '_key' for 'ExplicitIndexer' objects doesn't apply to 'BasicIndexer' object
Linear fits to ECCO T along ρ surfaces in the along-transect direction doesn’t work. The field has too much curvature
# recalculate gradients from mean fields in density space
dTiso = xr.ones_like(eccodens.rho) * np.nan
dTiso.name = "dTiso"
dTdz = xr.ones_like(eccodens.rho) * np.nan
dTdz.name = "dTdz"
for idx, rr in enumerate(eccodens.rho):
Tvec = eccodens.Tmean.sel(rho=rr)
mask = np.isnan(Tvec)
if len(Tvec[~mask]) > 0:
slope, intercept, r_value, p_value, std_err = sp.stats.linregress(
eccodens.dist[~mask] * 1000, Tvec[~mask]
)
dTiso[idx] = slope
dTdz.values = -np.gradient(eccodens.Tmean.mean(dim="cast"), eccodens.P.mean(dim="cast"))
f, ax = plt.subplots(1, 2)
np.abs(dTiso).plot.line(ax=ax[0], y="rho")
np.abs(eccodens.dTiso).mean(dim="cast").plot.line(ax=ax[0], y="rho", yincrease=False)
ax[0].set_xlim([0, 5e-6])
f.legend(
[
"recalculated from density-averaged field",
"along-transect mean of local gradient",
]
)
dTdz.plot(ax=ax[1], y="rho", yincrease=False)
eccodens.dTdz.mean(dim="cast").plot.line(ax=ax[1], y="rho", yincrease=False)
[<matplotlib.lines.Line2D at 0x7f1727a84630>]
nn = 6
Tvec = eccodens.Tmean.isel(rho=nn)
mask = np.isnan(Tvec)
plt.plot(eccodens.dist[~mask] * 1000, Tvec[~mask], ".")
plt.plot(
eccodens.dist * 1000,
Tvec.mean() + dTiso.isel(rho=nn) * (eccodens.dist - eccodens.dist.mean()) * 1000,
)
[<matplotlib.lines.Line2D at 0x7f1725c2a6d8>]
argograd.dTiso.mean("time").plot(x="cast", robust=True, yincrease=False)
<matplotlib.collections.QuadMesh at 0x7fd75806b350>
eccograd.dTiso.plot(x="cast", yincrease=False, robust=True)
<matplotlib.collections.QuadMesh at 0x7fd75a8a8510>
clim = eccograd.copy()
clim = clim.to_dataframe().reset_index()
trmean, ρbins = ed.average_transect_1d(p06, nbins=15)
climrho = clim.groupby(pd.cut(clim.ρmean, ρbins, precision=1))
cole.diffusivity.plot(norm=mpl.colors.LogNorm(), x="cast", yincrease=False)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-55-05ef08ea103d> in <module>
----> 1 cole.diffusivity.plot(norm=mpl.colors.LogNorm(), x='cast', yincrease=False)
NameError: name 'mpl' is not defined
cole.diffusivity.mean(dim="cast").plot()
[<matplotlib.lines.Line2D at 0x7f1730d097b8>]
clim = eccograd.sel(time=9)
transect = p06.sel(P=slice(0, 2000))
trmean, ρbins = ed.average_transect_1d(transect, nbins=20)
gradmean = ed.average_clim(clim, transect, ρbins)
Ke = ed.estimate_Ke(trmean, gradmean)
Ke
| chi | KtTz | dTdz | dTmdz | dTiso | KT | Ke | |
|---|---|---|---|---|---|---|---|
| rho | |||||||
| (1024.8000000000002, 1026.7] | 1.340903e-07 | 1.843108e-06 | 0.021105 | 0.021170 | 4.694987e-06 | 0.000118 | 1271.439129 |
| (1026.7, 1027.5] | 8.350073e-08 | 1.431120e-06 | 0.026548 | 0.023706 | 3.095114e-06 | 0.000058 | 816.732447 |
| (1027.5, 1028.2] | 6.809042e-08 | 1.229691e-06 | 0.024866 | 0.026552 | 2.792055e-06 | 0.000053 | 178.802085 |
| (1028.2, 1028.9] | 3.888472e-08 | 9.499299e-07 | 0.018603 | 0.019622 | 1.978210e-06 | 0.000053 | 205.196687 |
| (1028.9, 1029.4] | 1.696346e-08 | 6.028373e-07 | 0.011949 | 0.011681 | 1.093078e-06 | 0.000053 | 1205.030222 |
| (1029.4, 1029.9] | 1.025537e-08 | 4.112075e-07 | 0.008578 | 0.009867 | 4.934073e-07 | 0.000047 | 4396.180518 |
| (1029.9, 1030.4] | 6.098227e-09 | 3.541930e-07 | 0.006906 | 0.006893 | 3.572366e-07 | 0.000053 | 4761.760099 |
| (1030.4, 1030.9] | 5.922741e-09 | 3.396340e-07 | 0.006503 | 0.005814 | 3.952476e-07 | 0.000051 | 6315.357062 |
| (1030.9, 1031.4] | 4.479737e-09 | 3.283833e-07 | 0.006106 | 0.005641 | 3.961862e-07 | 0.000056 | 2468.021433 |
| (1031.4, 1031.9] | 4.335862e-09 | 3.358884e-07 | 0.005741 | 0.005445 | 3.654930e-07 | 0.000059 | 2536.931307 |
| (1031.9, 1032.4] | 3.778694e-09 | 3.191589e-07 | 0.005229 | 0.006691 | 3.008868e-07 | 0.000064 | -2719.446279 |
| (1032.4, 1032.9] | 2.663402e-09 | 2.663522e-07 | 0.004435 | 0.005343 | 2.868961e-07 | 0.000064 | -1111.907562 |
| (1032.9, 1033.4] | 2.050237e-09 | 2.458359e-07 | 0.003670 | 0.002568 | 1.781828e-07 | 0.000071 | 12403.643288 |
| (1033.4, 1033.9] | 1.563165e-09 | 2.117540e-07 | 0.003097 | 0.003163 | 1.434013e-07 | 0.000068 | 5439.135721 |
| (1033.9, 1034.4] | 1.084065e-09 | 1.862677e-07 | 0.002532 | 0.002644 | 1.283914e-07 | 0.000076 | 3006.651780 |
| (1034.4, 1034.9] | 8.051773e-10 | 1.646219e-07 | 0.002085 | 0.002116 | 1.193445e-07 | 0.000082 | 3804.070508 |
| (1034.9, 1035.4] | 5.643653e-10 | 1.386612e-07 | 0.001779 | 0.001680 | 1.091446e-07 | 0.000080 | 4130.684457 |
| (1035.4, 1035.9] | 3.849335e-10 | 1.173186e-07 | 0.001456 | NaN | 1.000824e-07 | 0.000083 | NaN |
| (1035.9, 1036.4] | 2.681242e-10 | 1.045344e-07 | 0.001217 | NaN | NaN | 0.000090 | NaN |
| (1036.4, 1036.9] | 2.172361e-10 | 9.460649e-08 | 0.001071 | NaN | 8.956461e-08 | 0.000094 | NaN |
def compare_transect_clim(transect, clim):
f, ax = plt.subplots(3, 1, sharex=True, sharey=True)
for aa, (trvar, climvar) in enumerate(
zip(["T", "S", "rho"], ["Tmean", "Smean", "ρmean"])
):
_, levels = pd.qcut(transect[trvar].values.ravel(), 20, retbins=True)
(
clim[climvar]
.sel(**ed.get_region_from_transect(p06))
.isel(lat=1)
.plot.contour(
ax=ax[aa],
levels=levels,
x="lon",
add_colorbar=True,
yincrease=False,
cmap=mpl.cm.RdYlBu,
)
)
(
transect[trvar].plot.contour(
ax=ax[aa], levels=levels, colors="k", x="lon", y="P", yincrease=False
)
)
trname = (
transect.attrs["transect_name"]
if "transect_name" in transect.attrs
else "transect"
)
f.suptitle("Compare " + trname + " vs " + clim.dataset, y=0.9)
plt.gcf().set_size_inches((10, 12))
compare_transect_clim(p06, eccograd.sel(time=8))
plt.gca().set_ylim((2400, 0))
# compare_transect_clim(p06, argograd)
# plt.gca().set_ylim((2400, 0))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-19-6a0f5cf774f5> in <module>()
21
22
---> 23 compare_transect_clim(p06, eccograd.sel(time=8))
24 plt.gca().set_ylim((2400, 0))
25 # compare_transect_clim(p06, argograd)
~/work/python/xarray/xarray/core/dataset.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
1507 indexers = either_dict_or_kwargs(indexers, indexers_kwargs, 'sel')
1508 pos_indexers, new_indexes = remap_label_indexers(
-> 1509 self, indexers=indexers, method=method, tolerance=tolerance)
1510 result = self.isel(indexers=pos_indexers, drop=drop)
1511 return result._replace_indexes(new_indexes)
~/work/python/xarray/xarray/core/coordinates.py in remap_label_indexers(obj, indexers, method, tolerance, **indexers_kwargs)
353
354 pos_indexers, new_indexes = indexing.remap_label_indexers(
--> 355 obj, v_indexers, method=method, tolerance=tolerance
356 )
357 # attach indexer's coordinate to pos_indexers
~/work/python/xarray/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance)
235 new_indexes = {}
236
--> 237 dim_indexers = get_dim_indexers(data_obj, indexers)
238 for dim, label in iteritems(dim_indexers):
239 try:
~/work/python/xarray/xarray/core/indexing.py in get_dim_indexers(data_obj, indexers)
203 if invalid:
204 raise ValueError("dimensions or multi-index levels %r do not exist"
--> 205 % invalid)
206
207 level_indexers = defaultdict(dict)
ValueError: dimensions or multi-index levels ['time'] do not exist
Calculate 3#
%aimport eddydiff
import eddydiff as ed
ed.eddydiff.format_ecco2(kecco)
<xarray.Dataset>
Dimensions: (lat: 360, lon: 720, pres: 50)
Coordinates:
* lat (lat) float64 -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
* lon (lon) float64 -179.8 -179.2 -178.8 -178.2 ... 178.8 179.2 179.8
* pres (pres) float64 1.0 2.0 3.0 4.0 5.0 ... 46.0 47.0 48.0 49.0 50.0
Data variables:
Kgm_ECCOv4 (lat, lon, pres) float32 nan nan nan nan nan ... nan nan nan nan
Attributes:
title: Bolus Velocity Coefficient (ECCO v4 Estimate; Forget et a...
Format: native grid (nctiles w. 52 tiles)
source: ECCO consortium (http://ecco-group.org/)
institution: MIT
history: files revision history :\n 2016/05/07 : release of re...
references: Forget, G., J.-M. Campin, P. Heimbach, C. N. Hill, R. M. ...
_FillValue: nan
missing_value: nan
Conventions: CF-1.6
date: 10-May-2016- lat: 360
- lon: 720
- pres: 50
- lat(lat)float64-89.75 -89.25 ... 89.25 89.75
array([-89.75, -89.25, -88.75, ..., 88.75, 89.25, 89.75])
- lon(lon)float64-179.8 -179.2 ... 179.2 179.8
array([-179.75, -179.25, -178.75, ..., 178.75, 179.25, 179.75])
- pres(pres)float641.0 2.0 3.0 4.0 ... 48.0 49.0 50.0
- long_name :
- array index 3
- units :
- 1
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50.])
- Kgm_ECCOv4(lat, lon, pres)float32nan nan nan nan ... nan nan nan nan
- long_name :
- Bolus Velocity Coefficient (ECCO v4 Estimate; Forget et al 2015a,b,2016)
- units :
- m^2/s
array([[[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], [[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], [[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], ..., [[659.4894 , 500.91663, 320.21997, ..., nan, nan, nan], [660.7585 , 502.7165 , 322.60538, ..., nan, nan, nan], [662.02216, 504.51074, 324.98486, ..., nan, nan, nan], ..., [655.61163, 495.4347 , 312.96793, ..., nan, nan, nan], [656.9137 , 497.27267, 315.39694, ..., nan, nan, nan], [658.20605, 499.1001 , 317.81445, ..., nan, nan, nan]], [[603.9421 , 434.1819 , 238.91277, ..., nan, nan, nan], [604.6996 , 435.15845, 240.00772, ..., nan, nan, nan], [605.4477 , 436.12415, 241.09155, ..., nan, nan, nan], ..., [601.6406 , 431.22247, 235.60126, ..., nan, nan, nan], [602.41565, 432.2176 , 236.71368, ..., nan, nan, nan], [603.1812 , 433.20172, 237.8149 , ..., nan, nan, nan]], [[554.81036, 379.41898, 189.04736, ..., nan, nan, nan], [555.0568 , 379.70895, 189.2995 , ..., nan, nan, nan], [555.29944, 379.99478, 189.54868, ..., nan, nan, nan], ..., [554.06714, 378.54477, 188.28748, ..., nan, nan, nan], [554.31366, 378.83453, 188.53893, ..., nan, nan, nan], [554.5586 , 379.1227 , 188.78952, ..., nan, nan, nan]]], dtype=float32)
- title :
- Bolus Velocity Coefficient (ECCO v4 Estimate; Forget et al 2015a,b,2016) -- ECCO v4 ocean state estimate, release 2 -- 1992-2011
- Format :
- native grid (nctiles w. 52 tiles)
- source :
- ECCO consortium (http://ecco-group.org/)
- institution :
- MIT
- history :
- files revision history : 2016/05/07 : release of remote sensed variables (GF) 2015/12/12 : second release of ECCO v4 (GF) 2014/02/04 : initial release of ECCO v4 (GF) estimate revision history : r4it12 : include geothermal heating, targeted bottom viscosity, and 2000-2011 wind stress adjustments that were omitted in r4it11; adjust global mean precipitation to closely match aviso global mean time series; put adjusted forcing fields on llc90 grid. r4it11 : reduce background vertical viscosity r4it10 : cleanup control vector adjustments r4it9 : optim. global mean sea level alone r4it0-8 : full adjoint iterations, omitting global mean sea level altimetry constraint.
- references :
- Forget, G., J.-M. Campin, P. Heimbach, C. N. Hill, R. M. Ponte, and C. Wunsch, 2015: ECCO version 4: an integrated framework for non-linear inverse modeling and global ocean state estimation. Geoscientific Model Development, 8, 3071-3104, doi:10.5194/gmd-8-3071-2015 Forget, G., D. Ferreira, and X. Liang, 2015: On the observability of turbulent transport rates by argo: supporting evidence from an inversion experiment. Ocean Science, 11, 839853, doi:10.5194/os-11-839-2015 Forget, G., J.-M. Campin, P. Heimbach, C. N. Hill, R. M. Ponte, and C. Wunsch, 2016: ECCO version 4: Second Release, http://hdl.handle.net/1721.1/102062
- _FillValue :
- nan
- missing_value :
- nan
- Conventions :
- CF-1.6
- date :
- 10-May-2016
kecco = (
xr.open_dataset("../datasets/ecco/interp_Kgm_ECCOv4.nc")
.pipe(ed.eddydiff.format_ecco2)
.Kgm_ECCOv4
)
kecco
<xarray.DataArray 'Kgm_ECCOv4' (lat: 360, lon: 720, pres: 50)>
array([[[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
...,
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan]],
[[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
...,
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan]],
[[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
...,
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan],
[ nan, nan, nan, ..., nan, nan,
nan]],
...,
[[449.7568 , 269.2915 , 146.21722, ..., nan, nan,
nan],
[449.26746, 269.019 , 146.27124, ..., nan, nan,
nan],
[448.78452, 268.7531 , 146.32971, ..., nan, nan,
nan],
...,
[451.28967, 270.1708 , 146.09207, ..., nan, nan,
nan],
[450.76907, 269.86832, 146.12814, ..., nan, nan,
nan],
[450.25885, 269.57617, 146.1708 , ..., nan, nan,
nan]],
[[488.71448, 306.11115, 164.50214, ..., nan, nan,
nan],
[488.2017 , 305.6677 , 164.3479 , ..., nan, nan,
nan],
[487.69604, 305.23145, 164.19669, ..., nan, nan,
nan],
...,
[490.2769 , 307.46857, 164.97755, ..., nan, nan,
nan],
[489.7501 , 307.00974, 164.81644, ..., nan, nan,
nan],
[489.23047, 306.55817, 164.65837, ..., nan, nan,
nan]],
[[521.16046, 340.92065, 172.53606, ..., nan, nan,
nan],
[520.9415 , 340.68723, 172.3936 , ..., nan, nan,
nan],
[520.72534, 340.4571 , 172.25227, ..., nan, nan,
nan],
...,
[521.8189 , 341.62262, 172.96187, ..., nan, nan,
nan],
[521.60065, 341.38974, 172.82086, ..., nan, nan,
nan],
[521.38165, 341.15634, 172.6784 , ..., nan, nan,
nan]]], dtype=float32)
Coordinates:
* lat (lat) float64 -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
* lon (lon) float64 0.25 0.75 1.25 1.75 2.25 ... 358.2 358.8 359.2 359.8
* pres (pres) float64 5.0 15.0 25.0 35.0 ... 5.039e+03 5.461e+03 5.906e+03
Attributes:
long_name: Bolus Velocity Coefficient (ECCO v4 Estimate; Forget et al 20...
units: m^2/s- lat: 360
- lon: 720
- pres: 50
- nan nan nan nan nan nan nan ... 967.74115 972.6106 nan nan nan nan
array([[[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], [[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], [[ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], ..., [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan], [ nan, nan, nan, ..., nan, nan, nan]], ..., [[449.7568 , 269.2915 , 146.21722, ..., nan, nan, nan], [449.26746, 269.019 , 146.27124, ..., nan, nan, nan], [448.78452, 268.7531 , 146.32971, ..., nan, nan, nan], ..., [451.28967, 270.1708 , 146.09207, ..., nan, nan, nan], [450.76907, 269.86832, 146.12814, ..., nan, nan, nan], [450.25885, 269.57617, 146.1708 , ..., nan, nan, nan]], [[488.71448, 306.11115, 164.50214, ..., nan, nan, nan], [488.2017 , 305.6677 , 164.3479 , ..., nan, nan, nan], [487.69604, 305.23145, 164.19669, ..., nan, nan, nan], ..., [490.2769 , 307.46857, 164.97755, ..., nan, nan, nan], [489.7501 , 307.00974, 164.81644, ..., nan, nan, nan], [489.23047, 306.55817, 164.65837, ..., nan, nan, nan]], [[521.16046, 340.92065, 172.53606, ..., nan, nan, nan], [520.9415 , 340.68723, 172.3936 , ..., nan, nan, nan], [520.72534, 340.4571 , 172.25227, ..., nan, nan, nan], ..., [521.8189 , 341.62262, 172.96187, ..., nan, nan, nan], [521.60065, 341.38974, 172.82086, ..., nan, nan, nan], [521.38165, 341.15634, 172.6784 , ..., nan, nan, nan]]], dtype=float32) - lat(lat)float64-89.75 -89.25 ... 89.25 89.75
array([-89.75, -89.25, -88.75, ..., 88.75, 89.25, 89.75])
- lon(lon)float640.25 0.75 1.25 ... 359.2 359.8
array([2.5000e-01, 7.5000e-01, 1.2500e+00, ..., 3.5875e+02, 3.5925e+02, 3.5975e+02]) - pres(pres)float645.0 15.0 ... 5.461e+03 5.906e+03
array([5.000000e+00, 1.500000e+01, 2.500000e+01, 3.500000e+01, 4.500000e+01, 5.500000e+01, 6.500000e+01, 7.500500e+01, 8.502500e+01, 9.509500e+01, 1.053100e+02, 1.158700e+02, 1.271500e+02, 1.397400e+02, 1.544700e+02, 1.724000e+02, 1.947350e+02, 2.227100e+02, 2.574700e+02, 2.999300e+02, 3.506800e+02, 4.099300e+02, 4.774700e+02, 5.527100e+02, 6.347350e+02, 7.224000e+02, 8.144700e+02, 9.097400e+02, 1.007155e+03, 1.105905e+03, 1.205535e+03, 1.306205e+03, 1.409150e+03, 1.517095e+03, 1.634175e+03, 1.765135e+03, 1.914150e+03, 2.084035e+03, 2.276225e+03, 2.491250e+03, 2.729250e+03, 2.990250e+03, 3.274250e+03, 3.581250e+03, 3.911250e+03, 4.264250e+03, 4.640250e+03, 5.039250e+03, 5.461250e+03, 5.906250e+03])
- long_name :
- Bolus Velocity Coefficient (ECCO v4 Estimate; Forget et al 2015a,b,2016)
- units :
- m^2/s
kecco.interp(lon=p06.lon, lat=p06.lat, pres=p06.P.values).mean("cast").plot()
[<matplotlib.lines.Line2D at 0x7fd6c9b508d0>]
kecco.interp
<matplotlib.collections.QuadMesh at 0x7fd6d66d1dd0>
newKe = xr.Dataset()
newKe["KT"] = trdens.KT # .mean(dim="cast")
newKe["chi"] = trdens.chi # .mean(dim="cast")
newKe["KtTz"] = trdens.KtTz # .mean(dim="cast")
newKe["dTiso"] = np.abs(eccodens.dTiso)
newKe["dTmdz"] = np.abs(eccodens.dTdia)
newKe["dTdz"] = trdens.dTdz # .mean(dim="cast")
newKe.coords["pres"] = trdens.pres.mean("cast")
# newKe = newKe.sel(cast=slice(242)).coarsen(cast=60).mean()
# newKe = newKe.mean("cast")
newKe["Ke"] = (newKe["chi"] / 2 - np.abs(newKe["KtTz"] * newKe["dTmdz"])) / (
newKe["dTiso"] ** 2
)
# ed.plot_bar_Ke(newKe.to_dataframe())
fullmean = newKe
cole.diffusivity.sel(cast=slice(242)).coarsen(cast=40).mean().plot.line(hue="cast")
/home/deepak/work/python/xarray/xarray/core/nanops.py:142: RuntimeWarning: Mean of empty slice
return np.nanmean(a, axis=axis, dtype=dtype)
[<matplotlib.lines.Line2D at 0x7fd6d6915290>,
<matplotlib.lines.Line2D at 0x7fd6d6915490>,
<matplotlib.lines.Line2D at 0x7fd6d6915650>,
<matplotlib.lines.Line2D at 0x7fd6d6915810>,
<matplotlib.lines.Line2D at 0x7fd6d69159d0>,
<matplotlib.lines.Line2D at 0x7fd6d6915b90>]
fullmean.Ke.plot.line(hue="cast", y="pres", yincrease=False, color="k")
newKe.Ke.where(newKe.Ke > 0).plot(hue="cast", y="pres")
eccograd, argograd, cole, aber = ed.read_all_datasets(kind="monthly")
f, ax = plt.subplots(2, 2, sharex=True, sharey=True, constrained_layout=True)
def plot(ds, ax, norm):
hdl = (
ds.sel(lat=slice(-10, 10), lon=slice(200, 280))
.mean("time")
.plot(ax=ax, norm=norm, add_colorbar=False)
)
dcpy.plots.liney(0, ax=ax, zorder=10, color="w", lw=2)
ax.plot([360 - 140, 360 - 110, 360 - 125], [0, 0, 0], marker="x", color="w", ms=16)
return hdl
plot(
eccograd.dTiso.sel(pres=100, method="nearest"),
ax=ax[0, 0],
norm=mpl.colors.LogNorm(5e-7, 5e-6),
)
h1 = plot(
argograd.dTiso.sel(pres=100, method="nearest"),
ax=ax[0, 1],
norm=mpl.colors.LogNorm(5e-7, 5e-6),
)
plot(
eccograd.dTiso.sel(pres=1000, method="nearest"),
ax=ax[1, 0],
norm=mpl.colors.LogNorm(5e-8, 5e-7),
)
h2 = plot(
argograd.dTiso.sel(pres=1000, method="nearest"),
ax=ax[1, 1],
norm=mpl.colors.LogNorm(5e-8, 5e-7),
)
f.colorbar(h1, ax=ax[0, :])
f.colorbar(h2, ax=ax[1, :])
dcpy.plots.label_subplots(ax.flat, color="w")
f.savefig("../images/ecco-argo-grad-epac.png")
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
mask |= resdat <= 0
argograd.dTiso.sel(lat=slice(-10, 10), lon=slice(200, 280)).sel(
pres=100, method="nearest"
).mean("time").plot(robust=True)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
x = np.divide(x1, x2, out)
<matplotlib.collections.QuadMesh at 0x7f16aa8b2b10>