EQUIX: Jq divergence#

Hide code cell content
%load_ext watermark
%matplotlib inline


import glob
import os

import cf_xarray as cfxr
import dcpy
import distributed
import hvplot.xarray
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from dcpy.oceans import read_osu_microstructure_mat
from IPython.display import Image

# import eddydiff as ed
import pump

xr.set_options(keep_attrs=True)
mpl.rcParams["figure.dpi"] = 140

%watermark -iv
The watermark extension is already loaded. To reload it, use:
  %reload_ext watermark
xarray     : 0.19.0
cf_xarray  : 0.5.3.dev29+g3660810.d20210729
numpy      : 1.21.3
hvplot     : 0.7.3
dcpy       : 0.1
matplotlib : 3.4.3
distributed: 2021.10.0
pump       : 0.1

Read data#

Hide code cell content
# th = xr.load_dataset("/home/deepak/datasets/microstructure/osu/tropicheat.nc")
# tiwe = xr.load_dataset("/home/deepak/datasets/microstructure/osu/tiwe.nc")
equix = xr.load_dataset("/home/deepak/datasets/microstructure/osu/equix.nc")

tao = xr.open_dataset(
    "/home/deepak/work/datasets/microstructure/osu/equix/hourly_tao.nc"
)
iop = xr.open_dataset(
    "/home/deepak/work/datasets/microstructure/osu/equix/hourly_iop.nc"
)
eop = xr.open_dataset(
    "/home/deepak/work/datasets/microstructure/osu/equix/hourly_eop.nc"
)
%matplotlib inline
plt.rcParams["figure.dpi"] = 140

np.abs(equix.chi / 2 / (equix.dTdz.where(np.abs(equix.dTdz) > 5e-3) ** 2)).mean(
    "time"
).plot(y="depth", yincrease=False)
np.abs(0.2 * equix.eps / equix.N2).mean("time").plot(
    y="depth", yincrease=False, xscale="log", xlim=(1e-6, 1e-1)
)
[<matplotlib.lines.Line2D at 0x7f8ecf07cd90>]
_images/94fbe172d2a4f11d6a3e00369ac186426409e2e15fbdfbf45f0d383c3cd20290.png

Chameleon dJ/dz estimate#

subset = equix.sel(time=slice("2008-10-29", "2008-11-03"))
eps_plot = subset.eps.hvplot.quadmesh(
    y="depth",
    x="time",
    cmap="RdYlBu_r",
    cnorm="log",
    clim=(1e-10, 1e-5),
    ylim=(200, 0),
)

theta_contours = subset.theta.hvplot.contour(
    # levels=[21, 22, 23, 24], #colors="gray", #linewidths=0.5, x="time", ax=ax[0]
)
# equix.theta.cf.plot.contour(
#    levels=bins, colors="k", linewidths=0.25, x="time", ax=ax[0]
# )
# equix.mld.plot(color="g", ax=ax[0], lw=0.25)
# equix.eucmax.plot(color="k", ax=ax[0], lw=0.5)
# dcpy.plots.liney(iop.depth.data, zorder=10, color="w", ax=ax[0])
# dcpy.plots.liney(tao.depth.data, zorder=10, color="cyan", ax=ax[0])

eps_plot * theta_contours
%matplotlib widget

f, ax = plt.subplots(3, 1, sharex=True, sharey=True, constrained_layout=True)

equix.eps.cf.plot(
    x="time",
    cmap=mpl.cm.RdYlBu_r,
    norm=mpl.colors.LogNorm(),
    robust=True,
    ax=ax[0],
)
equix.theta.cf.plot.contour(
    levels=[21, 22, 23, 24], colors="gray", linewidths=0.5, x="time", ax=ax[0]
)
# equix.theta.cf.plot.contour(
#    levels=bins, colors="k", linewidths=0.25, x="time", ax=ax[0]
# )
equix.mld.plot(color="g", ax=ax[0], lw=0.25)
equix.eucmax.plot(color="k", ax=ax[0], lw=0.5)
dcpy.plots.liney(iop.depth.data, zorder=10, color="w", ax=ax[0])
dcpy.plots.liney(tao.depth.data, zorder=10, color="cyan", ax=ax[0])

