TAO (0, 140) χpod#

TODO#

  1. 1023.5 surface does not exist south of 2N? Something is weird. More generally how do I deal with ECCO bias? Or I need to choose bins based on outcrops I guess

  2. Argo spline fits are a little steep

  3. Estimate gradients at latitude=0, exactly

  4. Understand regrid_conservative: Am I providign bin edges or bin centers.

  5. Then do the right thing to get derivative.

Think about EUC max

%load_ext watermark

import cf_xarray
import dcpy
import distributed
import hvplot.xarray
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pump
import xgcm

import eddydiff as ed
import xarray as xr

xr.set_options(keep_attrs=True)

%watermark -iv
plt.rcParams["figure.dpi"] = 180
plt.rcParams["savefig.dpi"] = 200

client = distributed.Client()
client
xgcm       : 0.5.1
pump       : 0.1
hvplot     : 0.7.1
distributed: 2021.3.0
dcpy       : 0.1
pandas     : 1.2.3
cf_xarray  : 0.4.1.dev21+gab9dc66
xarray     : 0.17.1.dev3+g48378c4b1
matplotlib : 3.3.4
eddydiff   : 0.1
numpy      : 1.20.1

Client

Cluster

  • Workers: 4
  • Cores: 8
  • Memory: 33.39 GB


Read χpod , TAO data#

chi = (
    xr.open_dataset(
        "/home/deepak/datasets/chipod/tao/chipods_0_140W.nc",
        decode_cf=False,
        chunks={"time": 10000},
    )
    .set_coords(["mooring", "chipod", "crs"])
    .swap_dims({"timeSeries": "depth"})
    .rename({"Kt": "KT", "Nsqr": "N2"})
    .drop(["timeSeries", "crs"])
)
for var in chi.variables:
    if "FillValue" in chi[var].attrs:
        chi[var].attrs["_FillValue"] = int(chi[var].attrs["FillValue"])
chi = xr.decode_cf(chi)
chi["T"] -= 273
chi.T.attrs["units"] = "C"
chi["KtTz"] = chi.KT * chi.dTdz
chi["lat"] = chi.lat[0].load()
chi["lon"] = chi.lon[0].load()

chisub = chi.sel(time=slice("2008-05-01", "2009-05-01"))


tao = xr.open_mfdataset(
    "/home/deepak/datasets/TaoTritonPirataRama/TAO_TRITON/[ts]_xyzt_dy.cdf",
    chunks={"depth": 10, "time": 8000},
)


for var in ["T_20", "S_41"]:
    tao[var].attrs["missing_value"] = tao.attrs["missing_value"]
    tao[var].attrs["_FillValue"] = tao.attrs["_FillValue"]
tao = xr.decode_cf(tao).rename({"T_20": "T", "S_41": "S"})
tao = tao.cf.guess_coord_axis()
tao = tao.assign_coords(lon=tao.lon - 360)
tao = tao[["S", "T"]]


def calc_mld(pden):

    drho = pden - pden.cf.isel(Z=0)
    return xr.where(drho > 0.015, np.abs(drho.cf["Z"]), np.nan).cf.min("Z")


def subset_mooring_to_chipod(tao, chipod):
    taos = (
        tao.sel(
            lat=chipod.lat.load().item(),
            lon=chipod.lon.load().item(),
            method="nearest",
        )
        .sel(
            time=slice(chipod.time[0], chipod.time[-1]),
            depth=slice(chipod.depth.max().item() + 20),
        )
        .load()
        .dropna("depth", how="all")
        .dropna("time", how="all")
        # .interpolate_na("depth")
        .interpolate_na("time", max_gap="2D")
    )

    return taos


taos = subset_mooring_to_chipod(tao, chisub)
taos["rho"] = dcpy.eos.pden(taos.S.interpolate_na("depth"), taos.T, 0, pr=0)
taos["rhoT"] = dcpy.eos.pden(35, taos.T, 0, pr=0)
taos["rho"].attrs.update({"long_name": "$ρ$", "units": "kg/m³"})
taos["rhoT"].attrs.update({"long_name": "$ρ^T$", "units": "kg/m³"})
taos["mld"] = calc_mld(taos.rhoT)