smooth_dJdz = (
    -1
    * equix.dJdz
    # .coarsen(depth=2, boundary="trim")
    # .mean()
    # .resample(time="3H")
    # .mean()
)
smooth_dJdz.attrs["long_name"] += " (2m, 3H mean)"
smooth_dJdz.cf.plot(
    x="time",
    cmap=mpl.cm.coolwarm,
    robust=True,
    ax=ax[1],
)
equix.theta.cf.plot.contour(
    levels=[21, 22, 23, 24], colors="gray", linewidths=0.5, x="time", ax=ax[1]
)
equix.mld.plot(color="g", ax=ax[1], lw=0.25)
equix.eucmax.plot(color="k", ax=ax[1], lw=1)
dcpy.plots.liney(iop.depth.data, zorder=10, color="k", ax=ax[1])
dcpy.plots.liney(tao.depth.data, zorder=10, color="cyan", ax=ax[1])

(-1 * equix.Jq).coarsen(depth=3, boundary="trim").mean().resample(
    time="H"
).mean().cf.plot(
    x="time",
    cmap=dcpy.plots.white_blue_orange_red,
    robust=True,
    ax=ax[2],
)
equix.theta.cf.plot.contour(
    levels=[21, 22, 23, 24], colors="gray", linewidths=0.5, x="time", ax=ax[2]
)
equix.mld.plot(color="g", ax=ax[1], lw=0.25)
equix.eucmax.plot(color="k", ax=ax[1], lw=1)
dcpy.plots.liney(iop.depth.data, zorder=10, color="k", ax=ax[2])
dcpy.plots.liney(tao.depth.data, zorder=10, color="m", ax=ax[2])


plt.ylim([120, 0])
plt.xlim(["2008-10-25", "2008-11-06"])
f.set_size_inches((8, 8))

Chameleon dJ/dz (depth space)#

Temperature contours work shows that at short-ish time scales(< 12h) depth space averaging should be OK.