fastT = xr.open_mfdataset(
    "/home/deepak/datasets/TaoTritonPirataRama/high_resolution/10m/t0n140w_10m.cdf",
    chunks={"depth": 10, "time": 8000},
).T_20
fastT = subset_mooring_to_chipod(fastT, chisub)

# TODO: get salinity?
chisub = chisub.rename({"T": "T_original"})
chisub["T"] = fastT.interp(depth=chisub.depth)
chisub["pden"] = dcpy.eos.pden(35, chisub.T, 0, pr=0)

# mask out ML
chisub = chisub.where(chisub.depth > taos.mld.interp(time=chisub.time))

taos
<xarray.Dataset>
Dimensions:             (depth: 16, time: 357)
Coordinates:
    lon                 float32 -140.0
    lat                 float32 0.0
  * depth               (depth) float64 1.0 5.0 10.0 13.0 ... 100.0 120.0 123.0
  * time                (time) datetime64[ns] 2008-05-10T12:00:00 ... 2009-05...
    reference_pressure  int64 0
Data variables:
    S                   (depth, time) float32 nan 35.24 35.26 ... nan nan nan
    T                   (depth, time) float32 25.88 25.94 26.06 ... 19.34 18.53
    rho                 (depth, time) float32 nan 1.023e+03 ... nan nan
    rhoT                (depth, time) float32 1.023e+03 1.023e+03 ... 1.025e+03
    mld                 (time) float64 5.0 5.0 5.0 5.0 5.0 ... 5.0 5.0 5.0 5.0
Attributes:
    array:                        TAO/TRITON
    Data_Source:                  GTMBA Project Office/NOAA/PMEL
    Data_info:                    Contact Paul Freitag: 206-526-6727
    File_info:                    Contact Dai McClurg: Dai.C.McClurg@noaa.gov
    Request_for_acknowledgement:  If you use these data in publications or pr...
    missing_value:                1e+35
    _FillValue:                   1e+35

Check for chi T biases

kwargs = dict(vmin=20, vmax=27, cmap=mpl.cm.magma_r)
taos.T.plot(robust=True, yincrease=False, **kwargs)
(
    chisub.resample(time="D")
    .mean()
    .plot.scatter(
        **kwargs, y="depth", x="time", hue="T_original", edgecolor="w", linewidth=0.05
    )
)

plt.figure()
taos.T.plot(robust=True, yincrease=False, **kwargs)
(
    chisub.resample(time="D")
    .mean()
    .plot.scatter(**kwargs, y="depth", x="time", hue="T", edgecolor="w", linewidth=0.05)
)
<matplotlib.collections.PathCollection at 0x7f10fb34ff10>
_images/bd440f0a128b1a833608a14d87a85225131e470da7f03c704a528ef7a2d6989a.png _images/bee5daaf00f666a911e63f3cd4164976f1207234ef74ad1d8f3322a4cbbd5268.png
chisub.pden.plot(x="time", yincrease=False, robust=True)
<matplotlib.collections.QuadMesh at 0x7f10fab202b0>
_images/6c3c035d2569f0531567fd33346c7635f872126f5ea231016546c95190861291.png

Read in gradients#

argo#

argograd = xr.open_zarr(
    "../datasets/argo_monthly_iso_gradients.zarr", decode_times=False
)
argograd = argograd.cf.guess_coord_axis()
argograd.pres.attrs["positive"] = "down"
argograd = argograd.cf.add_bounds("pres")
argo = (
    argograd.sel(lon=360 + chisub.lon.item(), method="nearest")
    .sel(lat=slice(-3, 8), pres=slice(500))
    .mean("time")
)
argo["pden"] = ed.jmd95.dens(
    argo.Smean, argo.Tmean, 0  # ecco.pres.broadcast_like(ecco.Smean)
)
argo
<xarray.Dataset>
Dimensions:      (bounds: 2, lat: 11, pres: 34)
Coordinates:
  * lat          (lat) float32 -2.5 -1.5 -0.5 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5
    lon          float32 220.5
  * pres         (pres) float64 2.5 10.0 20.0 30.0 ... 420.0 440.0 462.5 500.0
    pres_bounds  (bounds, pres) float32 -1.25 6.25 15.0 ... 450.0 473.8 518.8