%matplotlib widget
plt.rcParams["figure.dpi"] = 140
avg = equix.resample(time="H").mean().coarsen(depth=5).mean()
avg["dTdz"] = avg.theta.differentiate("depth")
avg["dTdz"] = avg.dTdz.where(np.abs(avg.dTdz) > 5e-3)
avg["Jq"] = 1025 * 4000 * avg.chi / 2 / avg.dTdz
avg["Jq"].attrs = equix.Jq.attrs
avg["dJdz"] = avg.Jq.differentiate("depth")
avg["dJdz"].attrs = equix.dJdz.attrs
avg.dJdz.cf.plot(robust=True)
<matplotlib.collections.QuadMesh at 0x7f20d9876730>
j = avg.Jq.resample(time="D").mean()
j = j.where(np.abs(j) < 1e4).drop_vars("time")
equix_mean.chi.mean("time").plot(y="depth", xscale="log", yincrease=False)
equix.chi.mean("time").plot(y="depth", xscale="log")
[<matplotlib.lines.Line2D at 0x7f20d989a2b0>]
_images/2b62266468de1fd8c0a4a3b7f25962a15cadfe605a54e271234b4dd3a486e00b.png
equix_mean = equix.resample(time="D").mean().drop_vars("time")
tao_mean = (
    tao.sel(time=slice(equix.time[0], equix.time[-1]))
    .resample(time="D")
    .mean()
    .drop_vars("time")
)
iop_mean = (
    iop.sel(time=slice(equix.time[0], equix.time[-1]))
    .resample(time="D")
    .mean()
    .drop_vars("time")
)
da = ds[var].pipe(rescaler[var])
da.name = var
da.hvplot.line(y="depth", by="time"
%matplotlib inline
plt.rcParams["figure.dpi"] = 150

f, axx = plt.subplots(1, 4, constrained_layout=True)

for ax, var in zip(axx, ["chi", "eps", "Jq", "dTdz"]):
    for ds, marker, label in zip([iop_mean, tao_mean], ["x", "^"], ["IOP", "TAO"]):
        if label == "TAO":
            continue
        ax.scatter(
            np.abs(equix_mean[var]).sel(
                depth=ds.depth.isel(depth=slice(1, None)), method="nearest"
            ),
            np.abs(ds[var].isel(depth=slice(1, None))),
            s=8,
            c=np.repeat(ds.time.data, ds.sizes["depth"] - 1),
            marker=marker,
            label=label,
        )

    ax.legend()

    ax.set_xscale("log")
    ax.set_yscale("log")
    ax.set_title(var)
    ax.set_xlabel("chameleon")
    ax.set_ylabel("TAO or IOP")

    dcpy.plots.line45(ax)


f.set_size_inches((10, 4))

# [axxx.set_xscale("log") for axxx in axx[:2]]
# [axxx.set_yscale("log") for axxx in axx[:2]]
_images/e7c5cd0c75f4d9432d0deb46c4b498af3ad79d1f7e1f47357eaa6f92ce015196.png
equix_mean = equix.resample(time="D").mean().drop_vars("time")
(equix_mean.chi.isel(depth=slice(20, None))).mean("time").cf.plot(xscale="log")
(equix_mean.eps).mean("time").cf.plot(xscale="log")

plt.gca().set_prop_cycle(None)
(equix.chi.isel(depth=slice(20, None))).mean("time").cf.plot(xscale="log")
(equix.eps.isel(depth=slice(20, None))).mean("time").cf.plot(xscale="log")
[<matplotlib.lines.Line2D at 0x7f20da3a9400>]
equix_mean = equix.resample(time="D").mean().drop_vars("time")
equix_mean["dTdz"] = equix_mean.theta.differentiate("depth")
(np.abs(equix_mean.dTdz) ** 1).mean("time").cf.plot(xscale="linear")
# (0.2 * equix_mean.eps.isel(depth=slice(20, None))/equix_mean.N2).mean("time").cf.plot(xscale="log")

# plt.gca().set_prop_cycle(None)
(np.abs(equix.dTdz) ** 1).mean("time").cf.plot(xscale="linear")
# (0.2 * equix.eps.isel(depth=slice(20, None))/equix.N2).mean("time").cf.plot(xscale="log")
[<matplotlib.lines.Line2D at 0x7f20d7a83ac0>]
_images/38afe4b34ec75dab1560f3aa24e372d7113f6399bce650ec3d31bc5e0179322d.png
(
    1025
    * 4000
    * 2
    * equix_mean.chi.isel(depth=slice(20, None))
    / 2
    / equix_mean.dTdz.where(np.abs(equix_mean.dTdz) > 1e-2)
).mean("time").cf.plot()
(
    1025
    * 4000
    * 0.2
    * equix_mean.eps.isel(depth=slice(20, None))
    / equix_mean.N2
    * equix_mean.dTdz
).mean("time").cf.plot()
[<matplotlib.lines.Line2D at 0x7f20da4cc9a0>]
_images/6417f257aac8fddeb370bfebb22188b9fe3acf837b329a4dee1b66831e19dfb6.png
plt.figure()
itime = 2
var = "Jq"
yscale = "linear"
equix_mean.sel(time=itime)[var].plot(yscale=yscale)
iop_mean.sel(time=itime)[var].plot(yscale=yscale, marker="x")
tao_mean.sel(time=itime)[var].plot(yscale=yscale, marker="o")
[<matplotlib.lines.Line2D at 0x7f20dfbe04c0>]
%matplotlib widget

rescaler = {
    "chi": lambda x: np.log10(x) + x.time * 3,
    "eps": lambda x: np.log10(x) + x.time * 3,
    "Jq": lambda x: np.abs(x) / 150 + x.time * 3 - 10,
    "dTdz": lambda x: np.abs(x) * 1e1 + x.time * 3 - 10,
}


f, axx = plt.subplots(4, 1, sharex=True, sharey=True)
names = ["chi", "eps", "Jq", "dTdz"]
ax = dict(zip(names, axx))
for var, aa in ax.items():
    for ds, kwargs in zip(
        [equix_mean, iop_mean, tao_mean],
        ({}, {"ls": "none", "marker": "x"}, {"ls": "none", "marker": "o"}),
    ):
        ds = ds.isel(time=[4])
        aa.set_prop_cycle(None)
        ds[var].pipe(rescaler[var]).cf.plot.line(
            hue="time", add_legend=False, xlim=(-15, 40), ax=aa, **kwargs
        )

# rescale(equix_mean.chi).cf.plot.line(hue="time", add_legend=False)
# ax.set_prop_cycle(None)
# rescale(iop_mean.chi).cf.plot.line(hue="time", marker="x", ls="none", add_legend=False)
# ax.set_prop_cycle(None)
# rescale(tao_mean.chi).cf.plot.line(hue="time", marker="o", ls="none", add_legend=False)

Chameleon \(w_{ci}\) estimate#

Following Winters & D’Asaro (1996) §7.

Take a group of profiles (e.g. 3 hours or a day, with approx. 6 profiles per hour), and choose temperature bin edges \(θ_{bin} = θ_f\) (“theta at faces”)

  1. Calculate dT/dz: Identify pressure of each \(θ_{f}\), find mean \(Δp\) between each pair of bins in this group of profiles (mean distance between isotherms), then \(⟨T⟩_z = Δθ_{f}/Δp\) at \(θ_c\) (“theta centers”)

  2. Calculate heat flux \(J_q = ρ c_p ⟨χ⟩/2/⟨T⟩_z\) at \(θ_f\), where \(⟨χ⟩\) is 1m χ averaged in temperature bins.

  3. Calculate \(w_{ci} = 1/(ρc_p) ΔJ_q/Δθ_c\)

TODO:

  1. Check mld estimate

  2. Ignore bin averages when number of observations is “small”

Choosing bins#

bins = np.hstack(
    [np.arange(18, 23, 1), np.arange(23, 24, 0.5), np.arange(24, 27, 0.25)]
)

f, ax = plt.subplots(2, 1, sharex=True, sharey=True, constrained_layout=True)

equix.eps.cf.plot(
    x="time",
    cmap=mpl.cm.RdYlBu_r,
    norm=mpl.colors.LogNorm(),
    robust=True,
    ax=ax[0],
    cbar_kwargs={"orientation": "horizontal"},
)
equix.theta.cf.plot.contour(
    levels=bins, colors="k", linewidths=0.25, x="time", ax=ax[0]
)
equix.mld.plot(color="g", ax=ax[0], lw=0.25)
dcpy.plots.liney(iop.depth.data, zorder=10, color="w", ax=ax[0])

equix.theta.cf.plot.contourf(
    x="time",
    cmap=mpl.cm.Spectral_r,
    vmin=bins[0],
    vmax=bins[-1],
    levels=bins,
    ax=ax[1],
    add_colorbar=False,
)
dcpy.plots.liney(iop.depth.data, zorder=10, color="w", ax=ax[1])
hdl = equix.mld.plot(color="g", ax=ax[1], lw=0.25)
dcpy.plots.annotate_end(hdl[0], "MLD")

f.set_size_inches((6, 6))
_images/31a19819ee16d6fdb7843ac53c61c1200174b0946b1f962517e8066bbb6f1ce7.png

Example: 1 Day average#

First panel shows mean θ (simple time average) in blue and the reconstructed T profile in orange. Not sure if I should be worried about the difference.

Second panel shows \(J_q\) (blue) and \(∂J/∂z\) in red (signed so that positive means heating).

Third panel is wci due to shear

profiles.theta.interp(depth=profiles.eucmax).plot()
[<matplotlib.lines.Line2D at 0x7fa28387a610>]
_images/01de8509e20c599e26c0e4fe96613d1a7ec9bb5ee8fea2479dd60b791cbe913d.png
profiles = equix.sel(
    time=slice("2008-10-29 15:00", "2008-10-30 15:00"), depth=slice(156)
)
eucmax = profiles.eucmax
profiles = profiles.where(profiles.depth > profiles.mld)
profiles["eucmax"] = eucmax
result = pump.tspace.regrid_chameleon_(profiles, bins=bins, debug=True, trim_mld=False)
_images/7353f034790352238a84889e691886ed9ed3dcc7cb7b42318fa33ad377aadd22.png _images/54e02bfce94e2ba98d14c59813346103f3951e8889b43dc63e99b2af363bd093.png
profiles = equix.sel(
    time=slice("2008-11-01 15:00", "2008-11-02 15:00"), depth=slice(156)
)
eucmax = profiles.eucmax
profiles = profiles.where(profiles.depth > profiles.mld)
profiles["eucmax"] = eucmax
result = pump.tspace.regrid_chameleon_(profiles, bins=bins, debug=True, trim_mld=False)
_images/067ef73a8fe79b81e835300b3764b3ba294f5965560e0f4088714a2342ee96ae.png _images/f530d5bd51afdcf20bf271e88d272c759e5e9477b4135dbc4a016fae8984cef9.png

The following figure is from before I switched to interpolating to find depth of isothermal surfaces, i.e. closer to what is proposed in Winters & D’Asaro (1996). Note that I seem to be losing heat during regridding (panel 1)

Hide code cell content
profiles = equix.sel(
    time=slice("2008-10-29 15:00", "2008-10-30 15:00"), depth=slice(156)
)
profiles = profiles.where(profiles.depth > profiles.mld)
result = pump.tspace.regrid_chameleon_(profiles, debug=True, trim_mld=False)
_images/c7202ff51c2a0435cab4c88e463419af10de8b04c9889e13ce72d50ff487c75d.png _images/4ecc2ca7a8a14b773a70783c8f638738ba3ded8f06de4721338133885980c7c4.png

All data: 3 hour average#

Here I use 3 hour averages for all the data. Exlude mld+5m to account for some uncertainty in finding MLD. I think it’s too noisy, could be improved.

equixT = pump.tspace.regrid_chameleon(
    equix.sel(depth=slice(156)).where(equix.depth > equix.mld + 5),
    time_freq="3H",
    bins=bins,
    trim_mld=False,
)

This summary plot shows ε for the full record and wci.

f, ax = plt.subplots(2, 1, sharex=True, squeeze=False, constrained_layout=True)
equix.eps.cf.plot(
    x="time", cmap=mpl.cm.RdYlBu_r, norm=mpl.colors.LogNorm(), robust=True, ax=ax[0, 0]
)
# equix.dJdz.cf.plot(
#    x="time", cmap=mpl.cm.RdBu, vmin=-10, vmax=10, ax=ax[0, 0]
# )
equix.theta.resample(time="H").mean().cf.plot.contour(
    levels=equixT.theta_f,
    colors="k",
    linewidths=0.5,
    x="time",
    ax=ax[0, 0],
    ylim=(150, 0),
)
equixT.wci.sel(theta_f=slice(None, 26)).plot(x="time", vmin=-10, ax=ax[1, 0])

dcpy.plots.clean_axes(ax)
f.set_size_inches((8, 4))
_images/e9ef8e65ebc17ac6234a69b3ee283668d8f6ffaf461b4dc82f1b47d4d1a2aaaf.png

All data: daily average#

I’m using a daily average starting at midnight.

equixT = pump.tspace.regrid_chameleon(
    equix.sel(depth=slice(156)).where(equix.depth > equix.mld + 5),
    time_freq="1D",
    bins=bins,
    trim_mld=False,
)
f, ax = plt.subplots(2, 1, sharex=True, squeeze=False, constrained_layout=True)
equix.eps.cf.plot(
    x="time", cmap=mpl.cm.RdYlBu_r, norm=mpl.colors.LogNorm(), robust=True, ax=ax[0, 0]
)
# equix.dJdz.cf.plot(
#    x="time", cmap=mpl.cm.RdBu, vmin=-10, vmax=10, ax=ax[0, 0]
# )
equix.theta.resample(time="H").mean().cf.plot.contour(
    levels=equixT.theta_f,
    colors="k",
    linewidths=0.5,
    x="time",
    ax=ax[0, 0],
    ylim=(150, 0),
)
equixT.wci.sel(theta_f=slice(None, 26)).plot(x="time", vmin=-10, ax=ax[1, 0])

dcpy.plots.clean_axes(ax)
f.set_size_inches((8, 4))
_images/ac9cc6e26297c61967f04e92dc1f043a2b065e4a74da3c61264b2f921efbe4f8.png

All data: 5-day average#

Maybe this is comparable to POP2?

equixT = pump.tspace.regrid_chameleon(
    equix.sel(depth=slice(156)).where(equix.depth > equix.mld + 5),
    time_freq="5D",
    bins=bins,
    trim_mld=False,
)
f, ax = plt.subplots(2, 1, sharex=True, squeeze=False, constrained_layout=True)
equix.eps.cf.plot(
    x="time", cmap=mpl.cm.RdYlBu_r, norm=mpl.colors.LogNorm(), robust=True, ax=ax[0, 0]
)
# equix.dJdz.cf.plot(
#    x="time", cmap=mpl.cm.RdBu, vmin=-10, vmax=10, ax=ax[0, 0]
# )
equix.theta.resample(time="H").mean().cf.plot.contour(
    levels=equixT.theta_f,
    colors="k",
    linewidths=0.5,
    x="time",
    ax=ax[0, 0],
    ylim=(150, 0),
)
equixT.wci.sel(theta_f=slice(None, 26)).plot(x="time", vmin=-5, ax=ax[1, 0])

dcpy.plots.clean_axes(ax)
f.set_size_inches((8, 4))
_images/c984e0cf59fec7248553986c29912e8be67f22f49e9e6a383943bbcf370ee6c7.png

Conservative regridding#

I think I’m losing heat when reconstructing the profile with mean ∂T/∂z! but this conservative thing gives a smaller spacing. I think there’s a bug

profiles = profiles.drop(["lon", "lat"]).cf.guess_coord_axis()
Hide code cell content
grouped = (
    profiles[["theta", "pres"]]
    .sel(time=slice("2008-10-30 00:00", "2008-10-30 03:00"))
    .groupby_bins(
        "theta",
        bins=bins,
    )
)


dzs = []

for label, group in grouped:
    Tmean = (label.left + label.right) / 2
    temp = group.unstack().theta
    plt.figure()
    temp.plot()

    Δt = (temp.time[-1] - temp.time[0]).astype(int)

    dzs.append(
        xr.Dataset(
            {
                "mean": pump.tspace.get_avg_dz(group),
                "conservative": -1
                * (temp.fillna(0) - temp.min())
                .interpolate_na("depth")
                .integrate(["time", "depth"])
                / Δt
                / Tmean,
            }
        )
    )
_images/89f90ebbb32a81501095026059ee2f774695903426cd1c6855c2053c45c349c9.png _images/de5c22a2026afa86f0a65002c7ede9c156be31c17474ff59cc818dd09cf04359.png _images/b6d7343b56ba0b7e82e9d4152fc407d5f1ff242265f62c48033485074fd82779.png _images/50de7669fd0264c4e131cccc3ae11d33c8cb09fc66647c165efa174027691aa6.png _images/9e01e54a7c549a69bebf2168bc2646f1b0f593647a06feef36b014af1aece3db.png _images/dbc88af537cc05015360936def339d7d0313000901619e067f03a596bb69cdee.png _images/539ca2ef0586446581d6c14d5e520397f88694d999e1e450ae82daadb2a1e3dd.png _images/be4edd794cb1eec9c0423bab72bdfc542571aa44d3f07f22206777683cc14782.png _images/7d0220df178f88398b4b3a90427611fb3b1e642f6ff33ab43243f4254a50314e.png _images/49e3225d9544ab0c323c9159237cbdc7d7e547abd6b304b24bdb18c7d1e081bb.png _images/ac2e625651075d6eb64aaf74f03655389a1a53a6ef829faa53b98f6d341eb45e.png _images/81e6eac9abec14e83ba902f45679a024834541f460a5aa2b6ba706e26aa81746.png
xr.concat(dzs, dim="theta_bins").to_array().plot(hue="variable")
[<matplotlib.lines.Line2D at 0x7f0daf4faac0>,
 <matplotlib.lines.Line2D at 0x7f0daf57a550>]
_images/a34dd979a623b1492caa8cd75ccf350e0d6d67d431d8a3e53098b680cdb635db.png

Chameleon vs χpod: dJ/dz#

equix.eps.cf.plot(x="time", robust=True, norm=mpl.colors.LogNorm())
dcpy.plots.liney(iop.depth.data, zorder=10, color="w")
_images/a93cd8a09ec6b4ad1d5262481b68a5478f8a0bed09f536d714e1bdc7cb711383.png
iop.Jq.sel(depth=[49, 51]).differentiate("depth").isel(depth=1).plot()
iop.Jq.sel(depth=[49, 53]).differentiate("depth").isel(depth=1).plot()
iop.Jq.sel(depth=[51, 53]).differentiate("depth").isel(depth=1).plot()
iop.Jq.sel(depth=[49, 51, 53]).differentiate("depth").isel(depth=1).plot()
[<matplotlib.lines.Line2D at 0x7fae0b16bee0>]
_images/bfce771702b3e8037563b12f61d3579bba2a7ff99c41ca92b4dafda4fd1d8ce9.png
import hvplot.xarray
import ipywidgets as ipw
import panel as pn
iop.Jq.interactive.sel(depth=pn.widgets.DiscreteSlider).plot()
import pump

T = pump.read_eq_tao_temp_hr()
tfloor = equix.time.dt.floor("D").data

taoT = (
    T.sel(longitude=-140, time=slice(tfloor[0], tfloor[-1]))
    .sel(depth=slice(-200, 0))
    .squeeze()
    .load()
    .dropna("depth", how="all")
)
del taoT.depth.attrs["positive"]
taoT["depth"] = taoT.depth * -1
# S = pump.read_eq_tao_salt_hr()
100%|███████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 37.45it/s]
100%|███████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 88.18it/s]
/home/deepak/miniconda3/envs/dcpy/lib/python3.8/site-packages/dask/array/numpy_compat.py:41: RuntimeWarning: invalid value encountered in true_divide
  x = np.divide(x1, x2, out)
%matplotlib widget
mpl.rcParams["figure.dpi"] = 140

plt.figure(constrained_layout=True)

bins = np.hstack([17, 20, 22.75, 24.25, 25])
# equix.chi.cf.plot(x="time", norm=mpl.colors.LogNorm(), robust=True)
(-1 * equix.dJdz).rolling(depth=7, center=True).mean().resample(
    time="4H"
).mean().cf.plot(x="time", robust=True, cmap=mpl.cm.RdBu_r)
# taoT.cf.plot(robust=True)
taoT.cf.plot.contour(yincrease=False, levels=bins, colors="darkgreen")
dcpy.plots.liney(tao.depth, zorder=10, lw=1.5, color="darkgray", label="T")
dcpy.plots.liney(
    iop.depth,
    zorder=10,
    lw=1.5,
    color="k",
    label="E",
)
plt.figure()
iop.theta.cf.plot()
<matplotlib.collections.QuadMesh at 0x7f90d9d9e160>
plt.figure()
iop.Jq.sel(depth=[49, 51, 53]).differentiate("depth").isel(depth=1).resample(
    time="D"
).mean().plot()
equix.dJdz.rolling(depth=5, center=True).mean().resample(time="D").mean().sel(
    depth=51, method="nearest"
).plot()
[<matplotlib.lines.Line2D at 0x7f26578494c0>]
%matplotlib inline

tao.Jq.resample(time="3H").mean().sel(depth=[59, 69, 84]).plot(hue="depth")
[<matplotlib.lines.Line2D at 0x7f26594a5e50>,
 <matplotlib.lines.Line2D at 0x7f26594a5eb0>,
 <matplotlib.lines.Line2D at 0x7f2659456250>]
_images/61bfedbd0fafbcc6568403356637e301f151acf1bfc1a798c148c961028b14b0.png
%matplotlib inline
plt.rcParams["figure.dpi"] = 140
(tao.Jq.sel(depth=69).resample(time="8H").mean()).plot()
[<matplotlib.lines.Line2D at 0x7f265aa1e400>]
_images/9b8bfee9e438cc01f84e2be57acc23ef405fb513d273a953294c2268906a33b1.png
Δ = tao.sel(depth=[59, 69]).diff("depth").resample(time="D").mean()

(Δ.Jq / 10).plot()
[<matplotlib.lines.Line2D at 0x7f2668163f10>]
_images/826bbd9a84826b35501f8c09fa208839188b83909ba83c093e563bf05ed5d9ef.png