Dimensions without coordinates: bounds
Data variables:
    Smean        (pres, lat) float32 dask.array<chunksize=(34, 11), meta=np.ndarray>
    Tmean        (pres, lat) float32 dask.array<chunksize=(34, 11), meta=np.ndarray>
    dSdia        (pres, lat) float64 dask.array<chunksize=(34, 11), meta=np.ndarray>
    dSdz         (pres, lat) float32 dask.array<chunksize=(34, 11), meta=np.ndarray>
    dSiso        (pres, lat) float64 dask.array<chunksize=(34, 11), meta=np.ndarray>
    dTdia        (pres, lat) float64 dask.array<chunksize=(34, 11), meta=np.ndarray>
    dTdz         (pres, lat) float32 dask.array<chunksize=(34, 11), meta=np.ndarray>
    dTiso        (pres, lat) float64 dask.array<chunksize=(34, 11), meta=np.ndarray>
    ρmean        (pres, lat) float32 dask.array<chunksize=(34, 11), meta=np.ndarray>
    pden         (pres, lat) float32 dask.array<chunksize=(34, 11), meta=np.ndarray>
Attributes:
    dataset:  argo
    name:     Mean fields and isopycnal, diapycnal gradients from Argo
(
    argo[["ρmean", "pden"]]
    # .sel(lon=220, method="nearest")
    .to_array().cf.plot(col="variable", y="vertical", robust=True)
)
<xarray.plot.facetgrid.FacetGrid at 0x7f10fa916c40>
_images/32314fea67e7483c6d275c41c731415e019e83e1e641964eae476049b227247a.png

ECCO#

ecco = (
    ed.eddydiff.read_ecco_clim()
    .sel(lon=360 + chisub.lon.item(), method="nearest")
    .sel(lat=slice(-3, 8), pres=slice(500))
    .mean("time")
)


Evaluate bin choices#

  1. How well do ECCO & Argo agree?

  2. Do the chosen ρ levels cross the mooring location? Otherwise I can’t get an estimate of lateral gradient? I need the edges to cross too, so that I can get a vertical gradient

  3. How do the bins look in T-S space? Am I seeing enough stirring to do the analysis

bins = [
    1022.5,
    1023,
    1023.5,
    1024,
    1024.5,
    1025,
    1025.5,
    1026,
    1026.5,
]
bins = np.array([1023.2, 1023.5, 1024, 1025, 1026])
centers = (bins[1:] + bins[:-1]) / 2

(
    chisub.pden.resample(time="3D")
    .mean()
    .plot(
        x="time",
        levels=bins,
        yincrease=False,
        cmap=mpl.cm.magma_r,
        edgecolor="w",
        linewidths=0.15,
    )
)

ed.plot.check_bins_with_climatology(bins, argo, ecco)

dcpy.oceans.TSplot(
    taos.S,
    taos.T,
    rho_levels=bins,
    hexbin=False,
)

# chi to density space
plt.figure()
chisub.plot.scatter(x="time", y="pden", hue="Jq", robust=True, cmap=mpl.cm.Blues_r, s=1)
plt.gca().yaxis.set_inverted(True)
if "bins" in locals():
    dcpy.plots.liney(bins, zorder=10)
/home/deepak/work/python/dcpy/dcpy/plots.py:1006: MatplotlibDeprecationWarning: 
The ax attribute was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  ax = cs.ax
_images/5b30c0958e204e3e1bd3e63d69d270eb17b6fc94d57ecf460fce34e222876c63.png _images/fc56512c4044673796e7ea733e57d1be29f6f22f1aea2a22abe1a9573119ceab.png
/home/deepak/miniconda3/envs/dcpy/lib/python3.8/site-packages/IPython/core/pylabtools.py:132: UserWarning: constrained_layout not applied.  At least one axes collapsed to zero width or height.
  fig.canvas.print_figure(bytes_io, **kw)
_images/9be20903e33902db3034af484d14cb3c796ba3102be29e1cefcedc9b937b4b8c.png _images/79b337f00ba4fb47b1d3154437970daf0c23a21d546b465bd1f502180f680676.png


Compare dTdz between mean field and mooring#

f, ax = plt.subplots(1, 2, sharex=True, sharey=True)
(
    (-1 * argograd.Tmean.interp(lat=chisub.lat.values, lon=360 + chisub.lon.values))
    .differentiate("pres")
    .cf.plot(y="Z", ylim=(500, 0), hue="time", ax=ax[0])
)


(
    (
        -1
        * eccograd.drop("dayofyear").Tmean.interp(
            lat=chisub.lat.values, lon=360 + chisub.lon.values
        )
    )
    .differentiate("pres")
    .cf.plot(y="Z", ylim=(500, 0), hue="time", ax=ax[1])
)

[dcpy.plots.liney(chisub.depth, ax=aa) for aa in ax]

# eccoT["dTdz"].sel(lat=0, method="nearest").plot(y="z")
[None, None]
_images/cb2a7cf1099689472faffe1bcbc4f86752b5429766d80f0b0a20fae3b80be92e.png


Do estimate#

eccoT, edge = ed.eddydiff.estimate_gradients(ecco, bins, debug=True)
argoT, edge = ed.eddydiff.estimate_gradients(argo, bins, debug=True)
_images/c51814614a661bf7f0e1f944c3edea15a32a95e5570796674feb04f2c279f91f.png _images/b4f8281f015e23967c81110771fe1395f22f5fb014a467fbce4ca30036efc3fc.png
# .sel(depth=slice(39, None))  # TODO: wintertime MLD?
chidens = ed.eddydiff.bin_avg_in_density_time(
    chisub.reset_coords(drop=True).where(chisub.KT < 1e-3).coarsen(time=24).mean(),
    bins={"pden": bins},
)
chidens
<xarray.Dataset>
Dimensions:             (binvar: 4, time: 13)
Coordinates:
  * binvar              (binvar) float64 1.023e+03 1.024e+03 1.024e+03 1.026e+03
  * time                (time) datetime64[ns] 2008-05-01 ... 2009-05-01
Data variables: (12/16)
    depth               (binvar, time) float64 57.4 69.0 69.0 ... 119.0 nan
    T_original          (binvar, time) float64 23.86 24.56 25.29 ... 17.92 nan
    dTdz                (binvar, time) float64 0.04416 0.06119 ... 0.1247 nan
    N2                  (binvar, time) float64 0.0001219 0.0001575 ... nan
    KT                  (binvar, time) float64 9.291e-05 4.81e-05 ... nan
    chi                 (binvar, time) float64 1.76e-07 2.496e-07 ... nan
    ...                  ...
    lat                 (binvar, time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 nan
    lon                 (binvar, time) float64 -140.0 -140.0 ... -140.0 nan
    mooring             (binvar, time) float64 9.969e+36 9.969e+36 ... nan
    chipod              (binvar, time) float64 9.969e+36 9.969e+36 ... nan
    reference_pressure  (binvar, time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 nan
    numobs              (binvar, time) float64 25.0 33.0 23.0 ... 31.0 13.0 nan
%matplotlib inline

chidens.Jq.plot.line(hue="pden")
[<matplotlib.lines.Line2D at 0x7f10faba7460>,
 <matplotlib.lines.Line2D at 0x7f10e0373d90>,
 <matplotlib.lines.Line2D at 0x7f10b09c0280>,
 <matplotlib.lines.Line2D at 0x7f10b09c01c0>]
_images/93a7b60e3daf170eaa56911c23c350ac771bfa90f5e5bf7f317336c27a282cc1.png
%matplotlib inline

isoT = eccoT.interp(lat=0)

Ke = (chidens["chi"] / 2 - (chidens["KtTz"] * isoT["dTdz"])) / (isoT["dTdy"] ** 2)
Ke.plot.line(hue="pden")
dcpy.plots.liney(0)
_images/0d636bd843782f50ae50970dec475c5bb860793e8c5d5fb38cd18be6e80d2603.png

Debugging estimate#

  1. Seasonal cycle in ‘inverse” \(T_z\) estimated as \(⟨χ/2⟩ / ⟨K_T T_z⟩\)

  2. Negative \(K_e\) values are where the annual mean gradient in climatology is larger than the “inverse” \(T_z\)

  3. \(⟨T^χ_z⟩\) from χpods averaged in density space is always larger than the other two estimates

%matplotlib inline

est = chidens.isel(pden=2)
isoTz = isoT.dTdz.isel(pden=2)

f, axx = plt.subplots(
    4,
    1,
    sharex=True,
    sharey=False,
    squeeze=False,
    constrained_layout=True,
    figsize=(4, 6),
)
ax = dict(zip(["count", "chi", "KtTz", "Tz"], axx.flat))

(est["numobs"]).plot.step(ax=ax["count"])
(est.chi / 2).plot.step(ax=ax["chi"], label="$⟨χ/2⟩$")
(est.KtTz * isoTz).plot.step(ax=ax["chi"], label="$⟨K_T T_z⟩ ⟨T_z⟩$", _labels=False)
ax["chi"].legend()
# (est.KtTz * est.dTdz).plot(ax=ax["chi"])

(est.KtTz).plot.step(ax=ax["KtTz"])

(est.dTdz).plot.step(ax=ax["Tz"], label="$⟨T^χ_z⟩$")
(est.chi / 2 / est.KtTz).plot.step(
    ax=ax["Tz"], label="$⟨χ/2⟩ / ⟨K_T T_z⟩$", _labels=False
)
dcpy.plots.liney(isoTz, ax=ax["Tz"], label="$⟨T_z⟩$")
ax["Tz"].legend()
dcpy.plots.clean_axes(axx)
_images/7bcd1d0a402fd8fa6438572decc449d8cedff5301255b1da780275d9c89f1e3e.png

The “seasonal” cycle in \(T_z\) is funny. There are more observations being averaged over and those observations are at 30,40,50m.

I thought it is an artifact. BUT what if there is a seasonal cycle in \(T_z\) in in the isopycnal bins.

In depth space, \(T_z\) increases with depth, so if the isopycnal surface shallows for two months (DJF here), “effective” dT/dz is smaller than our climatological estimate. This ends up being negative \(K_e\)

I think this is being ignored in the equations. Maybe this is advection at “eddy” timescales that is changing \(T_z\) at the “eddy” timescale

Manually excluding everything above 59m improves things a bunch.

Things that may help:

  1. Choose bins to avoid this by looking at plots?

  2. add a diagnostic that checks for scatter in \(T_z\) in chosen bins. This could help with 1.

  3. Explicitly account for this as a source of variance?

taos.rhoT.resample(time="2W").mean().plot.contour(levels=20, yincrease=False)
<matplotlib.contour.QuadContourSet at 0x7fa71984b110>
_images/2b37a5e07e10e41039b036f058b23f11014d8926bc182b1693e18f5cc3367f10.png
(
    chisub.pden.resample(time="3D")
    .mean()
    .plot(
        x="time",
        levels=bins,
        yincrease=False,
        cmap=mpl.cm.magma_r,
        edgecolor="w",
        linewidths=0.15,
    )
)
<matplotlib.collections.QuadMesh at 0x7fa71d96e750>
_images/a5265096e8ed76b470f21832aae700bc6c58da883d71237d69b80eaefe256b4e.png
chisub.resample(time="M").mean().dTdz.plot.line(hue="depth")
[<matplotlib.lines.Line2D at 0x7fa719870cd0>,
 <matplotlib.lines.Line2D at 0x7fa71636d390>,
 <matplotlib.lines.Line2D at 0x7fa7197d9dd0>,
 <matplotlib.lines.Line2D at 0x7fa7197cd850>,
 <matplotlib.lines.Line2D at 0x7fa716323650>,
 <matplotlib.lines.Line2D at 0x7fa7197df0d0>,
 <matplotlib.lines.Line2D at 0x7fa71ae64bd0>]
_images/017122036611c01c5a5174fcb44835fff4bf7961d5e04efad44a76c9451673ac.png
fg = (chidens["chi"] / 2).plot(col="pden", col_wrap=2)
fg.data = chidens.KtTz
fg.map_dataarray_line(xr.plot.line, x="time", y=None, hue=None)
<xarray.plot.facetgrid.FacetGrid at 0x7f87862524d0>
_images/73cf108ad567625bebcd90f4080cb2355aea15bf24aefa1db8708538dad23e7e.png
(chidens["chi"] / 2).plot.line(hue="pden")
plt.figure()
(chidens["KtTz"] * isoT["dTdz"]).plot.line(hue="pden")
[<matplotlib.lines.Line2D at 0x7f8787a05450>,
 <matplotlib.lines.Line2D at 0x7f8786e04150>,
 <matplotlib.lines.Line2D at 0x7f8794ec69d0>,
 <matplotlib.lines.Line2D at 0x7f8794ec6990>]
_images/7e15fa70eb9a7f17e0aa483ae578fb21d9286286dd8587e3b61b610d32de2cc6.png _images/d47b1e78a059aae87dd9e4536136a7c13aaeb8a3be2a1fce8aea39c1b911116b.png
chisub.KT.resample(time="D").mean().plot.line(hue="depth", yscale="log")
[<matplotlib.lines.Line2D at 0x7f38dfaedf10>,
 <matplotlib.lines.Line2D at 0x7f38dfaa3d50>,
 <matplotlib.lines.Line2D at 0x7f38dfb8ce10>,
 <matplotlib.lines.Line2D at 0x7f38e3783a50>,
 <matplotlib.lines.Line2D at 0x7f38e34ce490>,
 <matplotlib.lines.Line2D at 0x7f38dfaba950>,
 <matplotlib.lines.Line2D at 0x7f38dfb84990>]
_images/7dd8fa5f19cbd1aad8f0665f154293ec48cac78f5498927a91406a769d71c285.png

Testing χ#

eccoT.dTdz.interp(lat=0)
<xarray.DataArray 'dTdz' (pden: 3)>
array([0.03427257, 0.096845  , 0.06992526])
Coordinates:
    lon          float64 220.2
  * pden         (pden) float64 1.024e+03 1.025e+03 1.026e+03
    dz_remapped  (pden) float64 49.35 69.1 35.2
    y            float64 0.0
    lat          int64 0
chisub.chi.plot.line(row="depth", yscale="log")
<xarray.plot.facetgrid.FacetGrid at 0x7fd6914463d0>
_images/9635daf13d5003777d21abdeb110fc7ca90ad5779645ed0ddac9b7dba936d679.png
chi2.dTdz.mean().compute()
<xarray.DataArray 'dTdz' ()>
array(0.03167741)
Coordinates:
    lat      float64 0.0
    lon      float64 -140.0
    mooring  float64 9.969e+36
    chipod   float64 9.969e+36
Attributes:
    long_name:              vertical temperature gradient
    units:                  K m-1
    FillValue:              -9999
    valid_min:              4.9999999999999996e-06
    valid_max:              0.001
    coverage_content_type:  physicalMeasurement
    grid_mapping:           crs
    references:             Moum, J.N. and J.D. Nash, Mixing measurements on ...
    cell_methods:           depth: point, time: mean
    platform:               mooring
    instrument:             chipod
chi2.dTdz.plot.hist(bins=100)
dcpy.plots.linex(0.04)
dcpy.plots.linex(chi2.dTdz.mean(), color="r")
dcpy.plots.linex(chi2.dTdz.compute().median(), color="r")
_images/5ba7d494ccfed14384cf3f936df164b147a744735cb79f0b335ccfdb8162ff76.png
chisub.T.mean("time").differentiate("depth").plot(y="depth", yincrease=False)
[<matplotlib.lines.Line2D at 0x7fd68e34d850>]
_images/1fccbc975472c1b8f2b29e97690560cfe0084be4d850475f5589f361744acb9f.png

use observed mean dTdz instead of cliamtological mean

meanTz = 0.04
chi2 = (
    chisub.sel(depth=slice(50)).where(chisub.KT < 1e-3).where(chisub.dTdz > 1e-2)
)  # .resample(time="D").mean()
# chi2 = chi2.resample(time="D").mean()

np.log10((chi2.KtTz * meanTz) / (chi2.chi / 2)).plot.hist(bins=200, density=True);
# np.log10((chi2.KtTz * meanTz) / (chi2.chi)).plot.hist(bins=200, density=True);
_images/7beea78e7bef82e4c3329718eac0352d1d5130e17f542eed470e19f94f924790.png


Old stuff#

eccograd, argograd, cole, aber = ed.read_all_datasets(kind="monthly")
argograd.time.attrs["axis"] = "T"
argograd.pres.attrs["positive"] = "down"
argograd.sel(lat=0, lon=360 - 140, method="nearest").dTiso.cf.plot.pcolormesh(
    y="Z", robust=True, cmap=mpl.cm.Oranges
)
<matplotlib.collections.QuadMesh at 0x7fd6930df290>
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:214: RuntimeWarning: Glyph 8711 missing from current font.
  font.set_text(s, 0.0, flags=flags)
/home/deepak/miniconda3/envs/dcpy/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py:183: RuntimeWarning: Glyph 8711 missing from current font.
  font.set_text(s, 0, flags=flags)
_images/9b5003533db59bc287916f9d30a73c33c9582adef79eecb6980f8d0a864718f5.png
chidens = binned.to_xarray()
grad, _ = ed.bin_to_density_space(
    argograd.sel(lat=0, lon=360 - 140, method="nearest").rename({"ρmean": "rho"}),
    bins=bins,
)
grad = grad.sel(time=chidens.time.dt.month.values).assign_coords(time=chidens.time)
grad
<xarray.Dataset>
Dimensions:   (rho: 4, time: 358)
Coordinates:
  * time      (time) datetime64[ns] 2008-05-10 2008-05-11 ... 2009-05-02
  * rho       (rho) float32 1022.75 1023.25 1024.5 1025.75
    lat       float32 0.5
    lon       float32 220.5
Data variables:
    pres      (time, rho) float64 15.62 50.0 95.0 140.0 ... 50.0 95.0 140.0
    Smean     (time, rho) float32 35.150955 35.16125 ... 35.08096 34.97392
    Tmean     (time, rho) float32 26.652958 25.90761 ... 21.142931 15.874863
    dSdia     (time, rho) float64 0.0004355 0.0007541 ... 0.002183 0.002707
    dSdz      (time, rho) float32 -0.00043551126 0.0005791346 ... 0.002706909
    dSiso     (time, rho) float64 1.038e-06 1.437e-06 ... 2.434e-06 1.457e-06
    dTdia     (time, rho) float64 0.009585 0.0497 0.127 ... 0.0497 0.127 0.08775
    dTdz      (time, rho) float32 0.009585428 0.04970134 ... 0.08775275
    dTiso     (time, rho) float64 2.479e-06 3.539e-06 ... 6.849e-06 5.099e-06
    mean_rho  (time, rho) float32 1022.9419 1023.1831 ... 1024.4943 1025.7537
chidens["rho"] = grad["rho"]
Ke = (chidens["chi"] / 2 - np.abs(chidens["KtTz"] * grad["dTdz"] / 3)) / (
    grad["dTiso"] ** 2
)
Ke
<xarray.DataArray (rho: 4, time: 358)>
array([[            nan,             nan,             nan, ...,
                    nan,             nan,             nan],
       [ 11726.46725949,   8248.95985651,   5027.56820076, ...,
          -204.25370459,   -334.24473111,   -187.44859464],
       [ -1879.12790238, -12763.75317847, -15621.72404617, ...,
        -40449.6307827 , -59050.73202118, -58244.54230018],
       [            nan,             nan,             nan, ...,
                    nan,             nan,             nan]])
Coordinates:
  * rho      (rho) float32 1022.75 1023.25 1024.5 1025.75
  * time     (time) datetime64[ns] 2008-05-10 2008-05-11 ... 2009-05-02
    lat      float32 0.5
    lon      float32 220.5
Ke.isel(rho=2).plot()
[<matplotlib.lines.Line2D at 0x7feb1dc04650>]
_images/6708250622bdab894780a089924e5a5cbd251a2f8419889013d58c5d05774221.png
(chidens["chi"] / 2 - np.abs(chidens["KtTz"] * grad["dTdz"])).cf.plot(
    x="time", y="rho", robust=True
)
<matplotlib.collections.QuadMesh at 0x7feb1c082110>
_images/dc561345ebe9cb1968977e359865da39ae818e31a637e2e46eff185ee2c32826.png