TIW DCL#

import dask_jobqueue

if "client" in locals():
    client.close()
if "cluster" in locals():
    cluster.close()

env = {"OMP_NUM_THREADS": "3", "NUMBA_NUM_THREADS": "3"}

# cluster = distributed.LocalCluster(
#    n_workers=8,
#    threads_per_worker=1,
#    env=env
# )

if "cluster" in locals():
    del cluster

cluster = dask_jobqueue.SLURMCluster(
    cores=1,
    processes=1,
    memory="25GB",
    walltime="08:00:00",
    project="NCGD0046",
    scheduler_options=dict(dashboard_address=":9797"),
)
# cluster = dask_jobqueue.PBSCluster(
#    cores=9, processes=9, memory="108GB", walltime="02:00:00", project="NCGD0043",
#    env_extra=env,
# )

cluster.scale(6)
# %load_ext autoreload
# %autoreload 2

%matplotlib inline

import dask
import distributed
import holoviews as hv
import hvplot.xarray
import matplotlib as mpl
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import matplotlib.units as munits
import numpy as np
import pandas as pd
import seawater as sw
import xarray as xr
from holoviews import opts

import cf_xarray
import dcpy
import pump

# import hvplot.xarray


# import facetgrid

mpl.rcParams["savefig.dpi"] = 300
mpl.rcParams["savefig.bbox"] = "tight"
mpl.rcParams["figure.dpi"] = 140

munits.registry[np.datetime64] = mdates.ConciseDateConverter()

xr.set_options(keep_attrs=True)


hv.extension("bokeh")
# hv.opts.defaults(opts.Image(fontscale=1.5), opts.Curve(fontscale=1.5))


print(dask.__version__)
print(distributed.__version__)
print(xr.__version__)


def unpack(d):
    val = []
    for k, v in d.items():
        if isinstance(v, dict):
            val.extend(unpack(v))
        else:
            val.append(v)
    return val


xr.DataArray([1.0])
2.23.0
2.23.0
0.16.0
<xarray.DataArray (dim_0: 1)>
array([1.])
Dimensions without coordinates: dim_0
client = distributed.Client(cluster)
client

Client

Cluster

  • Workers: 6
  • Cores: 6
  • Memory: 150.00 GB
from dask.cache import Cache

cache = Cache(5e9, 0.4)  # Leverage two gigabytes of memory
cache.register()  # Turn cache on globally
gcm1 = pump.Model(
    "/glade/u/home/dcherian/pump/TPOS_MITgcm_1_hb/HOLD_NC_LINKS/",
    name="gcm1",
    full=False,
    budget=False,
)
# gcm1.tao.load()
# gcm1.tao = xr.merge([gcm1.tao, pump.calc.get_tiw_phase(gcm1.tao.v)])
# gcm1.surface["zeta"] = xr.open_dataset(gcm1.dirname + "obs_subset/surface_zeta.nc").zeta
# gcm1.surface = gcm1.surface.chunk({"time": 1})
# gcm1.surface["zeta"] = gcm1.surface.v.differentiate("longitude") - gcm1.surface.u.differentiate("latitude")
calc uz
calc vz
calc S2
calc N2
calc shred2
Calc Ri
gcm1.tao["mld"] = pump.calc.get_mld(gcm1.tao.dens)
gcm1.tao["dcl"] = pump.calc.get_dcl_base_Ri(gcm1.tao)

read data#

model = gcm1
periods = np.arange(1, 9)
longitudes = [-110]  # -140, -155]
tslice = slice(None, "1996-03-01")
subset_fields = [
    "Jq",
    "theta",
    "salt",
    "dens",
    "u",
    "v",
    "w",
    "KPP_diffusivity",
    "sst",
    "Ri",
]
anomalize_fields = ["u", "v", "w", "theta", "salt", "sst"]
anomalize_over = ["time"]
import xfilter

surf = (
    model.surface.sel(longitude=longitudes, method="nearest")
    .assign_coords(longitude=longitudes)
    .drop("depth")
)
tao = model.tao.sel(longitude=longitudes, latitude=0).chunk({"longitude": 1})
# tao["time"] = model.full.time

sst = surf.theta.sel(longitude=longitudes).chunk({"longitude": 1, "time": -1})
sstfilt = pump.calc.tiw_avg_filter_sst(sst, "bandpass")  # .persist()

# filter out daily cycle
subdaily_sst = xfilter.lowpass(
    surf.theta.chunk({"time": -1, "latitude": 10}),
    coord="time",
    freq=2,
    cycles_per="D",
).reindex(time=tao.time)
subdaily_sst.attrs["long_name"] = "2 day filtered SST"
subdaily_sst.attrs["units"] = "C"

# surf["theta"] = (
#    sst.pipe(xfilter.lowpass, coord="time", freq=1/7, cycles_per="D", num_discard=0, method="pad")
# )

Tx = model.surface.theta.differentiate("longitude")
Ty = model.surface.theta.differentiate("latitude")
gradT = (
    np.hypot(Tx, Ty)
    .sel(longitude=longitudes, method="nearest")
    .assign_coords(longitude=longitudes)
    .drop_vars("depth")
)

# with performance_report("profiles/phase-period.html"):
tiw_phase, period, tiw_ptp = dask.compute(
    pump.calc.get_tiw_phase_sst(
        sstfilt.chunk({"longitude": 1}), gradT.chunk({"longitude": 1, "time": -1})
    ),
)[0]
full = pump.utils.read_gcm1_zarr_subset(gcm1)
# needed for apply_ufunc later
valid_subset_fields = list(set(subset_fields).intersection(set(full.data_vars)))
full_subset = full[valid_subset_fields]

full_subset = pump.calc_reduced_shear(
    full_subset.sel(depth=slice(0, -200))
    .sel(longitude=longitudes)
    .sel(time=tslice)
    .chunk({"longitude": 1, "latitude": -1, "time": 36})
    .assign_coords(
        period=period,
        tiw_phase=tiw_phase,
    )
)
# full_subset["uz"] = full_subset.u.differentiate("depth")
# full_subset["vz"] = full_subset.v.differentiate("depth")
# full_subset["S2"] = full_subset.uz ** 2 + full_subset.vz ** 2
# full_subset["N2"] = -9.81/1025 * full_subset.dens.differentiate("depth")
# full_subset["Ri"] = full_subset.N2 / full_subset.S2
full_subset["sst"] = surf.theta.sel(
    time=full_subset.time
)  # full_subset.theta.isel(depth=0)
# if "zeta" in surf:
#    full["ssvor"] = surf.zeta

euc_max = tao.euc_max.reset_coords(drop=True)
mld = pump.calc.get_mld(full_subset.dens)
dcl_base = pump.calc.get_dcl_base_Ri(full_subset, mld, euc_max)


full_subset = full_subset.assign_coords(mld=mld, dcl_base=dcl_base, eucmax=tao.euc_max)

single TIW period analysis#

Paritioning mixing within KPP interior & KPP BL#

Jq = xr.Dataset()
Jq["Total DCL"] = period4.Jq.where(period4.dcl_mask)
Jq["Within KPP BL"] = period4.Jq.where(
    period4.dcl_mask & (period4.depth > -period4.KPPhbl)
)
Jq["Below KPP BL"] = period4.Jq.where(
    period4.dcl_mask & (period4.depth <= -period4.KPPhbl)
)
Jq = Jq.isel(longitude=1).to_array().load()
(
    Jq.mean("depth").plot(
        col="variable", robust=True, x="time", **pump.plot.cmaps["Jq"], ylim=(-2, 5)
    )
)
<xarray.plot.facetgrid.FacetGrid at 0x2b559b58c820>
_images/56d4da3722c5d1b267a7677c56724ee8e44829155895a5e4ff6c41a050d87484.png
f, ax = plt.subplots(1, 1, constrained_layout=1)
(
    Jq.fillna(0)
    .integrate("time", datetime_unit="s")
    .integrate("depth")
    .plot.line(
        hue="variable",
        y="latitude",
        ylim=(-3, 5),
        xlim=(0, None),
        add_legend=False,
        ax=ax,
    )
)

ax.legend(Jq["variable"].values, loc="upper right")
ax.grid(True, which="both")
ax.xaxis.set_minor_locator(mpl.ticker.AutoMinorLocator(3))
ax.set_xlabel("$∫dt∫dz$ $J_q$ [J/m]")
ax.set_title("Parameterized heat flux \nin low Ri layer at 110°W")

f.set_size_inches((dcpy.plots.pub_fig_width("jpo", "single column"), 4))

f.savefig("images/kpp-deep-cycle-bl-int-heat-flux.png")
_images/cc2e30a9c629041b60e4ec7f592ed1097e11e5d2d863515dba9ce5968768bf72.png

Reduced shear analysis#

pump.plot.plot_tiw_period_snapshots(
    full_subset,
    lon=-110,
    period=4,
    times=[
        "1995-11-18 00:00",
        # "1995-11-24 18:00",
        "1995-11-26 06:00",
        "1995-12-03 18:00",
        # "1995-12-09 18:00",
    ],
)

plt.gcf().savefig("images/sst-dcl-shred2.png", dpi=150)
/glade/u/home/dcherian/python/xarray/xarray/core/resample.py:176: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, the dimension order of these coordinates will be restored as well unless you specify restore_coord_dims=False.
  super().__init__(*args, **kwargs)
_images/84f9af5134cf16f04fb49f39bc06449a484a90a3499f531a88a12f9bc861a2ef.png
shred2 = (
    (full_subset.uz**2 + full_subset.vz**2 - 1 / 0.4 * full_subset.N2).sel(
        time="1995-12-03 20:00", longitude=-110
    )
).compute()

are we seeing a deep cycle off the equator? Yes!#

Jq#

sub = full_subset.sel(longitude=-110, latitude=3.5, method="nearest").sel(
    time=slice("1995-11-29", "1995-12-05")
)

sub.Jq.rolling(depth=3, center=True).mean().plot(
    y="depth",
    cmap=mpl.cm.Blues_r,
    vmax=0,
    vmin=-400,
)
sub.mld.plot(color="orange", x="time")
sub.dcl_base.plot(color="k", x="time")
[<matplotlib.lines.Line2D at 0x2ba424ec7860>]
_images/6ea3c21a919cf7b1c4c026561372c437d1901aafe37a43e5c53969a04965e629.png

deep cycle summary#

Jq, N2, S2, Ri

ds = (
    full_subset[["Ri", "S2", "N2", "Jq"]]
    .sel(latitude=2, method="nearest")
    .sel(time=slice("1995-11-29", "1995-12-09"), depth=slice(-100))
    .assign_coords(latitude=2)
    .squeeze()
    .compute()
)
ds["Jq"] = ds.Jq.rolling(depth=2).mean()
del ds.time.attrs["long_name"]
ds.depth.attrs["units"] = "m"
ds.Jq.attrs["long_name"] = "$J^t_q$"
ds.Jq.attrs["units"] = "W/m²"
ds.S2.attrs["long_name"] = "$S²$"
ds.S2.attrs["units"] = "$s^{-2}$"
ds.Ri.attrs["long_name"] = "$Ri$"
ds.N2.attrs["long_name"] = "$N²$"
ds.N2.attrs["units"] = "$s^{-2}$"
f, axx = plt.subplots(4, 1, sharex=True, sharey=True, constrained_layout=True)
ax = dict(zip(["Ri", "S2", "N2", "Jq"], axx))

kwargs = {
    "S2": dict(cmap=mpl.cm.OrRd, norm=mpl.colors.LogNorm(1e-5, 1e-3)),
    "Jq": dict(
        cmap=mpl.cm.Blues_r,
        vmax=0,
        vmin=-400,
    ),
    "Ri": dict(cmap=mpl.cm.RdYlBu_r, center=0.5, norm=mpl.colors.LogNorm(0.25, 1)),
    "N2": dict(cmap=mpl.cm.GnBu, norm=mpl.colors.LogNorm(1e-6, 3e-4)),
}

for var in kwargs.keys():
    ds[var].plot(ax=ax[var], x="time", y="depth", **kwargs[var])


def plot(ax):
    ds.mld.plot(ax=ax, color="w", x="time", _labels=False, lw=2)
    ds.mld.plot(ax=ax, color="orange", x="time", _labels=False, lw=1)
    ds.dcl_base.plot(ax=ax, color="w", x="time", _labels=False, lw=2)
    ds.dcl_base.plot(ax=ax, color="k", x="time", _labels=False, lw=1)


[plot(aa) for aa in axx]
[aa.set_xlabel("") for aa in axx]
[aa.set_title("") for aa in axx[1:]]
[tt.set_rotation(0) for tt in axx[-1].get_xticklabels()]

f.set_size_inches((6, 6))

# f.savefig("images/110-deep-cycle-2.png")
_images/9f96818a964dc5cab1b55c2ee7d51a523f48880939149875d7a746a87bcc6a94.png

Deep cycle forcing: shear, velocity & vorticity#

subset = (
    full_subset[["u", "v"]].sel(
        longitude=-110,
        latitude=slice(-3, 6),
        time=(full_subset.period == 4).squeeze().reset_coords(drop=True),
    )
).compute()
ssta4 = (
    gcm1.surface.theta.sel(time=full_subset.time)
    .sel(
        longitude=slice(-140, -100),
        time=(full_subset.period == 4).squeeze().reset_coords(drop=True),
    )
    .pipe(lambda x: x - x.mean(["longitude", "time"]))
    .reset_coords(drop=True)
)
ssta4.isel(time=slice(None, None, 20)).plot(
    x="longitude", y="latitude", col="time", col_wrap=3, robust=True, aspect=2.5
)
<xarray.plot.facetgrid.FacetGrid at 0x2b3a768f65f8>
_images/750e220fe2aba289a29716a5c9531d1648915309e15e35f796789d5e73da5f51.png

propagation velocity from hovmoeller plots#

Using 0.5m/s barotropic shift in u works OK. This is inferred from SST, SSV plots.

SST#

fg = (
    ssta4.sel(longitude=slice(-120, -100))
    .sel(latitude=[0, 1, 2, 2.5, 3, 3.5, 4], method="nearest")
    .sortby("latitude", ascending=False)
    .plot(
        x="longitude",
        y="time",
        col="latitude",
        col_wrap=2,
        robust=True,
        aspect=3,
        cbar_kwargs={"orientation": "horizontal", "shrink": 0.6, "aspect": 40},
    )
)


[plot_reference(ax) for ax in fg.axes.flat]
fg.fig.suptitle("SST hovmoeller plots with -0.6, -0.5, -0.4 m/s slope lines", y=1.01)
Text(0.5, 1.01, 'SST hovmoeller plots with -0.6, -0.5, -0.4 m/s slope lines')
_images/7f2e0fb4d6e200d3ba23738b4abfa552cd7ba2d2e0c4723d23543b5cb9cf72e7.png

SSV#

ssv = (
    gcm1.surface.v.sel(time=full_subset.time)
    .sel(
        longitude=slice(-140, -100),
        time=(full_subset.period == 4).squeeze().reset_coords(drop=True),
    )
    .reset_coords(drop=True)
)
fg = (
    ssv.sel(longitude=slice(-120, -100))
    .sel(latitude=[0, 1, 2, 2.5, 3, 3.5, 4], method="nearest")
    .sortby("latitude", ascending=False)
    .plot(
        x="longitude",
        y="time",
        col="latitude",
        col_wrap=2,
        robust=True,
        aspect=3,
        cbar_kwargs={"orientation": "horizontal", "shrink": 0.6, "aspect": 40},
    )
)

[plot_reference(ax) for ax in fg.axes.flat]
fg.fig.suptitle("SSV hovmoeller plots with -0.6, -0.5, -0.4 m/s slope lines", y=1.01)
Text(0.5, 1.01, 'SSV hovmoeller plots with -0.6, -0.5, -0.4 m/s slope lines')
_images/735031d7acbad4e7b0f39ee8b6e70a7f90fe230ab8e114ec78c12fc6b13f0934.png

depth-averaged velocity?#

time4 = full_subset.time.where((full_subset.period == 4).squeeze().reset_coords(drop=True), drop=True)

fg = (
    gcm1.full.v
    .sel(depth=slice(-60))
    .mean("depth")
    .sel(longitude=slice(-120, -100), time=time4)
    .sel(latitude=[4, 3.5, 3, 2.5, 2, 1, 0], method="nearest")
    .plot(x="longitude", y="time", col="latitude", col_wrap=2, robust=True, aspect=3, 
          cbar_kwargs={"orientation": "horizontal", "shrink": 0.6, "aspect": 40})

)

[plot_reference(ax) for ax in fg.axes.flat]
fg.fig.suptitle("[0-60m] mean V hovmoeller plots with -0.6, -0.5, -0.4 m/s slope lines", y=1.01);;;;;;;;
_images/590150cfc6e5dc32be2bb6659bca92f908c98373a230e6cda454585b4e33ddc8.png

velocity in vortex-following frame#

Kennan & Flament find 0.35 m/s north of eq and 0.8m/s at eq. so there’s definitely some latitudinal structure

fg = quiver(
    (subset.assign(u=lambda x: x["u"] + 0.5))
    .sel(depth=[0, -30, -60, -90], method="nearest")
    .isel(latitude=slice(None, None, 5), time=slice(None, None, 6))
    .reset_coords(drop=True),
    row="depth",
    x="time",
    y="latitude",
    u="u",
    v="v",
    scale=10,
)

fg.fig.suptitle("Velocity vectors in \n -0.5m/s reference frame", y=1.03);;;;;;;;
_images/f92514589c558e33a08ac30d3aa5f5d0fe770a058d75f579d74bf1c63a87a04b.png
refvel = xr.concat(
    [
        subset.assign(u=lambda x: x["u"] + 0.4),
        subset.assign(u=lambda x: x["u"] + 0.5),
        subset.assign(u=lambda x: x["u"] + 0.6),
    ],
    dim=xr.Variable("uref", [-0.4, -0.5, -0.6]),
)
refvel
<xarray.Dataset>
Dimensions:    (depth: 200, latitude: 180, time: 143, uref: 3)
Coordinates:
    mld        (time, latitude) float32 -23.5 -24.5 -22.5 ... -35.5 -31.5 -28.5
    eucmax     (time) float64 -91.5 -88.5 -86.5 -85.5 ... -80.5 -78.5 -77.5
    tiw_phase  (time) float64 0.0 2.571 5.143 7.714 ... 350.3 352.7 355.1 357.6
    dcl_base   (time, latitude) float32 -48.5 -49.5 -47.5 ... -35.5 -31.5 -28.5
    longitude  int64 -110
    period     (time) float64 4.0 4.0 4.0 4.0 4.0 4.0 ... 4.0 4.0 4.0 4.0 4.0
  * time       (time) datetime64[ns] 1995-11-16T16:00:00 ... 1995-12-10T08:00:00
  * latitude   (latitude) float32 -2.981211 -2.9311066 ... 5.9373693 5.987474
  * depth      (depth) float32 -0.5 -1.5 -2.5 -3.5 ... -197.5 -198.5 -199.5
  * uref       (uref) float64 -0.4 -0.5 -0.6
Data variables:
    u          (uref, time, depth, latitude) float32 0.1987586 ... 0.64383435
    v          (uref, time, depth, latitude) float32 -0.06828315 ... -0.027467424
Attributes:
    easting:            longitude
    field_julian_date:  400296
    julian_day_unit:    days since 1950-01-01 00:00:00
    northing:           latitude
    title:              daily snapshot from 1/20 degree Equatorial Pacific MI...
fg = quiver(
    refvel.sel(depth=slice(-60)).mean("depth")
    .isel(latitude=slice(None, None, 5), time=slice(None, None, 6))
    .reset_coords(drop=True),
    col="uref",
    x="time",
    y="latitude",
    u="u",
    v="v",
    scale=10,
)

fg.fig.suptitle("[0-60m] avg. velocity vectors in reference frame", y=1.03);
[dcpy.plots.concise_date_formatter(aa) for aa in fg.axes.flat]
[[aa.set_xlabel("") for aa in fg.axes.flat]];;;;;;;;
[[Text(0.5, 5.811111111111111, ''),
  Text(0.5, 5.811111111111111, ''),
  Text(0.5, 5.811111111111111, '')]]
_images/b3d77f907e0ab6fd573bcb55aaa1aee70f020a692b88a4a3e0294ba1923bce6c.png

bandpass filtering#

Not sure this does what i want.

Let’s try bandpass filtering in time. This will be wrong at the front but sensible behind it?

vel = (
    full_subset[["u", "v"]]
    .squeeze()
    .sel(depth=[0, -30, -60, -90], method="nearest")
    .chunk({"time": -1, "depth": 1})
)
tiw_filter = lambda x: xfilter.bandpass(
    x, coord="time", freq=[1 / 20.0, 1 / 40.0], cycles_per="D", num_discard=0
)
filtered = vel.map(tiw_filter)
/glade/u/home/dcherian/python/xfilter/xfilter/xfilter.py:152: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  data = data.copy().transpose(..., coord)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/missing.py:410: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  ).transpose(*arr.dims)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/missing.py:427: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  ).transpose(*arr.dims)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/missing.py:346: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  ).transpose(*self.dims)
/glade/u/home/dcherian/python/xfilter/xfilter/xfilter.py:152: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  data = data.copy().transpose(..., coord)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/missing.py:410: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  ).transpose(*arr.dims)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/missing.py:427: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  ).transpose(*arr.dims)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/missing.py:346: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, these coordinates will be transposed as well unless you specify transpose_coords=False.
  ).transpose(*self.dims)
merged = xr.concat(
    [vel, filtered.reset_coords(drop=True)],
    dim=xr.Variable("kind", ["unfiltered", "filtered"]),
    coords="minimal",
)
merged_subset = (
    merged.sel(
        time=merged.time.where(filtered.period == 4, drop=True), latitude=slice(-3, 6)
    )
    .isel(latitude=slice(None, None, 5), time=slice(None, None, 5))
    .compute()
)
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-171-5c50a822dbc5>", line 8, in <module>
    .sel(time=merged.time.where(filtered.period == 4, drop=True), latitude=slice(-3, 6))
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/common.py", line 1141, in where
    nonzeros = zip(clipcond.dims, np.nonzero(clipcond.values))
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/dataarray.py", line 557, in values
    return self.variable.values
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/variable.py", line 451, in values
    return _as_array_or_item(self._data)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/variable.py", line 254, in _as_array_or_item
    data = np.asarray(data)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/dask/array/core.py", line 1342, in __array__
    x = self.compute()
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/dask/base.py", line 166, in compute
    (result,) = compute(self, traverse=False, **kwargs)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/dask/base.py", line 437, in compute
    results = schedule(dsk, keys, **kwargs)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/distributed/client.py", line 2595, in get
    results = self.gather(packed, asynchronous=asynchronous, direct=direct)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/distributed/client.py", line 1893, in gather
    asynchronous=asynchronous,
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/distributed/client.py", line 780, in sync
    self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/distributed/utils.py", line 345, in sync
    e.wait(10)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/threading.py", line 551, in wait
    signaled = self._cond.wait(timeout)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/threading.py", line 299, in wait
    gotit = waiter.acquire(True, timeout)
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2044, in showtraceback
    stb = value._render_traceback_()
AttributeError: 'KeyboardInterrupt' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/IPython/core/ultratb.py", line 1148, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/IPython/core/ultratb.py", line 316, in wrapped
    return f(*args, **kwargs)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/IPython/core/ultratb.py", line 350, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/inspect.py", line 1490, in getinnerframes
    frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/inspect.py", line 1452, in getframeinfo
    lines, lnum = findsource(frame)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/IPython/core/ultratb.py", line 182, in findsource
    lines = linecache.getlines(file, globals_dict)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/linecache.py", line 47, in getlines
    return updatecache(filename, module_globals)
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/linecache.py", line 136, in updatecache
    with tokenize.open(fullname) as fp:
  File "/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/tokenize.py", line 452, in open
    buffer = _builtin_open(filename, 'rb')
KeyboardInterrupt
---------------------------------------------------------------------------
quiver(
    merged_subset,
    x="time",
    y="latitude",
    u="u",
    v="v",
    row="depth",
    col="kind",
    scale=8,
)
quiver(
    subset.sel(depth=[0, -30, -60, -90], method="nearest")
    .isel(latitude=slice(None, None, 5), time=slice(None, None, 6))
    .reset_coords(drop=True),
    row="depth",
    x="time",
    y="latitude",
    u="u",
    v="v",
)
dcl = (
    (subset.mld - subset.dcl_base)
    .resample(time="D")
    .mean()
    .rolling(latitude=6)
    .mean()
    .compute()
)
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/resample.py:176: FutureWarning: This DataArray contains multi-dimensional coordinates. In the future, the dimension order of these coordinates will be restored as well unless you specify restore_coord_dims=False.
  super().__init__(*args, **kwargs)
shears = subset.differentiate("depth").to_array("shear").reset_coords(drop=True)
shears.name = "shear"
shears.attrs["units"] = "1/s"

fg = shears.sel(depth=[-30, -45, -60, -75, -90], method="nearest").plot(
    col="depth",
    row="shear",
    x="time",
    y="latitude",
    robust=True,
    cbar_kwargs={"orientation": "horizontal", "pad": 0.2, "shrink": 0.8, "aspect": 40},
)


def plot():
    dcl.plot.contour(
        levels=7, colors="k", robust=True, x="time", add_labels=False, linewidths=1
    )


fg.map(plot)
fg.set_xlabels("")
fg.fig.set_size_inches((10, 8))
_images/ff75932de3c1d1116b51b3f89abb630db777548c83a5bd0b59afaf920a115339.png
times = pd.to_datetime(["1995-11-18 00:00", "1995-11-26 04:00", "1995-12-03 16:00"])

shears.sel(time=times).sel(depth=slice(-100)).plot(col="time", row="shear", robust=True)
full_subset[["u", "v"]].to_array("vel").sel(
    time=times, latitude=slice(-3, 6), depth=slice(-100)
).plot(col="time", row="vel", robust=True)
<xarray.plot.facetgrid.FacetGrid at 0x2abce7ac7128>
_images/c766a157c10248ce5927aa8d145232b44f6ea50461e067016f0cb3260e0eb147.png _images/0e45a6d6382d0c9dfa83e517192873724e685700ad3153ee89c71b9156f4e678.png
fg = shears.sel(depth=slice(-60)).mean("depth").plot(col="shear", x="time", robust=True)


def plot():
    dcl.plot.contour(
        levels=7, colors="k", robust=True, x="time", add_labels=False, linewidths=1
    )


fg.map(plot)
<xarray.plot.facetgrid.FacetGrid at 0x2abc7cd550f0>
_images/473034b12dc81a93766e766ca8c84e6fb677ff4286b131017240e230a1fc290f.png

shear evolution#

\begin{align} D_t u_z &= u_z v_y + (f - u_y) v_z - b_x + ∂_z F_x \ D_t v_z &= v_z u_x - (f + v_x) u_z - b_y + ∂_z F_y \end{align}

ilon = gcmfull.full.indexes["longitude"].get_loc(-110, method="nearest")
time_subset = gcmfull.time.where(full_subset.period.squeeze() == 4, drop=True).values
ds = gcmfull.full.isel(longitude=[ilon - 1, ilon, ilon + 1]).sel(
    time=time_subset, depth=slice(-200)
)
# ds = dcpy.dask.map_copy(ds)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-d89d001597c4> in <module>
----> 1 ilon = gcmfull.full.indexes["longitude"].get_loc(-110, method="nearest")
      2 time_subset = gcmfull.time.where(full_subset.period.squeeze() == 4, drop=True).values
      3 ds = gcmfull.full.isel(longitude=[ilon-1, ilon, ilon+1]).sel(time=time_subset, depth=slice(-200))
      4 # ds = dcpy.dask.map_copy(ds)

NameError: name 'gcmfull' is not defined
ds.to_netcdf("/glade/scratch/dcherian/TPOS_MITgcm_1_hb/110w-period-4.nc")
from pump.calc import ddx, ddy
from pump.plot import plot_shear_terms

ds = xr.open_dataset("/glade/scratch/dcherian/TPOS_MITgcm_1_hb/110w-period-4.nc")
duzdt, dvzdt = dask.compute(pump.calc.estimate_shear_evolution_terms(ds))

Tilting of the vertical vortex tube is what changes both components of shear so lets look at that

f = dcpy.oceans.coriolis(ds.latitude)

vvort = xr.Dataset()
vvort["zeta"] = ddx(ds.v) - ddy(ds.u)
vvort["vx"] = ddx(ds.v)
vvort["uy"] = ddy(ds.u)
vvort["xcomp"] = f - vvort.uy
vvort["ycomp"] = f + vvort.vx
vvort = vvort.isel(longitude=1).load()
(vvort[["vx", "uy"]].to_array("vort") / np.abs(f)).sel(
    latitude=slice(-3, 6), depth=slice(-60)
).mean("depth").plot(
    col="vort",
    x="time",
    vmin=-1,
    vmax=1,
    cmap=mpl.cm.RdBu_r,
    cbar_kwargs={"label": "vx/|f|; uy/|f|"},
)
<xarray.plot.facetgrid.FacetGrid at 0x2ba563a03cf8>
_images/4fad293efd6209e243cd2f2ec5387f912fc22018d972faa102de1c7804bdbad4.png
(f + vvort.zeta).isel(depth=1).sel(latitude=slice(-3, 6)).plot(x="time", robust=True)
<matplotlib.collections.QuadMesh at 0x2b16b6c32fd0>
_images/70fe3b755f0c83b4cbd29073dcdee6fb1cdc861b457ee9d1f46858024af4a5d9.png
vvort[["xcomp", "ycomp"]].sel(depth=slice(-60), latitude=slice(-3, 6)).mean(
    "depth"
).to_array("comp").plot(col="comp", robust=True)
<xarray.plot.facetgrid.FacetGrid at 0x2b3cb8ec62e8>
_images/f7150e6164f36d94acd2fbf948a37b39ed177e9d284d7900ca76a6718118c7ec.png

depth slices shear evolution terms#

large advection at the surface

plot_shear_terms(duzdt.sel(depth=[-20, -40, -60], method="nearest"), dcl)
plot_shear_terms(dvzdt.sel(depth=[-20, -40, -60], method="nearest"), dcl)
_images/b444ebb1ed747fa14ac6d58bb0f07ca09b0e1e378ed778e10db41d701e559ac0.png _images/24d06993dcf692b9037a90dab73360998a6aadba4873329c6d666509465b73ff.png

depth averaged shear evolution terms#

plot_shear_terms(duzdt.sel(depth=slice(-60)).mean("depth", keep_attrs=True), dcl)
plot_shear_terms(dvzdt.sel(depth=slice(-60)).mean("depth", keep_attrs=True), dcl)
_images/42835cf21f952081cd5cc7669450bd22bb89b70c502b0531ba66379403069fd3.png _images/45be9c59b690acf5ca429ef2670cf3e04d6358d686990b43ba0ef9aa0d834a6d.png
plot_shear_terms(duzdt.sel(depth=slice(-90)).mean("depth", keep_attrs=True))
plot_shear_terms(dvzdt.sel(depth=slice(-90)).mean("depth", keep_attrs=True))
_images/27e32d8f4075eff4427d4d33405876a159522880cae679a4183223bd80281045.png _images/22ee2b3ed7eaaa96129fde6b52f0b723e60ee32f85e57b045e11ede10effd5d5.png

vertical and horizontal vorticity#

\[ \hat{ω} = [(w_y - v_z), (u_z - w_x), (v_x - u_y)] \]
vort = xr.Dataset()
vort["x"] = ddy(ds.w) - ds.v.differentiate("depth")
vort["y"] = ds.u.differentiate("depth") - ddx(ds.w)
vort["z"] = ddx(ds.v) - ddy(ds.u)
vort["vx"] = ddx(ds.v)
vort["uy"] = ddy(ds.u)
vort = vort.isel(longitude=1).load()
subset = (
    vort.sel(depth=(-20, -40, -60), method="nearest")
    .sel(latitude=slice(-2, 5))
    .isel(latitude=slice(None, None, 5), time=slice(None, None, 5))
)

fg = quiver(
    subset,
    u="x",
    v="y",
    x="time",
    y="latitude",
    col="depth",
    scale=0.4,
)


uvsub = (
    ds.isel(longitude=1)[["u", "v"]]
    # .differentiate("depth")
    .sel(latitude=slice(-2, 5)).isel(
        latitude=slice(None, None, 6), time=slice(None, None, 6)
    )
).load()

for loc, ax in zip(fg.name_dicts.flat, fg.axes.flat):
    quiver(
        uvsub.sel(loc).load(),
        u="u",
        v="v",
        x="time",
        y="latitude",
        scale=10,
        ax=ax,
        color="r",
    )
_images/9043d3d308832ad42f5b189be6bfa911841b053bfbb3b862f3bf4fa47b99c798.png
subset = vort.sel(depth=(-20, -40, -60), method="nearest").sel(latitude=slice(-2, 5))

fg = subset.z.sel(depth=(-20, -40, -60), method="nearest").plot(
    x="time", col="depth", vmax=2.5e-5, cbar_kwargs={"label": "vertical vorticity"}
)
subset.time.attrs["name"] = ""

for loc, ax in zip(fg.name_dicts.flat, fg.axes.flat):
    quiver(
        subset.isel(latitude=slice(None, None, 5), time=slice(None, None, 5))
        .sel(loc)
        .load(),
        u="x",
        v="y",
        x="time",
        y="latitude",
        scale=0.3,
        ax=ax,
        color="k",
    )

fg.set_xlabels("")
fg.fig.suptitle(
    "Horizontal vortex vectors[$ω_xi + ω_yj$] over vertical vorticity [color]", y=1.03
)
plt.gcf().savefig("images/110-period-4-horizontal-vertical-vorticity-depth.png")
_images/28d0cc55cbb16450228ef2232ccf46c025c3ff46afae24e294b8faaebe81590c.png
subset = vort.sel(latitude=slice(-2, 6), depth=slice(0, -60)).mean("depth")
f0 = f.reindex_like(subset.z)

subset.z.attrs["long_name"] = "vert vorticity"
((f0 + subset.vx - subset.uy)).plot(x="time", vmax=3e-5)
(
    ds.theta.isel(depth=0, longitude=1)
    .resample(time="D")
    .mean()
    .plot.contour(x="time", colors="k", levels=[23.8], zorder=2, add_labels=False)
)
quiver(
    subset.isel(latitude=slice(None, None, 4), time=slice(None, None, 4)),
    u="x",
    v="y",
    x="time",
    y="latitude",
    scale=0.3,
)

quiver(
    ds.sel(depth=-30, method="nearest").isel(
        longitude=1, latitude=slice(None, None, 4), time=slice(None, None, 6)
    ),
    u="u",
    v="v",
    x="time",
    y="latitude",
    color="darkgreen",
    scale=12,
)


plt.gcf().suptitle(
    "Horizontal vorticity vectors over ($f+v_x - u_y$) [color].\n Depth average to 60m",
    y=1.05,
)

# plt.gcf().savefig("images/110-period-4-horizontal-vertical-vorticity.png")
Text(0.5, 1.05, 'Horizontal vorticity vectors over ($f+v_x - u_y$) [color].\n Depth average to 60m')
_images/bc062365ca1eef5fa76fa7dea5598ac9077a763e41abffbd5e108fc6e4519b0c.png
quiver(subset, x="time", y="latitude", u="u", v="v", scale=10)
subset = (
    ds.isel(longitude=1)
    .sel(
        latitude=slice(
            -2,
            6,
        ),
        depth=slice(-20, -60),
    )
    .isel(latitude=slice(0, -1, 2))
    .mean("depth")
    .resample(time="D")
    .mean()
)

t = (subset.time - subset.time[0]).values.astype("timedelta64[s]").astype("float32")

x = t * 1200e3 / 25 / 86400

y = subset.latitude  # np.linspace(-2, 6, 100)

start_points = [x[-4] * np.ones_like(y), y]
start_points = np.stack(start_points).T

plt.streamplot(
    x,
    y,
    subset.u.transpose().values,
    subset.v.transpose().values,
    integration_direction="forward",
    start_points=start_points,
)

older plots#

plot_shear_terms(duzdt.sel(depth=[-25, -50, -75], method="nearest"))
_images/248f4a54ed741efd8acd9523c3861d807d3d71643ef644e1a1ea17378674e415.png
plot_shear_terms(dvzdt.sel(depth=[-25, -50, -75], method="nearest"))
_images/e1df9347fec4698e14281fe2abf431d2100536a87bbce587b9ddfec479194506.png

particle tracking#

from datetime import timedelta as delta

import numpy as np
import xarray as xr

from parcels import (
    AdvectionRK4,
    FieldSet,
    JITParticle,
    ParticleSet,
    plotTrajectoriesFile,
)
variables = {"U": "u", "V": "v"}
dimensions = {"lon": "longitude", "lat": "latitude", "time": "time"}
fset = FieldSet.from_xarray_dataset(gcm1.surface, variables, dimensions)
# fset.add_periodic_halo(zonal=True, meridional=False, halosize=2)

fset
WARNING: Casting depth data to np.float32
WARNING:parcels.tools.loggers:Casting depth data to np.float32
<parcels.fieldset.FieldSet at 0x2b3a5b619b70>
lons, lats = np.meshgrid(np.arange(-120.0, -105.0, 0.2), np.arange(-2, 8, 0.5))
pset = ParticleSet(fset, JITParticle, lon=lons, lat=lats)
ofile = pset.ParticleFile("particles.nc", outputdt=delta(hours=1))
kernel =
def beach(particle, fieldset, time):
    if particle.lon > -96:
        particle.lon = -96
gcm1.surface
<xarray.Dataset>
Dimensions:          (latitude: 480, longitude: 1500, time: 2947)
Coordinates:
  * latitude         (latitude) float32 -12.0 -11.949896 ... 11.949896 12.0
    depth            float32 ...
  * longitude        (longitude) float32 -170.0 -169.94997 ... -95.05003 -95.0
  * time             (time) datetime64[ns] 1995-09-01 ... 1997-01-04T12:00:00
Data variables:
    theta            (time, latitude, longitude) float32 dask.array<chunksize=(227, 480, 116), meta=np.ndarray>
    u                (time, latitude, longitude) float32 dask.array<chunksize=(227, 480, 116), meta=np.ndarray>
    v                (time, latitude, longitude) float32 dask.array<chunksize=(227, 480, 116), meta=np.ndarray>
    w                (time, latitude, longitude) float32 dask.array<chunksize=(227, 480, 116), meta=np.ndarray>
    salt             (time, latitude, longitude) float32 dask.array<chunksize=(227, 480, 116), meta=np.ndarray>
    KPP_diffusivity  (time, latitude, longitude) float32 dask.array<chunksize=(227, 480, 116), meta=np.ndarray>
    zeta             (time, latitude, longitude) float32 ...
Attributes:
    title:              daily snapshot from 1/20 degree Equatorial Pacific MI...
    easting:            longitude
    northing:           latitude
    field_julian_date:  400296
    julian_day_unit:    days since 1950-01-01 00:00:00
# %%time

# Advect ParticleSet with RK4 and periodic Boundary conditions
pset.execute(
    pset.Kernel(AdvectionRK4) + pset.Kernel(beach),
    runtime=delta(days=60),
    dt=delta(minutes=30),
    output_file=ofile,
)
INFO: Compiled JITParticleAdvectionRK4beach ==> /glade/scratch/dcherian/parcels-25721/3d4cb8c8bf1b028586a64d8cc3f66cce_0.so
INFO:parcels.tools.loggers:Compiled JITParticleAdvectionRK4beach ==> /glade/scratch/dcherian/parcels-25721/3d4cb8c8bf1b028586a64d8cc3f66cce_0.so
INFO: Temporary output files are stored in out-NQNDSGCQ.
INFO:parcels.tools.loggers:Temporary output files are stored in out-NQNDSGCQ.
INFO: You can use "parcels_convert_npydir_to_netcdf out-NQNDSGCQ" to convert these to a NetCDF file during the run.
INFO:parcels.tools.loggers:You can use "parcels_convert_npydir_to_netcdf out-NQNDSGCQ" to convert these to a NetCDF file during the run.
100% (5184000.0 of 5184000.0) |##########| Elapsed Time: 0:01:12 Time:  0:01:12
ds = xr.open_dataset("particles.nc").set_coords(["time"])
ds["time"] = ds.time.isel(traj=0, drop=True)
ds = ds.rename({"obs": "time"})
ds["trajectory"] = ds.trajectory.isel(time=0)
ds = ds.rename({"trajectory": "traj"})
ds = ds.set_coords("traj")
ds
<xarray.Dataset>
Dimensions:  (time: 241, traj: 2000)
Coordinates:
  * traj     (traj) float64 0.0 1.0 2.0 3.0 ... 1.997e+03 1.998e+03 1.999e+03
  * time     (time) datetime64[ns] 1995-09-01 1995-09-01T01:00:00 ... 1995-09-11
Data variables:
    lat      (traj, time) float32 ...
    lon      (traj, time) float32 ...
    z        (traj, time) float32 ...
Attributes:
    feature_type:           trajectory
    Conventions:            CF-1.6/CF-1.7
    ncei_template_version:  NCEI_NetCDF_Trajectory_Template_v2.0
    parcels_version:        2.1.4
    parcels_mesh:           spherical
ds.sel(traj=slice(None, None, 10)).plot.scatter(x="lon", y="lat", s=0.05)
<matplotlib.collections.PathCollection at 0x2b3a52b15588>
_images/60974de6884409f86f7f56f683d7486fb3d6d5f1e0997b854fc153af94c13660.png

Read new hourly output#

dirname = "/glade/campaign/cgd/oce/people/dcherian/TPOS_MITgcm_1_hb/HOLD"
metrics = pump.model.read_metrics(f"{dirname}/../")
ds = xr.open_mfdataset(f"{dirname}/File_*.nc", parallel=True)
# RAC = xr.align(metrics.RAC, ds, join="right")[0].chunk(
#    {k: v for k, v in ds.chunks.items() if k in ["latitude", "longitude"]}
# )
# ds["Jq"] = 1035 * 3994 * (ds.DFrI_TH + ds.KPPg_TH) / RAC
ds
<xarray.Dataset>
Dimensions:    (depth: 280, latitude: 400, longitude: 1420, time: 779)
Coordinates:
  * latitude   (latitude) float32 -10.0 -9.95 -9.9 -9.85 ... 9.85 9.9 9.95 10.0
  * longitude  (longitude) float32 -168.0 -167.9 -167.9 ... -97.1 -97.05 -97.0
  * depth      (depth) float32 -0.5 -1.5 -2.5 -3.5 ... -378.4 -391.7 -406.3
  * time       (time) datetime64[ns] 1995-11-15 ... 1995-12-17T10:00:00
Data variables:
    DFrI_TH    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    VISrI_Um   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    VISrI_Vm   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    Um_Diss    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    Vm_Diss    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    ETAN       (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 1420), meta=np.ndarray>
    KPPviscA   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    KPPdiffT   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    KPPRi      (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    KPPg_TH    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    KPPhbl     (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 1420), meta=np.ndarray>
    KPPbo      (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 1420), meta=np.ndarray>
    theta      (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    u          (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    v          (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    w          (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
    salt       (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 280, 400, 1420), meta=np.ndarray>
Attributes:
    title:              daily snapshot from 1/20 degree Equatorial Pacific MI...
    easting:            longitude
    northing:           latitude
    field_julian_date:  400296
    julian_day_unit:    days since 1950-01-01 00:00:00
idx = ds.indexes["longitude"].get_loc(-110, method="nearest")
period4 = dcpy.dask.map_copy(
    ds.isel(longitude=[idx - 1, idx, idx + 1]).sel(depth=slice(-200))
)
period4.to_zarr(
    "/glade/work/dcherian/pump/zarrs/110w-period-4-3.zarr",
    consolidated=True,
    mode="w",
)
<xarray.backends.zarr.ZarrStore at 0x2b629541f040>
RAC = metrics.RAC.reindex(
    longitude=period4.longitude, latitude=period4.latitude, method="nearest"
)  # .isel(longitude=[idx - 1, idx, idx + 1])
period4 = xr.open_zarr(
    "/glade/work/dcherian/pump/zarrs/110w-period-4-3.zarr", consolidated=True
)
period4["Jq"] = 1035 * 3994 * (period4.DFrI_TH + period4.KPPg_TH.fillna(0)) / RAC
period4["time"] = period4["time"] - pd.Timedelta("7h")
period4["dens"] = pump.mdjwf.dens(period4.salt, period4.theta, np.array([0.0]))
period4 = pump.calc.calc_reduced_shear(period4)
period4["mld"] = pump.calc.get_mld(period4.dens)
period4["dcl_base"] = pump.calc.get_dcl_base_Ri(period4)
period4["dcl"] = period4["mld"] - period4["dcl_base"]
period4["sst"] = period4.theta.isel(depth=0)
period4["eucmax"] = pump.calc.get_euc_max(
    period4.u.sel(latitude=0, method="nearest", drop=True)
)
period4.depth.attrs["units"] = "m"
period4.Jq.attrs["long_name"] = "$J^t_q$"
period4.Jq.attrs["units"] = "W/m²"
period4.S2.attrs["long_name"] = "$S²$"
period4.S2.attrs["units"] = "$s^{-2}$"
period4.Ri.attrs["long_name"] = "$Ri$"
period4.N2.attrs["long_name"] = "$N²$"
period4.N2.attrs["units"] = "$s^{-2}$"
period4
calc uz
calc vz
calc S2
calc N2
calc shred2
Calc Ri
<xarray.Dataset>
Dimensions:    (depth: 200, latitude: 400, longitude: 3, time: 779)
Coordinates:
  * depth      (depth) float32 -0.5 -1.5 -2.5 -3.5 ... -197.5 -198.5 -199.5
  * latitude   (latitude) float32 -10.0 -9.95 -9.9 -9.85 ... 9.85 9.9 9.95 10.0
  * longitude  (longitude) float64 -110.1 -110.0 -110.0
  * time       (time) datetime64[ns] 1995-11-14T17:00:00 ... 1995-12-17T03:00:00
Data variables:
    DFrI_TH    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    ETAN       (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    KPPRi      (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    KPPbo      (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    KPPdiffT   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    KPPg_TH    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    KPPhbl     (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    KPPviscA   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    Um_Diss    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    VISrI_Um   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    VISrI_Vm   (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    Vm_Diss    (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    salt       (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    theta      (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    u          (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    v          (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    w          (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    Jq         (time, depth, latitude, longitude) float64 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    dens       (time, depth, latitude, longitude) float64 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    uz         (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    vz         (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    S2         (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    shear      (time, depth, latitude, longitude) float32 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    N2         (time, depth, latitude, longitude) float64 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    shred2     (time, depth, latitude, longitude) float64 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    Ri         (time, depth, latitude, longitude) float64 dask.array<chunksize=(1, 200, 400, 3), meta=np.ndarray>
    mld        (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    dcl_base   (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    dcl        (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    sst        (time, latitude, longitude) float32 dask.array<chunksize=(1, 400, 3), meta=np.ndarray>
    eucmax     (time, longitude) float64 -96.5 -97.5 -97.5 ... -99.5 -99.5 -99.5
Attributes:
    easting:            longitude
    field_julian_date:  400296
    julian_day_unit:    days since 1950-01-01 00:00:00
    northing:           latitude
    title:              daily snapshot from 1/20 degree Equatorial Pacific MI...
period4.to_zarr(
    "/glade/work/dcherian/pump/zarrs/110w-period-4-4.zarr",
    consolidated=True,
    mode="w",
)
period4.Jq.isel(longitude=1).sel(latitude=0, method="nearest").plot(
    x="time", robust=True
)
<matplotlib.collections.QuadMesh at 0x2b5715c4e810>
_images/d9a72511c037f61f0339a0b399090339b92b52257e727134b72493ff71e1e964.png

Time series of shear#

subset = (
    period4.isel(longitude=1)
    .sel(latitude=3.5, method="nearest")
    .sel(depth=slice(-60))
    .mean("depth")
)


subset.uz.plot()
subset.vz.plot()
subset.sst.plot(ax=plt.gca().twinx(), color="C2")
plt.figure()
subset.N2.plot()
[<matplotlib.lines.Line2D at 0x2ae91f212310>]
_images/11a5182060c87f3c05726afffde0816ec8215077da19fb4e31651adf957a6b86.png _images/df6e3ffe7bb194b5029b01d337b8c40aab400c242b1beb75f2c1f84aeb6cb973.png

older attempts#

oni = pump.obs.process_oni().sel(time=slice("1996", None))
oni.plot()
oni = oni.where(oni.time.dt.month.isin([9, 10, 11, 12]))
yearly = oni.resample(time="Y", loffset="-6M").mean()
yearly.plot()
x
subset = yearly.where((yearly < -0.25) & (yearly > (-0.65)), drop=True)
subset.plot(marker="o", ls="none")
print(subset.time.dt.year)

neutral_years = subset.time.dt.year.values
ny = list(set(neutral_years) - set([2008]))
/glade/u/home/dcherian/pump/pump/obs.py:354: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support skipfooter; you can avoid this warning by specifying engine='python'.
  )
/glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/core/nanops.py:142: RuntimeWarning: Mean of empty slice
  return np.nanmean(a, axis=axis, dtype=dtype)
<xarray.DataArray 'year' (time: 5)>
array([1996, 2001, 2005, 2008, 2013])
Coordinates:
  * time     (time) datetime64[ns] 1996-06-30 2001-06-30 ... 2013-06-30
_images/15578d68967ce34b4ec9b22ff2887a51d80450c4ae067580eba51cdc9fdaddd9.png
tao.sel(longitude=-110, time="1996").T.plot(x="time")
<matplotlib.collections.QuadMesh at 0x2b2a8ba57ed0>
_images/3bfaa299e6fb37eb1a1fb37c7e22dddae81ad6d6fe09204e49b20eadcbc63f70.png
# meantao = tao.sel(longitude=-110, time=slice("1990", "2000")).resample(time="D").mean()
# meantao = meantao.where(meantao.time.dt.year.isin([1996, 2001, 2013]), drop=True).resample(time="Y").mean()
meantao = (
    tao.sel(longitude=-110, time="1996")
    # .where(tao.time.dt.year.isin([1996]), drop=True)
    # .groupby("time.year")
    # .mean()
    .mean("time")
)
meantao
<xarray.Dataset>
Dimensions:    (depth: 101)
Coordinates:
  * depth      (depth) float64 -500.0 -495.0 -490.0 -485.0 ... -10.0 -5.0 0.0
    latitude   float32 ...
    longitude  float32 -110.0
Data variables:
    T          (depth) float64 dask.array<chunksize=(101,), meta=np.ndarray>
    u          (depth) float32 dask.array<chunksize=(101,), meta=np.ndarray>
    v          (depth) float32 dask.array<chunksize=(101,), meta=np.ndarray>
    dens       (depth) float64 dask.array<chunksize=(101,), meta=np.ndarray>
import xrft

daily = (
    tao.sel(longitude=-140)
    .resample(time="D")
    .mean()
    .where(
        tao.time.dt.year.isin(ny) & tao.time.dt.month.isin([9, 10, 11, 12]), drop=True
    )
)
daily
Show/Hide data repr Show/Hide attributes
xarray.Dataset
    • depth: 101
    • time: 488
    • time
      (time)
      datetime64[ns]
      1996-09-01 ... 2013-12-31
      array(['1996-09-01T00:00:00.000000000', '1996-09-02T00:00:00.000000000',
             '1996-09-03T00:00:00.000000000', ..., '2013-12-29T00:00:00.000000000',
             '2013-12-30T00:00:00.000000000', '2013-12-31T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • longitude
      ()
      float32
      -140.0
      FORTRAN_format :
      epic_code :
      502
      type :
      EVEN
      units :
      degree_east
      array(-140., dtype=float32)
    • latitude
      ()
      float32
      0.0
      FORTRAN_format :
      epic_code :
      500
      type :
      EVEN
      units :
      degree_north
      array(0., dtype=float32)
    • depth
      (depth)
      float64
      -500.0 -495.0 -490.0 ... -5.0 0.0
      array([-500., -495., -490., -485., -480., -475., -470., -465., -460., -455.,
             -450., -445., -440., -435., -430., -425., -420., -415., -410., -405.,
             -400., -395., -390., -385., -380., -375., -370., -365., -360., -355.,
             -350., -345., -340., -335., -330., -325., -320., -315., -310., -305.,
             -300., -295., -290., -285., -280., -275., -270., -265., -260., -255.,
             -250., -245., -240., -235., -230., -225., -220., -215., -210., -205.,
             -200., -195., -190., -185., -180., -175., -170., -165., -160., -155.,
             -150., -145., -140., -135., -130., -125., -120., -115., -110., -105.,
             -100.,  -95.,  -90.,  -85.,  -80.,  -75.,  -70.,  -65.,  -60.,  -55.,
              -50.,  -45.,  -40.,  -35.,  -30.,  -25.,  -20.,  -15.,  -10.,   -5.,
                0.])
    • T
      (time, depth)
      float64
      dask.array<chunksize=(1, 101), meta=np.ndarray>
      Array Chunk
      Bytes 394.30 kB 808 B
      Shape (488, 101) (1, 101)
      Count 76730 Tasks 488 Chunks
      Type float64 numpy.ndarray
      101 488
    • u
      (time, depth)
      float32
      dask.array<chunksize=(1, 101), meta=np.ndarray>
      Array Chunk
      Bytes 197.15 kB 404 B
      Shape (488, 101) (1, 101)
      Count 76730 Tasks 488 Chunks
      Type float32 numpy.ndarray
      101 488
    • v
      (time, depth)
      float32
      dask.array<chunksize=(1, 101), meta=np.ndarray>
      Array Chunk
      Bytes 197.15 kB 404 B
      Shape (488, 101) (1, 101)
      Count 76730 Tasks 488 Chunks
      Type float32 numpy.ndarray
      101 488
    • dens
      (time, depth)
      float64
      dask.array<chunksize=(1, 101), meta=np.ndarray>
      Array Chunk
      Bytes 394.30 kB 808 B
      Shape (488, 101) (1, 101)
      Count 89182 Tasks 488 Chunks
      Type float64 numpy.ndarray
      101 488
ind = pd.MultiIndex.from_arrays([daily.time.dt.year, daily.time.dt.dayofyear])
daily = daily.assign_coords(time=ind)
reshaped = daily.unstack("time")
reshaped
Show/Hide data repr Show/Hide attributes
xarray.Dataset
    • dayofyear: 123
    • depth: 101
    • year: 4
    • longitude
      ()
      float32
      -140.0
      FORTRAN_format :
      epic_code :
      502
      type :
      EVEN
      units :
      degree_east
      array(-140., dtype=float32)
    • latitude
      ()
      float32
      0.0
      FORTRAN_format :
      epic_code :
      500
      type :
      EVEN
      units :
      degree_north
      array(0., dtype=float32)
    • depth
      (depth)
      float64
      -500.0 -495.0 -490.0 ... -5.0 0.0
      array([-500., -495., -490., -485., -480., -475., -470., -465., -460., -455.,
             -450., -445., -440., -435., -430., -425., -420., -415., -410., -405.,
             -400., -395., -390., -385., -380., -375., -370., -365., -360., -355.,
             -350., -345., -340., -335., -330., -325., -320., -315., -310., -305.,
             -300., -295., -290., -285., -280., -275., -270., -265., -260., -255.,
             -250., -245., -240., -235., -230., -225., -220., -215., -210., -205.,
             -200., -195., -190., -185., -180., -175., -170., -165., -160., -155.,
             -150., -145., -140., -135., -130., -125., -120., -115., -110., -105.,
             -100.,  -95.,  -90.,  -85.,  -80.,  -75.,  -70.,  -65.,  -60.,  -55.,
              -50.,  -45.,  -40.,  -35.,  -30.,  -25.,  -20.,  -15.,  -10.,   -5.,
                0.])
    • year
      (year)
      int64
      1996 2001 2005 2013
      array([1996, 2001, 2005, 2013])
    • dayofyear
      (dayofyear)
      int64
      244 245 246 247 ... 363 364 365 366
      array([244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
             258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
             272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
             286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
             300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
             314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327,
             328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341,
             342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355,
             356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366])
    • T
      (depth, year, dayofyear)
      float64
      dask.array<chunksize=(101, 1, 123), meta=np.ndarray>
      Array Chunk
      Bytes 397.54 kB 99.38 kB
      Shape (101, 4, 123) (101, 1, 123)
      Count 80157 Tasks 4 Chunks
      Type float64 numpy.ndarray
      123 4 101
    • u
      (depth, year, dayofyear)
      float32
      dask.array<chunksize=(101, 1, 123), meta=np.ndarray>
      Array Chunk
      Bytes 198.77 kB 49.69 kB
      Shape (101, 4, 123) (101, 1, 123)
      Count 80157 Tasks 4 Chunks
      Type float32 numpy.ndarray
      123 4 101
    • v
      (depth, year, dayofyear)
      float32
      dask.array<chunksize=(101, 1, 123), meta=np.ndarray>
      Array Chunk
      Bytes 198.77 kB 49.69 kB
      Shape (101, 4, 123) (101, 1, 123)
      Count 80157 Tasks 4 Chunks
      Type float32 numpy.ndarray
      123 4 101
    • dens
      (depth, year, dayofyear)
      float64
      dask.array<chunksize=(101, 1, 123), meta=np.ndarray>
      Array Chunk
      Bytes 397.54 kB 99.38 kB
      Shape (101, 4, 123) (101, 1, 123)
      Count 92609 Tasks 4 Chunks
      Type float64 numpy.ndarray
      123 4 101
u = reshaped.u.sel(depth=slice(-200, -55)).sel(dayofyear=slice(365)).fillna(0)
u
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'u'
  • depth: 30
  • year: 4
  • dayofyear: 122
  • dask.array<chunksize=(30, 1, 122), meta=np.ndarray>
    Array Chunk
    Bytes 58.56 kB 14.64 kB
    Shape (30, 4, 122) (30, 1, 122)
    Count 80177 Tasks 4 Chunks
    Type float32 numpy.ndarray
    122 4 30
    • longitude
      ()
      float32
      -140.0
      FORTRAN_format :
      epic_code :
      502
      type :
      EVEN
      units :
      degree_east
      array(-140., dtype=float32)
    • latitude
      ()
      float32
      0.0
      FORTRAN_format :
      epic_code :
      500
      type :
      EVEN
      units :
      degree_north
      array(0., dtype=float32)
    • depth
      (depth)
      float64
      -200.0 -195.0 ... -60.0 -55.0
      array([-200., -195., -190., -185., -180., -175., -170., -165., -160., -155.,
             -150., -145., -140., -135., -130., -125., -120., -115., -110., -105.,
             -100.,  -95.,  -90.,  -85.,  -80.,  -75.,  -70.,  -65.,  -60.,  -55.])
    • year
      (year)
      int64
      1996 2001 2005 2013
      array([1996, 2001, 2005, 2013])
    • dayofyear
      (dayofyear)
      int64
      244 245 246 247 ... 362 363 364 365
      array([244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
             258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271,
             272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285,
             286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299,
             300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313,
             314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327,
             328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341,
             342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355,
             356, 357, 358, 359, 360, 361, 362, 363, 364, 365])
variable = u.differentiate("depth")

fft = xrft.dft(variable, dim=["dayofyear"]).mean("year")
rms = 1.414 * np.abs(fft).sel(freq_dayofyear=slice(1 / 50, 1 / 5)).integrate(
    "freq_dayofyear"
)

mean = variable.mean(["year", "dayofyear"])
mean, rms = dask.compute(mean, rms)

mean.plot(y="depth")
(mean + rms).plot(y="depth")
(mean - rms).plot(y="depth")
[<matplotlib.lines.Line2D at 0x2ac3fabc32b0>]
_images/a729c11333d01cac28b82e9c7fcb5b3ecd825c3344db9bad7f0fc89962917a06.png

This plot is junk because of sampling bias.

model = (
    gcm1.annual.sel(depth=slice(-250))
    .sel(latitude=0, longitude=-110, method="nearest")
    .rename({"theta": "T"})
)

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

ax = dict(zip("uT", axx))

for var in ax:
    model[var].plot(ax=ax[var], y="depth")
    meantao[var].sel(depth=slice(-250, None)).plot(ax=ax[var], y="depth")

[aa.set_title("") for aa in axx]
[Text(0.5, 1.0, ''), Text(0.5, 1.0, '')]
_images/6d676aaabc5841b13d0a51a9f259fdc99fbae4bde8349369d630c29592110caf.png
levels = np.sort([0.2, 0.4, 0.6, 0.8, 1])
gcm1.annual.u.sel(depth=slice(-400)).sel(latitude=0, method="nearest").plot.contour(
    colors="w", levels=levels
)
johnson.u.sel(longitude=slice(-170, -95)).sel(
    latitude=0, method="nearest"
).plot.contour(colors="k", levels=levels)
<matplotlib.contour.QuadContourSet at 0x2ac327fe0d30>
_images/0007bffcacf8695b7eb022d31232e3999b680fc11b38b906c6a006895ab445cf.png

125 W summer low Ri#

subset = (
    sections.isel(longitude=1)
    .sel(depth=slice(-200), time=slice("1996-04-20", "1996-05-03"))
    .sel(latitude=3.5, method="nearest")
)

subset.Jq.plot(
    x="time",
    robust=True,
)
subset.mld.plot(x="time")
[<matplotlib.lines.Line2D at 0x2ac3f0fd2710>]
_images/c6e3cbc3866ed91e43ca5065c66b673556b5a39f1fa81232d0b7447bdf435101.png
fg = (
    sections.Ri.sel(time="1996-04-30", depth=slice(-100))
    .isel(longitude=1)
    .plot(y="depth", row="time", vmin=0.1, vmax=0.7)
)
sections.mld.sel(time="1996-04-30").isel(longitude=1)
<xarray.DataArray 'mld' (time: 6, latitude: 480)>
dask.array<getitem, shape=(6, 480), dtype=float32, chunksize=(6, 138), chunktype=numpy.ndarray>
Coordinates:
  * time       (time) datetime64[ns] 1996-04-30 ... 1996-04-30T20:00:00
  * latitude   (latitude) float32 -12.0 -11.949896 -11.899791 ... 11.949896 12.0
    longitude  int64 -125
Attributes:
    long_name:    MLD
    units:        m
    description:  Interpolate density to 1m grid. Search for max depth where ...
_images/56bc634015c3ef91ea7074c9a0124349961ec4db9febf1c9d50fa94ac8bac7fb.png

diurnal trigger#

subset = (
    period4.isel(longitude=1)
    .sel(latitude=3.5, method="nearest")
    .sel(depth=slice(-100))
    .transpose(..., "time")
)

f, axx = plt.subplots(3, 1, sharex=True, squeeze=False)
ax = axx.squeeze()
subset.S2.plot(
    ax=ax[0],
    robust=True,
    norm=mpl.colors.Normalize(vmin=8e-5, vmax=4e-4),
    cmap=mpl.cm.Spectral_r,
)
subset.N2.plot(
    ax=ax[1],
    robust=True,
    norm=mpl.colors.LogNorm(vmin=0.5e-5, vmax=2e-4),
    cmap=mpl.cm.Spectral_r,
)
subset.Jq.rolling(depth=2).mean().plot(
    ax=ax[2], vmax=0, robust=True, cmap=mpl.cm.BuPu_r
)


def plot(ax):
    if "KPPhbl" in subset:
        (-1 * subset.KPPhbl).plot(x="time", color="w", lw=2, ax=ax)
    subset.mld.plot(color="g", lw=4, ax=ax)
    subset.dcl_base.plot(color="k", lw=2, ax=ax)
    subset.Jq.rolling(depth=2).mean().plot.contour(
        levels=17,
        colors="k",
        linestyles="-",
        linewidths=0.5,
        x="time",
        robust=True,
        ax=ax,
    )


[plot(axx) for axx in ax]

dcpy.plots.clean_axes(axx)

f.set_size_inches((8, 8))
_images/ea790c3162a26cf3c24908df844e5a211183cd9831618e32ae32091946e1772c.png

Presentation images#

Summary lat-lon fields#

subset = period4.isel(longitude=1).sel(depth=slice(-40, -60), latitude=slice(-2, 5))
# subset = subset.where((subset.depth < subset.mld)).mean("depth")
subset = subset.mean("depth")

kwargs = {
    "sst": dict(cmap=mpl.cm.RdYlBu_r),
    "uz": dict(vmax=1.5e-2),
    "vz": dict(vmax=1.5e-2),
    "N2": dict(cmap=mpl.cm.Greens, vmin=0, vmax=4e-4),
    "Jq": dict(cmap=mpl.cm.Blues_r, vmax=0, vmin=-200),
    "dcl": dict(cmap=mpl.cm.GnBu, vmin=10, vmax=50),
}

subset = subset[list(kwargs.keys())].compute()

xr.set_options(keep_attrs=True)
sstmean = subset.sst.resample(time="D").mean().compute()
kwargs = {
    "sst": dict(cmap=mpl.cm.RdYlBu_r),
    "uz": dict(vmax=1.5e-2),
    "vz": dict(vmax=1.5e-2),
    "N2": dict(cmap=mpl.cm.Greens, vmin=1e-5, vmax=2e-4),
    "Jq": dict(cmap=mpl.cm.Blues_r, vmax=0, vmin=-200),
    "dcl": dict(cmap=mpl.cm.GnBu, vmin=10, vmax=50),
}


f, axx = plt.subplots(2, 3, sharex=True, sharey=True, constrained_layout=True)

subset["sst"].attrs["long_name"] = "SST"
subset["uz"].attrs["long_name"] = "$u_z$"
subset["uz"].attrs["units"] = "1/s"
subset["vz"].attrs["long_name"] = "$v_z$"
subset["vz"].attrs["units"] = "1/s"
subset["N2"].attrs["long_name"] = "$N^2$"
subset["N2"].attrs["units"] = "1/s²"
subset["dcl"].attrs["long_name"] = "$z_{MLD} - z_{Ri}$"
subset["dcl"].attrs["units"] = "m"
subset["Jq"].attrs["long_name"] = "$J_q^t$"
subset["Jq"].attrs["units"] = "W/m²"

ax = dict(zip(["sst", "uz", "vz", "N2", "dcl", "Jq"], axx.flat))

for var, axis in ax.items():
    subset[var].plot(
        x="time",
        cbar_kwargs={"orientation": "horizontal", "shrink": 0.8},
        ax=axis,
        robust=True,
        **kwargs[var],
    )
    sstmean.plot.contour(
        x="time",
        ax=axis,
        levels=[24],
        colors="w",
        add_labels=False,
        linewidths=2,
    )
    sstmean.plot.contour(
        x="time",
        ax=axis,
        levels=[24],
        colors="k",
        add_labels=False,
        linewidths=0.5,
    )

[dcpy.plots.concise_date_formatter(aa) for aa in axx.flat]
[aa.set_xlabel("") for aa in axx.flat]
[aa.set_title("") for aa in axx.flat]

dcpy.plots.clean_axes(axx)
# f.savefig("images/period4-all-fields.png")
_images/65c8e04afc97f4576edf7a68b5502b89a2db37d93de08a2d631351f225ed2baf.png

shear rotation sequence#

pump.plot.vor_streamplot(
    period4,
    vort,
    stride=3,
    refspeed=0.4,
    uy=False,
    vec=False,
    stream=False,
)
plt.gcf().savefig("images/110-period4-vort-0.png")
_images/b778946a69fc233f526bf785b8709e2f8ed9e7c639575a5d02ad65f6b7145408.png
pump.plot.vor_streamplot(
    period4, vort, stride=3, refspeed=0.4, uy=False, vec=False, stream=True
)
plt.gcf().savefig("images/110-period4-vort-1.png")
_images/a6083554cf52a90f3a20acd474dbe9e0659fcf902256602b139f4a7ab041fcdb.png
pump.plot.vor_streamplot(period4, vort, stride=3, refspeed=0.4, uy=False, stream=False)
plt.gcf().savefig("images/110-period4-vort-2.png")
_images/1cee6800c2642d327757c36c0becdc41d2d58a90c351dcdc6776ddf940aa92a8.png
pump.plot.vor_streamplot(
    period4, vort, stride=3, refspeed=0.4, vy=True, stream=False, colorbar=False
)
plt.gca().text(0.8, 0.9, "$+v_y$", fontsize="xx-large", transform=plt.gca().transAxes)
plt.gcf().savefig("images/110-period4-vort-3.png")
_images/89c220fc02952f49d4457185cf57e1a8003315fb7bd53ca6a21f7473ffcd702e.png
pump.plot.vor_streamplot(
    period4, vort, stride=3, refspeed=0.4, stream=False, colorbar=False
)
plt.gca().text(0.8, 0.9, "$-u_y$", fontsize="xx-large", transform=plt.gca().transAxes)
plt.gcf().savefig("images/110-period4-vort-4.png")
_images/416a16d31bd6eb83696a3e3118396bdc0f21b17863f26da70ea2882a6ef0f407.png
pump.plot.vor_streamplot(
    period4, vort, stride=3, refspeed=0.4, uy=False, colorbar=False
)
plt.gcf().savefig("images/110-period4-vort-4.png")
_images/e9c80b7e9b8759ffe51cb8441a99b4a1eece5d12779168263ca909ba4126aceb.png
pump.plot.vor_streamplot(
    period4, vort, stride=3, refspeed=0.4, uy=False, colorbar=False
)
plt.gcf().savefig("images/110-period4-vort-4.png")
_images/e9c80b7e9b8759ffe51cb8441a99b4a1eece5d12779168263ca909ba4126aceb.png
pump.plot.vor_streamplot(
    period4, vort, stride=3, refspeed=0.4, uy=False, colorbar=False
)
plt.gcf().savefig("images/110-period4-vort-4.png")
_images/e9c80b7e9b8759ffe51cb8441a99b4a1eece5d12779168263ca909ba4126aceb.png

KPP deep cycle 1999 nov#

stationnov = (
    xr.open_zarr("nov-1999-station.zarr", consolidated=True)
    .sel(depth=slice(-50))
    .load()
)
stationnov
<xarray.Dataset>
Dimensions:        (depth: 20, time: 49)
Coordinates:
  * depth          (depth) float32 -1.25 -3.75 -6.25 ... -43.75 -46.25 -48.75
    latitude       float64 3.525
    longitude      float32 -110.025
  * time           (time) datetime64[ns] 1999-11-21 ... 1999-11-23
Data variables:
    Cd             (time) float64 0.001047 0.001046 ... 0.001075 0.00107
    Cdn_10         (time) float64 0.9759 0.9749 0.9742 ... 1.008 0.9959 0.988
    Ce             (time) float64 0.001237 0.001237 ... 0.001244 0.001253
    Cen_10         (time) float64 1.108 1.108 1.108 1.109 ... 1.105 1.106 1.107
    Ch             (time) float64 0.001237 0.001237 ... 0.001244 0.001253
    Chn_10         (time) float64 1.108 1.108 1.108 1.109 ... 1.105 1.106 1.107
    DFrI_TH        (depth, time) float32 0.0 0.0 0.0 ... -763.1658 -812.03156
    Evap           (time) float64 0.1404 0.1398 0.1391 ... 0.1514 0.1474 0.1456
    Jq             (depth, time) float64 0.0 0.0 0.0 ... -95.27 -102.3 -108.8
    KPPdiffKzT     (depth, time) float32 0.0 0.0 ... 0.0007682296 0.00079970685
    KPPg_TH        (depth, time) float32 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
    KPPhbl         (time) float32 22.682652 22.976309 ... 22.382105 22.323658
    KPPviscAz      (depth, time) float32 0.0 0.0 ... 0.0007772296 0.00080870686
    L              (time) float64 -50.09 -50.04 -50.2 ... -48.49 -44.78 -41.55
    Le             (time) float64 2.5e+06 2.5e+06 2.5e+06 ... 2.5e+06 2.5e+06
    Q10            (time) float64 12.94 12.95 12.96 12.93 ... 13.38 13.4 13.41
    Qrf            (time) float64 12.94 12.95 12.96 12.93 ... 13.38 13.4 13.41
    Qs             (time) float64 0.01747 0.01747 0.01746 ... 0.01792 0.01793
    RF             (time) float64 1.601e-10 9.915e-11 ... 1.131e-10 1.209e-10
    RH10           (time) float64 75.81 75.84 75.88 75.48 ... 78.1 78.3 78.46
    RHrf           (time) float64 75.81 75.84 75.88 75.48 ... 78.1 78.3 78.46
    Rnl            (time) float64 23.84 28.76 33.68 35.42 ... 31.87 30.67 31.06
    SSH            (time) float32 0.36676002 0.36429515 ... 0.37923476
    T10            (time) float64 22.65 22.65 22.64 22.69 ... 22.7 22.69 22.65
    Trf            (time) float64 22.65 22.65 22.64 22.69 ... 22.7 22.69 22.65
    U10            (time) float64 5.76 5.745 5.736 5.713 ... 6.195 6.022 5.902
    U10N           (time) float64 5.966 5.95 5.941 5.912 ... 6.425 6.256 6.143
    UN             (time) float64 5.966 5.95 5.941 5.912 ... 6.425 6.256 6.143
    Urf            (time) float64 5.76 5.745 5.736 5.713 ... 6.195 6.022 5.902
    UrfN           (time) float64 5.966 5.95 5.941 5.912 ... 6.425 6.256 6.143
    VISrI_Um       (depth, time) float32 0.0 0.0 0.0 ... 190.43164 193.63968
    VISrI_Vm       (depth, time) float32 0.0 0.0 0.0 ... -298.01572 -318.4322
    dens           (depth, time) float32 1023.3128 1023.317 ... 1023.55115
    dqer           (time) float64 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
    dter           (time) float64 0.1908 0.1978 0.2047 ... 0.2018 0.2022 0.2055
    hbb            (time) float64 12.05 11.94 11.84 11.21 ... 16.35 16.06 16.21
    hlb            (time) float64 97.53 97.06 96.61 96.27 ... 105.1 102.3 101.1
    hlwebb         (time) float64 2.531 2.516 2.5 2.423 ... 3.198 3.135 3.137
    hsb            (time) float64 4.97 4.904 4.828 4.225 ... 8.717 8.634 8.871
    hsbb           (time) float64 10.89 10.79 10.69 10.06 ... 15.09 14.84 15.01
    huss           (time) float64 0.01294 0.01295 0.01296 ... 0.0134 0.01341
    lat            (time) float64 -97.53 -97.06 -96.61 ... -105.1 -102.3 -101.1
    long           (time) float64 -35.87 -40.65 -45.41 ... -43.73 -42.57 -42.95
    netflux        (time) float64 -138.4 -142.6 -146.9 ... -157.6 -153.5 -153.0
    nonlocal_flux  (depth, time) float64 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
    prra           (time) float64 1.427e-07 8.867e-08 ... 1.004e-07 1.07e-07
    psl            (time) float64 1.014e+05 1.014e+05 ... 1.014e+05 1.013e+05
    qsr            (time) float64 -0.1732 -0.1729 -0.1724 ... -0.1714 -0.1731
    rhoa           (time) float64 1.2 1.2 1.2 1.2 1.2 ... 1.2 1.2 1.2 1.2 1.2
    rlds           (time) float64 401.1 396.1 391.1 389.3 ... 395.5 396.7 396.3
    rsds           (time) float64 0.0 0.0 0.0 29.76 59.52 ... 0.0 0.0 0.0 0.0
    salt           (depth, time) float32 34.304375 34.30507 ... 34.393257
    sens           (time) float64 -4.97 -4.904 -4.828 ... -8.717 -8.634 -8.871
    short          (time) float64 0.0 0.0 0.0 26.78 53.57 ... 0.0 0.0 0.0 0.0
    stress         (time) float64 0.04198 0.04172 0.04156 ... 0.04716 0.04512
    tas            (time) float64 295.8 295.8 295.8 295.8 ... 295.8 295.8 295.8
    tau            (time) float64 0.04198 0.04172 0.04156 ... 0.04716 0.04512
    taux           (time) float64 -0.0117 -0.01035 ... -0.01367 -0.01311
    tauy           (time) float64 0.04032 0.04042 0.04057 ... 0.04513 0.04317
    theta          (depth, time) float32 23.32442 23.311815 ... 22.730448
    tkt            (time) float64 0.0009061 0.0009081 ... 0.0008566 0.0008741
    tsr            (time) float64 -0.02195 -0.02173 ... -0.03597 -0.03777
    u              (depth, time) float32 -0.29970324 -0.30042994 ... -0.17791136
    uas            (time) float64 -1.606 -1.426 -1.246 ... -1.768 -1.746 -1.715
    usr            (time) float64 0.1877 0.1872 0.1868 ... 0.2056 0.199 0.1947
    v              (depth, time) float32 0.689187 0.6815233 ... -0.060036022
    vas            (time) float64 5.532 5.565 5.599 5.612 ... 5.938 5.763 5.647
    w              (depth, time) float32 -7.249771e-06 ... 4.057019e-05
    zet            (time) float64 -0.1997 -0.1998 -0.1992 ... -0.2233 -0.2407
    zoq            (time) float64 0.0001268 0.0001276 ... 0.0001107 0.0001166
    zot            (time) float64 0.0001268 0.0001276 ... 0.0001107 0.0001166
Attributes:
    easting:   longitude
    northing:  latitude
    title:     Station profile, index (i,j)=(1200,240)
stationnov.KPPdiffKzT.attrs["long_name"] = "$K_T$"
stationnov.KPPdiffKzT.attrs["units"] = "$m²/s²$"
stationnov.stress.attrs["units"] = "$N/m²$"
stationnov.netflux.attrs["long_name"] = "$Q_{net}$"
stationnov.netflux.attrs["units"] = "$W/m²$"
f, ax = pump.plot.plot_dcl(stationnov)
ax[0, 0].set_title("(3.5°N, 110°W)")
dcpy.plots.pub_fig_width("jpo", "medium 2")
f.savefig("../images/kpp-deep-cycle-35.png")
calc uz
calc vz
calc S2
calc N2
calc shred2
Calc Ri
/glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
  mask |= resdat <= 0
/glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/IPython/core/pylabtools.py:132: UserWarning: Creating legend with loc="best" can be slow with large amounts of data.
  fig.canvas.print_figure(bytes_io, **kw)
_images/1630d3a7c6f69f96bd9fd16c8055a70ee5ae5578bd22d30340135e9edf9c7b79.png

dcl flux vs surface flux#

gcm1.budget["time"] = gcm1.budget.time - pd.Timedelta("7h")

qnet = gcm1.budget.oceQnet.sel(longitude=-110, method="nearest")
# qnet = qnet.isel(time=slice(10)).mean("latitude")
# qnet = qnet.copy(data=qnet.data.map_blocks(np.copy))
period4.sst.isel(longitude=1).sel(latitude=slice(-1, 5)).plot(x="time")
<matplotlib.collections.QuadMesh at 0x2b1332eaf9e8>
_images/a43d42caec53b704c9ac69c2bf207ee6199ae8678222e88d4487e074e17a8736.png
period4["qnet"] = qnet.sel(time=period4.time).expand_dims("longitude")
def visualize(da, nblocks=5, **kwargs):
    kwargs.setdefault("color", "order")
    kwargs.setdefault("optimize_graph", True)
    kwargs.setdefault("rankdir", "LR")
    kwargs.setdefault("cmap", "autumn")
    da.data.blocks[slice(nblocks)].visualize(**kwargs)
period4.dcl.load()
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'dcl'
  • time: 210
  • latitude: 480
  • longitude: 3
  • 0.0 0.0 0.0 0.0 0.0 0.0 2.0 0.0 ... 9.0 11.0 11.0 11.0 0.0 0.0 0.0
    array([[[ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 2.,  0.,  0.],
            ...,
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.]],
    
           [[ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            ...,
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.]],
    
           [[ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            ...,
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.]],
    
           ...,
    
           [[ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            ...,
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.]],
    
           [[ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            ...,
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.]],
    
           [[ 0.,  0.,  0.],
            [ 8.,  8.,  8.],
            [ 8.,  7.,  8.],
            ...,
            [ 9., 10.,  9.],
            [11., 11., 11.],
            [ 0.,  0.,  0.]]], dtype=float32)
    • longitude
      (longitude)
      float64
      -110.1 -110.0 -110.0
      array([-110.060043, -110.01001 , -109.959976])
    • latitude
      (latitude)
      float32
      -12.0 -11.949896 ... 11.949896 12.0
      array([-12.      , -11.949896, -11.899791, ...,  11.899791,  11.949896,
              12.      ], dtype=float32)
    • time
      (time)
      datetime64[ns]
      1995-11-10T17:00:00 ... 1995-12-15T13:00:00
      array(['1995-11-10T17:00:00.000000000', '1995-11-10T21:00:00.000000000',
             '1995-11-11T01:00:00.000000000', ..., '1995-12-15T05:00:00.000000000',
             '1995-12-15T09:00:00.000000000', '1995-12-15T13:00:00.000000000'],
            dtype='datetime64[ns]')
period4["mld"], period4["dcl_base"] = dask.compute(period4.mld, period4.dcl_base)
period4 = period4.sel(time=slice("1995-11-11 00:00", "1995-12-15 00:00"))
latslice = slice(None, None)
sstmask = (period4.sst.isel(longitude=1).sel(latitude=latslice) < 24.3).compute()
period4.sst.isel(longitude=1).where(sstmask).plot(levels=11, x="time")
<matplotlib.collections.QuadMesh at 0x2b12fdddbc18>
_images/5c73f214eabf7d702eb0711e15de5b96ce74a32273742dc99928350a08b465d6.png
masked = period4.isel(longitude=1).where(sstmask)
dcmask = ((masked.depth > masked.dcl_base) & (masked.depth < masked.mld)).compute()
dcl_jq = masked.Jq.where(sstmask & dcmask)
masked.dcl.where(dcmask).plot.hist(bins=30)
(array([4.70000e+03, 7.83600e+03, 1.29980e+04, 1.52560e+04, 1.78160e+04,
        1.13470e+04, 1.10620e+04, 3.17100e+03, 1.66364e+05, 3.42010e+04,
        2.79190e+04, 1.96840e+04, 3.16700e+04, 3.10220e+04, 2.97680e+04,
        2.74370e+04, 2.47780e+04, 1.82610e+04, 2.73120e+04, 2.48090e+04,
        2.26800e+04, 1.91240e+04, 1.08830e+04, 5.12700e+03, 4.89400e+03,
        4.30700e+03, 1.89900e+03, 7.07000e+02, 2.46000e+02, 8.60000e+01]),
 array([ 2.       ,  4.8333335,  7.6666665, 10.5      , 13.333333 ,
        16.166666 , 19.       , 21.833334 , 24.666666 , 27.5      ,
        30.333334 , 33.166668 , 36.       , 38.833332 , 41.666668 ,
        44.5      , 47.333332 , 50.166668 , 53.       , 55.833332 ,
        58.666668 , 61.5      , 64.333336 , 67.166664 , 70.       ,
        72.833336 , 75.666664 , 78.5      , 81.333336 , 84.166664 ,
        87.       ], dtype=float32),
 <a list of 30 Patch objects>)
_images/c217dabea64a6bc051e5e1ced69acef8fbb384e05ef2f95dc8d01ec0f48b36a5.png
period4.dcl.where(period4.dcl > 0).isel(longitude=1).plot()
<matplotlib.collections.QuadMesh at 0x2b1387a68f28>
_images/d1b64863679b24eefcfd2548ea502979c1edcb3cc995c409be93bdda61b8ac42.png
masked.qnet.sum("time").plot(y="latitude")
(-1 * dcl_jq.sum(["depth", "time"]) / 50).plot(y="latitude")
qnet = (period4.isel(longitude=1).qnet).load()
mean_dcl_jq = (-1 * dcl_jq.sum("depth") / 50).fillna(0).mean(["time"]).load()
uprof = (
    period4.u.sel(depth=slice(-70, -120))
    .isel(longitude=1)
    .mean(["depth", "time"])
    .load()
)
daily_qnet = qnet.resample(time="D").mean()

daily_qnet.where(daily_qnet > 0).mean("time").plot(y="latitude")
mean_dcl_jq.plot(y="latitude")

ax1 = plt.gca()
ax1.set_facecolor("None")
ax2 = ax1.twiny()

ax2.fill_betweenx(uprof.latitude, uprof.values, color="gray", alpha=0.5)
ax2.set_xlim([-0.5, 1.5])
ax2.set_ylim([-5, 5])
ax2.set_zorder(-1)
ax1.set_xlim([0, 220])
plt.gcf().set_size_inches((3, 5))
_images/0508a775914ec5d2543b6f692e551afc4ad5e548b934608ac03db5c52784ac1b.png
period4.isel(longitude=1).qnet.resample(time="D").mean().plot(x="time")
masked.sst.plot.contour(levels=11, x="time")
dcpy.plots.liney([2.5, 4.25], zorder=10)
_images/a66964822fdc3c5945e178f787010bf2a54a89aa423041e85a777f1173ef321c.png

Check 1_hb jq calculation#

tao = xr.open_dataset(
    "~/pump/glade/TPOS_MITgcm_1_hb/HOLD/obs_subset/tao-budget-extract.nc"
).load()
metrics = read_metrics("../glade/TPOS_MITgcm_1_hb/")
metrics.dRF.max().compute()
Show/Hide data repr Show/Hide attributes
xarray.DataArray
'dRF'
  • -2.5
    array(-2.5)
    (
        (
            3994
            * 1035
            * tao.sel(longitude=-110, latitude=0).DFrI_TH.rolling(depth=2).mean()
            / metrics.RAC.sel(longitude=-110, method="nearest", latitude=0)
        )
        .sel(time=slice("1996-05-19", "1996-05-23"))
        .plot(x="time", robust=True)
    )
    
    <matplotlib.collections.QuadMesh at 0x2b325d2fba20>
    
    _images/c9efd0566394acfe5a1b924e4e1dbf8a8fd2ed54de97bbbb0c9e92e3de10c055.png

    Get surface fluxes for station#

    station = ds
    
    jrafull = xr.concat(
        [
            pump.obs.read_jra(
                "/glade/p/nsc/ncgd0043/make_TPOS_MITgcm/JRA_FORCING/1999/JRA55DO*[0-9].nc",
                chunks={"time": 1200},
            ),
            pump.obs.read_jra(
                "/glade/p/nsc/ncgd0043/make_TPOS_MITgcm/JRA_FORCING/200[0-2]/JRA55DO*[0-9].nc",
                chunks={"time": 1200},
            ),
        ],
        dim="time",
    )
    jrafull["time"] = jrafull.time - pd.Timedelta("7h")
    jra = jrafull.interp(longitude=-110.009, latitude=0.02506, method="linear").sel(
        time=slice(station.time[0].values, station.time[-1].values)
    )
    jra["time"] = jra.time.dt.floor("h")
    for var in jra.variables:
        if isinstance(jra[var].data, dask.array.Array):
            jra[var] = jra[var].copy(data=jra[var].data.map_blocks(np.copy))
    jra
    
    Show/Hide data repr Show/Hide attributes
    xarray.Dataset
      • time: 8000
      • time
        (time)
        datetime64[ns]
        1998-12-31T18:00:00 ... 2000-05-14T17:00:00
        array(['1998-12-31T18:00:00.000000000', '1998-12-31T20:00:00.000000000',
               '1998-12-31T21:00:00.000000000', ..., '2000-05-14T14:00:00.000000000',
               '2000-05-14T15:00:00.000000000', '2000-05-14T17:00:00.000000000'],
              dtype='datetime64[ns]')
      • longitude
        ()
        float64
        -110.0
        array(-110.009)
      • latitude
        ()
        float64
        0.02506
        array(0.02506)
      • huss
        (time)
        float32
        dask.array<chunksize=(2399,), meta=np.ndarray>
        actual_range :
        [1.9999999e-05 2.0845825e-02]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • prra
        (time)
        float32
        dask.array<chunksize=(2400,), meta=np.ndarray>
        actual_range :
        [0. 0.00155959]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • psl
        (time)
        float32
        dask.array<chunksize=(2399,), meta=np.ndarray>
        actual_range :
        [ 94958.15 104364.42]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • rlds
        (time)
        float32
        dask.array<chunksize=(2400,), meta=np.ndarray>
        actual_range :
        [126.48046 442.72263]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • rsds
        (time)
        float32
        dask.array<chunksize=(2400,), meta=np.ndarray>
        actual_range :
        [ 0. 1149.1526]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • tas
        (time)
        float32
        dask.array<chunksize=(2399,), meta=np.ndarray>
        actual_range :
        [235.69489 304.40918]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • uas
        (time)
        float32
        dask.array<chunksize=(2399,), meta=np.ndarray>
        actual_range :
        [-26.107578 28.0601 ]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
      • vas
        (time)
        float32
        dask.array<chunksize=(2399,), meta=np.ndarray>
        actual_range :
        [-26.301264 20.78898 ]
        Array Chunk
        Bytes 32.00 kB 9.60 kB
        Shape (8000,) (2400,)
        Count 183 Tasks 4 Chunks
        Type float32 numpy.ndarray
        8000 1
    • About :
      Created with SOSIE interpolation environement => https://github.com/brodeau/sosie/
    jrai = jra.compute().interpolate_na("time").interp(time=station.time)
    fluxes = pump.calc.coare_fluxes_jra(station.sel(latitude=0, method="nearest"), jrai)
    
    fluxes.sel(time="1999-05").to_array().plot(x="time", hue="variable")
    
    [<matplotlib.lines.Line2D at 0x2ac8544011d0>,
     <matplotlib.lines.Line2D at 0x2ac81a4ca390>,
     <matplotlib.lines.Line2D at 0x2ac80b617b70>,
     <matplotlib.lines.Line2D at 0x2ac8511004a8>,
     <matplotlib.lines.Line2D at 0x2ac7d3a9a0b8>,
     <matplotlib.lines.Line2D at 0x2ac802430390>]
    
    _images/54684f5d64dccc196ce3933bb8e8a711ccb01542a5bbb5b271c9a9cb8733fe60.png
    expected = xr.open_mfdataset(
        "/glade/campaign/cgd/oce/people/bachman/TPOS_MITgcm_fix3/*00[0-9][0-9]*surf.nc",
        parallel=True,
        chunks={"time": 1},
    )
    # expected["time"] = expected.time - pd.Timedelta("7h")
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/ipykernel_launcher.py:2: FutureWarning: In xarray version 0.15 the default behaviour of `open_mfdataset`
    will change. To retain the existing behavior, pass
    combine='nested'. To use future default behavior, pass
    combine='by_coords'. See
    http://xarray.pydata.org/en/stable/combining.html#combining-multi
    
      
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/backends/api.py:941: FutureWarning: The datasets supplied have global dimension coordinates. You may want
    to use the new `combine_by_coords` function (or the
    `combine='by_coords'` option to `open_mfdataset`) to order the datasets
    before concatenation. Alternatively, to continue concatenating based
    on the order the datasets are supplied in future, please use the new
    `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset).
      from_openmfds=True,
    

    Things look good! I could take the daily error and distribute that in time uniformly in my hourly net flux time series

    actual = fluxes.sel(time=slice(expected.time[0], expected.time[-1]))
    # output has means calculated in GMT
    # so shift time back to GMT and then calculate daily means.
    # first and last points will be weird.
    actual["time"] = actual.time + pd.Timedelta("7h")
    # actual.total.plot()
    (
        actual.total.resample(time="D").mean().hvplot()
        * expected.TFLUX.sel(latitude=0, longitude=-110, method="nearest").hvplot(x="time")
    )
    

    debug eucmax#

    yp, y0, ym = dask.compute(*get_euc_bounds(u))
    yp.plot(hue="longitude")
    sections.eucmax.plot(hue="longitude")
    ym.plot(hue="longitude")
    
    [<matplotlib.lines.Line2D at 0x2ac3af343050>,
     <matplotlib.lines.Line2D at 0x2ac3e40111d0>,
     <matplotlib.lines.Line2D at 0x2ac3ed8dae50>,
     <matplotlib.lines.Line2D at 0x2ac3e8886910>]
    
    _images/5b68e1999df3db7815dd27129131993b7b69f8f2d1960ce27089ecb72b6f8c94.png

    KPP’s deep cycle#

    1. The descending shear layer coincides with a descending PBL. The mixed layer descends later

    20 year run stations#

    jrafull = pump.obs.read_jra_20()
    station = pump.model.model.read_stations_20("../TPOS_MITgcm_fix3/", "*110.000*.nc")
    station
    
    Show/Hide data repr Show/Hide attributes
    xarray.Dataset
      • depth: 185
      • latitude: 111
      • time: 24000
      • depth
        (depth)
        float32
        -1.25 -3.75 ... -5758.0986
        array([-1.250000e+00, -3.750000e+00, -6.250000e+00, -8.750000e+00,
               -1.125000e+01, -1.375000e+01, -1.625000e+01, -1.875000e+01,
               -2.125000e+01, -2.375000e+01, -2.625000e+01, -2.875000e+01,
               -3.125000e+01, -3.375000e+01, -3.625000e+01, -3.875000e+01,
               -4.125000e+01, -4.375000e+01, -4.625000e+01, -4.875000e+01,
               -5.125000e+01, -5.375000e+01, -5.625000e+01, -5.875000e+01,
               -6.125000e+01, -6.375000e+01, -6.625000e+01, -6.875000e+01,
               -7.125000e+01, -7.375000e+01, -7.625000e+01, -7.875000e+01,
               -8.125000e+01, -8.375000e+01, -8.625000e+01, -8.875000e+01,
               -9.125000e+01, -9.375000e+01, -9.625000e+01, -9.875000e+01,
               -1.012500e+02, -1.037500e+02, -1.062500e+02, -1.087500e+02,
               -1.112500e+02, -1.137500e+02, -1.162500e+02, -1.187500e+02,
               -1.212500e+02, -1.237500e+02, -1.262500e+02, -1.287500e+02,
               -1.312500e+02, -1.337500e+02, -1.362500e+02, -1.387500e+02,
               -1.412500e+02, -1.437500e+02, -1.462500e+02, -1.487500e+02,
               -1.512500e+02, -1.537500e+02, -1.562500e+02, -1.587500e+02,
               -1.612500e+02, -1.637500e+02, -1.662500e+02, -1.687500e+02,
               -1.712500e+02, -1.737500e+02, -1.762500e+02, -1.787500e+02,
               -1.812500e+02, -1.837500e+02, -1.862500e+02, -1.887500e+02,
               -1.912500e+02, -1.937500e+02, -1.962500e+02, -1.987500e+02,
               -2.012500e+02, -2.037500e+02, -2.062500e+02, -2.087500e+02,
               -2.112500e+02, -2.137500e+02, -2.162500e+02, -2.187500e+02,
               -2.212500e+02, -2.237500e+02, -2.262500e+02, -2.287500e+02,
               -2.312500e+02, -2.337500e+02, -2.362500e+02, -2.387500e+02,
               -2.412500e+02, -2.437500e+02, -2.462500e+02, -2.487500e+02,
               -2.513687e+02, -2.542363e+02, -2.573763e+02, -2.608145e+02,
               -2.645794e+02, -2.687019e+02, -2.732162e+02, -2.781592e+02,
               -2.835718e+02, -2.894987e+02, -2.959886e+02, -3.030949e+02,
               -3.108764e+02, -3.193972e+02, -3.287274e+02, -3.389439e+02,
               -3.501312e+02, -3.623811e+02, -3.757947e+02, -3.904827e+02,
               -4.065660e+02, -4.241773e+02, -4.434617e+02, -4.645781e+02,
               -4.877004e+02, -5.130195e+02, -5.407438e+02, -5.711019e+02,
               -6.043441e+02, -6.407443e+02, -6.806025e+02, -7.242472e+02,
               -7.720381e+02, -8.243693e+02, -8.816718e+02, -9.444181e+02,
               -1.013125e+03, -1.088360e+03, -1.170741e+03, -1.260949e+03,
               -1.358099e+03, -1.458099e+03, -1.558099e+03, -1.658099e+03,
               -1.758099e+03, -1.858099e+03, -1.958099e+03, -2.058098e+03,
               -2.158098e+03, -2.258098e+03, -2.358098e+03, -2.458098e+03,
               -2.558098e+03, -2.658098e+03, -2.758098e+03, -2.858098e+03,
               -2.958098e+03, -3.058098e+03, -3.158098e+03, -3.258098e+03,
               -3.358098e+03, -3.458098e+03, -3.558098e+03, -3.658098e+03,
               -3.758098e+03, -3.858098e+03, -3.958098e+03, -4.058098e+03,
               -4.158099e+03, -4.258099e+03, -4.358099e+03, -4.458099e+03,
               -4.558099e+03, -4.658099e+03, -4.758099e+03, -4.858099e+03,
               -4.958099e+03, -5.058099e+03, -5.158099e+03, -5.258099e+03,
               -5.358099e+03, -5.458099e+03, -5.558099e+03, -5.658099e+03,
               -5.758099e+03], dtype=float32)
      • longitude
        ()
        float32
        ...
        array(-110.025, dtype=float32)
      • latitude
        (latitude)
        float64
        -3.075 -3.025 ... 5.975 6.025
        array([-3.075, -3.025, -2.975, -2.825, -2.775, -2.725, -2.575, -2.525, -2.475,
               -2.325, -2.275, -2.225, -2.075, -2.025, -1.975, -1.825, -1.775, -1.725,
               -1.575, -1.525, -1.475, -1.325, -1.275, -1.225, -1.075, -1.025, -0.975,
               -0.825, -0.775, -0.725, -0.575, -0.525, -0.475, -0.325, -0.275, -0.225,
               -0.075, -0.025,  0.025,  0.175,  0.225,  0.275,  0.425,  0.475,  0.525,
                0.675,  0.725,  0.775,  0.925,  0.975,  1.025,  1.175,  1.225,  1.275,
                1.425,  1.475,  1.525,  1.675,  1.725,  1.775,  1.925,  1.975,  2.025,
                2.175,  2.225,  2.275,  2.425,  2.475,  2.525,  2.675,  2.725,  2.775,
                2.925,  2.975,  3.025,  3.175,  3.225,  3.275,  3.425,  3.475,  3.525,
                3.675,  3.725,  3.775,  3.925,  3.975,  4.025,  4.175,  4.225,  4.275,
                4.425,  4.475,  4.525,  4.675,  4.725,  4.775,  4.925,  4.975,  5.025,
                5.175,  5.225,  5.275,  5.425,  5.475,  5.525,  5.675,  5.725,  5.775,
                5.925,  5.975,  6.025])
      • time
        (time)
        datetime64[ns]
        1998-12-31T18:00:00 ... 2001-09-26T17:00:00
        array(['1998-12-31T18:00:00.000000000', '1998-12-31T19:00:00.000000000',
               '1998-12-31T20:00:00.000000000', ..., '2001-09-26T15:00:00.000000000',
               '2001-09-26T16:00:00.000000000', '2001-09-26T17:00:00.000000000'],
              dtype='datetime64[ns]')
      • SSH
        (time, latitude)
        float32
        dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 10.66 MB 24.00 kB
        Shape (24000, 111) (6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000
      • KPPhbl
        (time, latitude)
        float32
        dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 10.66 MB 24.00 kB
        Shape (24000, 111) (6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000
      • u
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • v
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • w
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • theta
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • salt
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • DFrI_TH
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • VISrI_Um
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • VISrI_Vm
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • KPPdiffKzT
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • KPPviscAz
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • KPPg_TH
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 2220 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
      • Jq
        (depth, time, latitude)
        float64
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 3.94 GB 8.88 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 6002 Tasks 444 Chunks
        Type float64 numpy.ndarray
        111 24000 185
      • nonlocal_flux
        (depth, time, latitude)
        float64
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 3.94 GB 8.88 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 3338 Tasks 444 Chunks
        Type float64 numpy.ndarray
        111 24000 185
      • dens
        (depth, time, latitude)
        float32
        dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Array Chunk
        Bytes 1.97 GB 4.44 MB
        Shape (185, 24000, 111) (185, 6000, 1)
        Count 4885 Tasks 444 Chunks
        Type float32 numpy.ndarray
        111 24000 185
    • title :
      Station profile, index (i,j)=(1200,240)
      easting :
      longitude
      northing :
      latitude

    frictional shear torque#

    state = xr.open_mfdataset(
        "/glade/campaign/cgd/oce/people/bachman/TPOS_MITgcm_fix3/File_0[0-4]*buoy.nc",
        parallel=True,
    )
    budget = xr.open_mfdataset(
        "/glade/campaign/cgd/oce/people/bachman/TPOS_MITgcm_fix3/File_0[0-4]*[u,v]b.nc",
        parallel=True,
    )
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: In xarray version 0.15 the default behaviour of `open_mfdataset`
    will change. To retain the existing behavior, pass
    combine='nested'. To use future default behavior, pass
    combine='by_coords'. See
    http://xarray.pydata.org/en/stable/combining.html#combining-multi
    
      """Entry point for launching an IPython kernel.
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/backends/api.py:941: FutureWarning: The datasets supplied have global dimension coordinates. You may want
    to use the new `combine_by_coords` function (or the
    `combine='by_coords'` option to `open_mfdataset`) to order the datasets
    before concatenation. Alternatively, to continue concatenating based
    on the order the datasets are supplied in future, please use the new
    `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset).
      from_openmfds=True,
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/ipykernel_launcher.py:2: FutureWarning: In xarray version 0.15 the default behaviour of `open_mfdataset`
    will change. To retain the existing behavior, pass
    combine='nested'. To use future default behavior, pass
    combine='by_coords'. See
    http://xarray.pydata.org/en/stable/combining.html#combining-multi
    
      
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/backends/api.py:941: FutureWarning: The datasets supplied have global dimension coordinates. You may want
    to use the new `combine_by_coords` function (or the
    `combine='by_coords'` option to `open_mfdataset`) to order the datasets
    before concatenation. Alternatively, to continue concatenating based
    on the order the datasets are supplied in future, please use the new
    `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset).The datasets supplied require both concatenation and merging. From
    xarray version 0.15 this will operation will require either using the
    new `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset), with a nested list structure such that you can combine
    along the dimensions None. Alternatively if your datasets have global
    dimension coordinates then you can use the new `combine_by_coords`
    function.
      from_openmfds=True,
    
    metrics = pump.model.model.read_metrics(
        "/glade/campaign/cgd/oce/people/bachman/TPOS_MITgcm_fix3/"
    )
    metrics = (
        metrics.isel(
            longitude=slice(40, -40), latitude=slice(40, -40), depth=slice(136)
        ).assign_coords(
            longitude=state.longitude, latitude=state.latitude, depth=state.depth
        )
    ).persist()
    
    VISrI_Um = xr.concat(
        [
            budget.VISrI_Um,
            xr.zeros_like(budget.VISrI_Um.isel(depth=0).drop("depth")).expand_dims(
                depth=[-5865.922]
            ),
        ],
        dim="depth",
    )
    
    VISrI_Vm = xr.concat(
        [
            budget.VISrI_Vm,
            xr.zeros_like(budget.VISrI_Vm.isel(depth=0).drop("depth")).expand_dims(
                depth=[-5865.922]
            ),
        ],
        dim="depth",
    )
    # from http://mailman.mitgcm.org/pipermail/mitgcm-support/2010-December/006921.html
    budget["Um_Impl"] = VISrI_Um.diff("depth", label="lower") / (
        metrics.rAw * metrics.drF * metrics.hFacW
    )
    # from http://mailman.mitgcm.org/pipermail/mitgcm-support/2010-December/006921.html
    budget["Vm_Impl"] = VISrI_Vm.diff("depth", label="lower") / (
        metrics.rAw * metrics.drF * metrics.hFacW
    )
    
    state.theta.isel(depth=0).sel(longitude=-110, method="nearest").sel(
        latitude=slice(-2, 6), time=slice("1999-Jul", "1999-Nov")
    ).plot(x="time")
    
    <matplotlib.collections.QuadMesh at 0x2b03bdf443c8>
    
    _images/7d4aeb9401ea92ada138151e9695131553eb75452c89a800f3ad789f283718f2.png
    def subset(ds):
        return (
            ds.sel(time=slice("1999-12-15", "1999-10-15"))
            .sel(latitude=slice(-2, 6), depth=slice(-100))
            .sel(longitude=-110, method="nearest")
            .pipe(dcpy.dask.map_copy)
        )
    
    subset(state.v.differentiate("depth")).sel(depth=slice(-60)).mean("depth").plot(
        x="time", robust=True
    )
    subset(state.theta).isel(depth=0).plot.contour(colors="k", linewidths=1, x="time")
    
    <matplotlib.contour.QuadContourSet at 0x2b03bdf21d30>
    
    _images/71767386705d7fe4ebebcc3f10d745807ccc84cef72b856a5968bd98ca4484ea.png
    state["dens"] = pump.mdjwf.dens(state.salt, state.theta, np.array([0.0]))
    period = (
        state.merge(budget[["Um_Diss", "Um_Impl", "Vm_Diss", "Vm_Impl"]])
        .sel(time=slice("1999-10-15", "1999-11-15"))
        .sel(latitude=slice(-2, 6), depth=slice(-100))
        .pipe(dcpy.dask.map_copy)
    )
    idx = period.indexes["longitude"].get_loc(-110, method="nearest")
    period = period.isel(longitude=[idx - 1, idx, idx + 1])
    duzdt, dvzdt = dask.compute(*pump.calc.estimate_shear_evolution_terms(period))
    
    period = pump.calc_reduced_shear(period)
    period["mld"] = pump.calc.get_mld(period.dens)
    period["dcl_base"] = pump.calc.get_dcl_base_Ri(period)
    period["dcl"] = period.mld - period.dcl_base
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    period = period.persist()
    
    f, ax = pump.plot.plot_shear_terms(period, duzdt, dvzdt, mask_dcl=False)
    # ax["u"]["shear"].set_xlim((None, "1999-12-06"))
    
    _images/465c73e57e7a116f29cac5909c992f5f07e93b5d88f8e2ade836393500b51fa7.png
    f, ax = pump.plot.plot_shear_terms(period, duzdt, dvzdt, mask_dcl=False)
    ax["u"]["shear"].set_xlim((None, "1999-12-06"))
    
    (730072.5, 730094.0)
    
    _images/b30b6b9676cf439cd880186d2ca8bb3760cf2d6f2f723cdad00ee00dc09e81b9.png
    state.v.sel(
        latitude=slice(-2, 2),
        depth=slice(-80),
        longitude=slice(-125, -95),
        time=slice("1999-11-09", "2000-01-01"),
    ).mean(["depth", "latitude"]).plot(x="longitude", robust=True)
    pump.plot.plot_reference_speed(plt.gca())
    
    _images/926feb1e768fc981e4d8599b5b76ea2c1df54ebb948ee51eda01c27cd3def636.png
    pump.plot.vor_streamplot(period, pump.calc.vorticity(period), stride=2, refspeed=0.3)
    
    _images/8b4bab6fa8dad8a04613833f9443985ac6be2536d5658be6508b0993db747679.png
    (subset(budget.Vm_Impl)).differentiate("depth").sel(depth=slice(-60)).mean(
        "depth"
    ).plot(x="time", vmin=-5e-8, cmap=mpl.cm.RdBu_r)
    subset(state.v.differentiate("depth")).sel(depth=slice(-60)).mean("depth").plot.contour(
        colors="k", levels=15, x="time", robust=True
    )
    
    <matplotlib.contour.QuadContourSet at 0x2b7f9adf5ed0>
    
    _images/7abd6df5f6946bfbdefade7b8689672a1b1af64623b51037faa06fc95a5b4ef7.png
    subset(state).theta.isel(depth=0).plot.contourf(levels=21, x="time", robust=True)
    
    <matplotlib.contour.QuadContourSet at 0x2b6e1e7b4190>
    
    _images/15e0abc9e333255b92abc6a2c60f4981b884c7f89710ee6854ffd9f03cb80503.png
    subset(ubvb).VISrI_Vm.sel(latitude=0, method="nearest").sel(depth=slice(-100)).plot(
        y="depth", robust=True
    )
    
    <matplotlib.collections.QuadMesh at 0x2b6e62631090>
    
    _images/3b5e899a855c917feb2732e1b1a90812a71a5a80700656f8e234aacec7672614.png
    subset(ubvb).Vm_Diss.differentiate("depth").sel(depth=slice(-60)).mean("depth").plot(
        x="time", robust=True
    )
    
    <matplotlib.collections.QuadMesh at 0x2b6e2c134c90>
    
    _images/a9dfdf1a7515a739379a34a1b751e5110833de20a95576281934f05afa1ae738.png
    forcing = pump.obs.interp_jra_to_station(jrafull, station)
    fluxes, coare = pump.calc.coare_fluxes_jra(station, forcing)
    station = station.merge(fluxes, compat="override")
    station = station.merge(coare, compat="override")
    station = station.merge(forcing, compat="override")
    
    /glade/u/home/dcherian/python/xcoare/xcoare/coare35vn.py:466: RuntimeWarning: invalid value encountered in greater
      k = u10 > umax
    /glade/u/home/dcherian/python/xcoare/xcoare/coare35vn.py:480: RuntimeWarning: invalid value encountered in greater
      charn = np.where(ut > 0, 0.011 + (ut - 10) / (18 - 10) * (0.018 - 0.011), 0.011)
    /glade/u/home/dcherian/python/xcoare/xcoare/coare35vn.py:481: RuntimeWarning: invalid value encountered in greater
      charn[ut > 18] = 0.018
    
    fluxes.netflux.sel(latitude=0, method="nearest").isel(time=slice(1000)).plot(x="time")
    
    [<matplotlib.lines.Line2D at 0x2b0a34394400>]
    
    _images/aecfdf5d6b675d49ee52c3e57a62dff5d93b3b4d6a5c3db8adabcca1a4583879.png

    deep cycle plots#

    def hvplot_dcl(subset):
        flx = subset.netflux.hvplot()
        S2 = subset.S2.hvplot(cmap="fire")
        N2 = subset.N2.hvplot()
        jq = subset.Jq.hvplot.image(x="time")
    
        lines = (
            subset.mld.hvplot(color="darkorange", line_style="--", line_width=3)
            * (-1 * subset.KPPhbl).hvplot(x="time", color="w", line_width=4)
            * (-1 * subset.KPPhbl).hvplot(x="time", color="k", line_width=2)
            * subset.dcl_base.hvplot(color="k", line_width=2)
            * (-1 * subset.Jq).hvplot.contour(
                levels=17, colormap=["black"], line_width=0.5, x="time"
            )
        )
    
        layout = flx + S2 * lines + N2 * lines + jq * lines
    
        return (layout).opts(shared_axes=True, transpose=True)
    
    
    hvplot_dcl(station)
    
    WARNING:param.Image03702: Image dimension latitude is not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.
    WARNING:param.Image03702: Image dimension latitude is not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.
    WARNING:param.Image03702: Image dimension latitude is not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.
    
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-217-d4f5524c1d25> in <module>
         21 
         22 
    ---> 23 hvplot_dcl(station)
    
    <ipython-input-217-d4f5524c1d25> in hvplot_dcl(subset)
          2 
          3     flx = subset.netflux.hvplot()
    ----> 4     S2 = subset.S2.hvplot(cmap="fire")
          5     N2 = subset.N2.hvplot()
          6     jq = subset.Jq.hvplot.image(x="time")
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/core/common.py in __getattr__(self, name)
        231                     return source[name]
        232         raise AttributeError(
    --> 233             "{!r} object has no attribute {!r}".format(type(self).__name__, name)
        234         )
        235 
    
    AttributeError: 'Dataset' object has no attribute 'S2'
    
    subset = station.sel(latitude=0, method="nearest").sel(
        depth=slice(-60), time=slice("1999-01-10", "1999-01-11")
    )
    pump.plot.plot_dcl(subset)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    (<Figure size 1120x1120 with 8 Axes>,
     array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b82520a0a90>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b825301af50>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b8251bb0c10>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b82520d88d0>]],
           dtype=object))
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/592d8dcf634fa00cb14a77c42a7777461c4fde9bcfe93265d4d100f741c758a5.png
    subset = station.sel(latitude=0, method="nearest").sel(
        depth=slice(-60), time=slice("1999-10-13", "1999-10-15")
    )
    
    plot_dcl(subset)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    (<Figure size 1120x1120 with 8 Axes>,
     array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b213b692dd8>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b21c0401c50>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b2182f40518>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b213c663240>]],
           dtype=object))
    
    _images/1dd0901bd068fbd429cfae2fc851f264996cd5170c48c1796b2fab76d83c7d7c.png
    subset = station.sel(latitude=0, method="nearest").sel(
        depth=slice(-80), time=slice("1999-03-21 12:00", "1999-03-23 12:00")
    )
    
    plot_dcl(subset)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    _images/dc1da1782b3f835fdc1c5237890cc5e3ef29cb2730a331ac8457a7b08ea3352e.png
    station
    
    <xarray.Dataset>
    Dimensions:        (depth: 185, latitude: 111, time: 24000)
    Coordinates:
      * latitude       (latitude) float64 -3.075 -3.025 -2.975 ... 5.925 5.975 6.025
      * depth          (depth) float32 -1.25 -3.75 -6.25 ... -5658.0986 -5758.0986
        longitude      float32 -110.025
      * time           (time) datetime64[ns] 1998-12-31T18:00:00 ... 2001-09-26T17:00:00
    Data variables:
        SSH            (time, latitude) float32 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        KPPhbl         (time, latitude) float32 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        u              (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        v              (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        w              (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        theta          (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        salt           (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        DFrI_TH        (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        VISrI_Um       (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        VISrI_Vm       (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        KPPdiffKzT     (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        KPPviscAz      (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        KPPg_TH        (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        Jq             (depth, time, latitude) float64 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        nonlocal_flux  (depth, time, latitude) float64 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        dens           (depth, time, latitude) float32 dask.array<chunksize=(185, 6000, 1), meta=np.ndarray>
        long           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        short          (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        sens           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        lat            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        netflux        (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        stress         (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        taux           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        tauy           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        usr            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        tau            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        hsb            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        hlb            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        hbb            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        hsbb           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        hlwebb         (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        tsr            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        qsr            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        zot            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        zoq            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Cd             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Ch             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Ce             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        L              (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        zet            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        dter           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        dqer           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        tkt            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Urf            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Trf            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Qrf            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        RHrf           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        UrfN           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Rnl            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Le             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        rhoa           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        UN             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        U10            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        U10N           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Cdn_10         (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Chn_10         (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Cen_10         (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        RF             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Qs             (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Evap           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        T10            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        Q10            (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        RH10           (time, latitude) float64 dask.array<chunksize=(6000, 1), meta=np.ndarray>
        huss           (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        psl            (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        tas            (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        uas            (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        vas            (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        prra           (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        rlds           (time, latitude) float64 nan nan nan nan ... nan nan nan nan
        rsds           (time, latitude) float64 nan nan nan nan ... nan nan nan nan
    Attributes:
        title:     Station profile, index (i,j)=(1200,240)
        easting:   longitude
        northing:  latitude
    subset = station.sel(latitude=0, method="nearest").sel(
        depth=slice(-50), time=slice("1999-05-19 00:00", "1999-05-22 00:00")
    )
    
    pump.plot.plot_dcl(subset)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    (<Figure size 1120x1400 with 10 Axes>,
     array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b0a48953e80>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b0a4959ceb8>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b0a4a728b70>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b0a4d50d550>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b0a4bde5ef0>]],
           dtype=object))
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/fab40369a9817294816f41ec274502d849456220658c1600f06ea9e7eff8db4f.png
    station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-200), time=slice("1999-11-21 00:00", "1999-11-23 00:00")
    ).to_zarr("nov-1999-station.zarr", consolidated=True)
    
    subset = station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-50), time=slice("1999-11-21 00:00", "1999-11-23 00:00")
    )
    
    f, ax = pump.plot.plot_dcl(subset)
    ax[0, 0].set_title("(3.5°N, -110°W)")
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    (<Figure size 1120x1400 with 10 Axes>,
     array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b82ac447410>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b82ac711310>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b82ae67c950>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b82ac715390>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b82ac6fec90>]],
           dtype=object))
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/2193aad4f26894d503dc3d282a55f6c72b0a325b5e07f62c0cabc5b89c3e5e60.png
    subset = station.sel(latitude=0, method="nearest").sel(
        depth=slice(-60), time=slice("1999-05-14 12:00", "1999-05-19 12:00")
    )
    
    plot_dcl(subset)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    _images/b2d4561390830bd5449e3fc5da301f91dcfb52b67381d5c1036af79f4b6d1ad1.png
    subset = station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-80), time=slice("1999-10-14", "1999-11-14")
    )
    
    plot_dcl(subset, shear_max=False, zeros_flux=False, lw=1)
    plt.gcf().set_size_inches((10, 8))
    
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-137-49c0a699a7bf> in <module>
          1 subset = station.sel(latitude=3.5, method="nearest").sel(depth=slice(-80), time=slice("1999-10-14", "1999-11-14"))
          2 
    ----> 3 plot_dcl(subset, shear_max=False, zeros_flux=False, lw=1)
          4 plt.gcf().set_size_inches((10,8))
    
    TypeError: plot_dcl() got an unexpected keyword argument 'lw'
    
    station.theta.isel(depth=0).sel(latitude=3.5, method="nearest").sel(
        time=slice("1999-12-14", "2000-01-14")
    ).plot(
        x="time",
    )
    
    [<matplotlib.lines.Line2D at 0x2b2188d085c0>]
    
    _images/415964a9c62469ba4c378aaaafe41ca5c5ea3fb5d64df6ff0a28d81fde9c1897.png
    subset = station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-80), time=slice("1999-10-14", "1999-11-14")
    )
    
    f, axx = plot_dcl(subset, shear_max=False, lw=1, zeros_flux=False)
    f.set_size_inches((11, 8))
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    _images/82f8374a9cdc94368c18aa486dfa5ad17e230991fd60b8871fc498ea443ec464.png
    subset = station.sel(latitude=0, method="nearest").sel(
        depth=slice(-40), time=slice("1999-10-13 12:00", "1999-10-15 12:00")
    )
    
    pump.plot.plot_dcl(subset, shear_max=False)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    (<Figure size 1120x1120 with 8 Axes>,
     array([[<matplotlib.axes._subplots.AxesSubplot object at 0x2b826d6cf210>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b826e5ccfd0>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b826e5d7b10>],
            [<matplotlib.axes._subplots.AxesSubplot object at 0x2b826e5f3a50>]],
           dtype=object))
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/5c77513aa9cb4828104e3e0cb34ab13301c3702e44303c7a541ad62cd6d57612.png
    subset = station.sel(
        depth=slice(-40), time=slice("1999-05-14 12:00", "1999-05-17 12:00")
    )
    
    pump.plot.plot_dcl(subset, shear_max=False)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    <ipython-input-53-3feb20bb07c2> in <module>
          3 )
          4 
    ----> 5 pump.plot.plot_dcl(subset, shear_max=False)
    
    ~/pump/pump/plot.py in plot_dcl(subset, shear_max, zeros_flux, lw, kpp_terms)
        690 
        691     if kpp_terms:
    --> 692         kpp = calc_kpp_hbl(sub)
        693 
        694     f, axx = plt.subplots(
    
    NameError: name 'sub' is not defined
    
    subset = station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-40), time=slice("1999-11-21", "1999-11-22")
    )
    subset
    
    Show/Hide data repr Show/Hide attributes
    xarray.Dataset
      • depth: 16
      • time: 48
      • depth
        (depth)
        float32
        -1.25 -3.75 -6.25 ... -36.25 -38.75
        array([ -1.25,  -3.75,  -6.25,  -8.75, -11.25, -13.75, -16.25, -18.75, -21.25,
               -23.75, -26.25, -28.75, -31.25, -33.75, -36.25, -38.75], dtype=float32)
      • longitude
        ()
        float32
        ...
        array(-110.025, dtype=float32)
      • latitude
        ()
        float64
        3.525
        array(3.5250001)
      • time
        (time)
        datetime64[ns]
        1999-11-21 ... 1999-11-22T23:00:00
        array(['1999-11-21T00:00:00.000000000', '1999-11-21T01:00:00.000000000',
               '1999-11-21T02:00:00.000000000', '1999-11-21T03:00:00.000000000',
               '1999-11-21T04:00:00.000000000', '1999-11-21T05:00:00.000000000',
               '1999-11-21T06:00:00.000000000', '1999-11-21T07:00:00.000000000',
               '1999-11-21T08:00:00.000000000', '1999-11-21T09:00:00.000000000',
               '1999-11-21T10:00:00.000000000', '1999-11-21T11:00:00.000000000',
               '1999-11-21T12:00:00.000000000', '1999-11-21T13:00:00.000000000',
               '1999-11-21T14:00:00.000000000', '1999-11-21T15:00:00.000000000',
               '1999-11-21T16:00:00.000000000', '1999-11-21T17:00:00.000000000',
               '1999-11-21T18:00:00.000000000', '1999-11-21T19:00:00.000000000',
               '1999-11-21T20:00:00.000000000', '1999-11-21T21:00:00.000000000',
               '1999-11-21T22:00:00.000000000', '1999-11-21T23:00:00.000000000',
               '1999-11-22T00:00:00.000000000', '1999-11-22T01:00:00.000000000',
               '1999-11-22T02:00:00.000000000', '1999-11-22T03:00:00.000000000',
               '1999-11-22T04:00:00.000000000', '1999-11-22T05:00:00.000000000',
               '1999-11-22T06:00:00.000000000', '1999-11-22T07:00:00.000000000',
               '1999-11-22T08:00:00.000000000', '1999-11-22T09:00:00.000000000',
               '1999-11-22T10:00:00.000000000', '1999-11-22T11:00:00.000000000',
               '1999-11-22T12:00:00.000000000', '1999-11-22T13:00:00.000000000',
               '1999-11-22T14:00:00.000000000', '1999-11-22T15:00:00.000000000',
               '1999-11-22T16:00:00.000000000', '1999-11-22T17:00:00.000000000',
               '1999-11-22T18:00:00.000000000', '1999-11-22T19:00:00.000000000',
               '1999-11-22T20:00:00.000000000', '1999-11-22T21:00:00.000000000',
               '1999-11-22T22:00:00.000000000', '1999-11-22T23:00:00.000000000'],
              dtype='datetime64[ns]')
      • SSH
        (time)
        float32
        dask.array<chunksize=(48,), meta=np.ndarray>
        Array Chunk
        Bytes 192 B 192 B
        Shape (48,) (48,)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 1
      • KPPhbl
        (time)
        float32
        dask.array<chunksize=(48,), meta=np.ndarray>
        Array Chunk
        Bytes 192 B 192 B
        Shape (48,) (48,)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 1
      • u
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • v
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • w
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • theta
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • salt
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • DFrI_TH
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • VISrI_Um
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • VISrI_Vm
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • KPPdiffKzT
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • KPPviscAz
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • KPPg_TH
        (depth, time)
        float32
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 3.07 kB 3.07 kB
        Shape (16, 48) (16, 48)
        Count 2225 Tasks 1 Chunks
        Type float32 numpy.ndarray
        48 16
      • Jq
        (depth, time)
        float64
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 6.14 kB 6.14 kB
        Shape (16, 48) (16, 48)
        Count 6007 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 16
      • nonlocal_flux
        (depth, time)
        float64
        dask.array<chunksize=(16, 48), meta=np.ndarray>
        Array Chunk
        Bytes 6.14 kB 6.14 kB
        Shape (16, 48) (16, 48)
        Count 3343 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 16
      • long
        (time)
        float64
        dask.array<chunksize=(48,), meta=np.ndarray>
        Array Chunk
        Bytes 384 B 384 B
        Shape (48,) (48,)
        Count 5778 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 1
      • short
        (time)
        float64
        0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0
        array([  0.        ,   0.        ,   0.        ,   0.        ,
                26.67723925,  53.3544785 ,  80.03171775, 234.07998805,
               388.12825834, 542.17652864, 637.58096106, 732.98539349,
               828.38982591, 705.72158814, 583.05335038, 460.38511261,
               313.98412565, 167.5831387 ,  21.18215175,  14.1214345 ,
                 7.06071725,   0.        ,   0.        ,   0.        ,
                 0.        ,   0.        ,   0.        ,   0.        ,
                29.58307234,  59.16614469,  88.74921703, 268.283195  ,
               447.81717296, 627.35115093, 693.29195576, 759.23276058,
               825.17356541, 705.6597719 , 586.1459784 , 466.6321849 ,
               318.92149786, 171.21081082,  23.50012379,  15.66674919,
                 7.8333746 ,   0.        ,   0.        ,   0.        ])
      • sens
        (time)
        float64
        dask.array<chunksize=(48,), meta=np.ndarray>
        Array Chunk
        Bytes 384 B 384 B
        Shape (48,) (48,)
        Count 1093602 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 1
      • lat
        (time)
        float64
        dask.array<chunksize=(48,), meta=np.ndarray>
        Array Chunk
        Bytes 384 B 384 B
        Shape (48,) (48,)
        Count 1093602 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 1
      • random_offset
        ()
        float64
        -12.5
        array(-12.5)
      • netflux
        (time)
        float64
        dask.array<chunksize=(48,), meta=np.ndarray>
        Array Chunk
        Bytes 384 B 384 B
        Shape (48,) (48,)
        Count 1108256 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 1
      • stress
        (time)
        float64
        dask.array<chunksize=(48,), meta=np.ndarray>
        long_name :
        wind stress
        units :
        N/m^2
        Array Chunk
        Bytes 384 B 384 B
        Shape (48,) (48,)
        Count 1093158 Tasks 1 Chunks
        Type float64 numpy.ndarray
        48 1
    • title :
      Station profile, index (i,j)=(1200,240)
      easting :
      longitude
      northing :
      latitude
    subset = station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-40), time=slice("1999-11-21", "1999-11-22")
    )
    
    f, axx = plot_dcl(subset, shear_max=False, lw=1.5)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/f8b03d76e483907ec969e13456ddf205ebb624fb3a0812bca6673b4212780448.png
    station.sel(latitude=3.5, method="nearest").sel(
        time=slice("1999-10-21 11:00", "1999-10-21 18:00"), depth=slice(-100)
    ).v.plot()
    
    <matplotlib.collections.QuadMesh at 0x2ba0c58020d0>
    
    _images/396de4983c9475176109def23a15b8be7754b0c9e334ff9ad7ce74f76ac080e1.png
    station.sel(latitude=3.5, method="nearest").sel(
        time=slice("1999-10-21 11:00", "1999-10-21 18:00"), depth=slice(-100)
    ).KPPdiffKzT.plot(x="time", robust=True, norm=mpl.colors.LogNorm(1e-5, 5e-3))
    
    <matplotlib.collections.QuadMesh at 0x2ba0c335a3d0>
    
    _images/3f1884376f04778b03de4a5916b167afb68a9eaec37ab3d37e22de32a5265bef.png
    (
        station.sel(latitude=3.5, method="nearest")
        .sel(time=slice("1999-10-21 11:00", "1999-10-21 18:00"))
        .KPPdiffKzT.plot.line(
            hue="time", xscale="log", y="depth", ylim=(-100, 0), xlim=(1e-6, None)
        )
    )
    
    [<matplotlib.lines.Line2D at 0x2ba0c59ba790>,
     <matplotlib.lines.Line2D at 0x2ba0c354a110>,
     <matplotlib.lines.Line2D at 0x2ba0c2c365d0>,
     <matplotlib.lines.Line2D at 0x2ba0c3beee10>,
     <matplotlib.lines.Line2D at 0x2ba094f7b290>,
     <matplotlib.lines.Line2D at 0x2ba0c4766c90>,
     <matplotlib.lines.Line2D at 0x2ba0c4766e50>,
     <matplotlib.lines.Line2D at 0x2ba0c4766b90>]
    
    _images/13b328277d8c2952e1459af9e5dbb5e9e42ffc1d488804db058e6c3b849bb8bf.png
    subset = station.sel(latitude=3.5, method="nearest").sel(
        depth=slice(-80), time=slice("1999-11-21", "1999-11-22")
    )
    
    f, axx = plot_dcl(subset, shear_max=False, lw=1)
    axx.flat[-1].set_ylim(-45, 0)
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    (-45.0, 0.0)
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/ab9f7bb616d7bf7ca064bc1a73fdcf54db950d073258a07ff7b849fec7771017.png
    subset.KPPdiffKzT.where(subset.KPPdiffKzT > 0).plot(
        x="time", vmin=1e-4, robust=True, norm=mpl.colors.LogNorm(), cmap=mpl.cm.Spectral_r
    )
    
    <matplotlib.collections.QuadMesh at 0x2ba4dc5bd910>
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/matplotlib/colors.py:1171: RuntimeWarning: invalid value encountered in less_equal
      mask |= resdat <= 0
    
    _images/40bba3f4562c6754e94b86367fcc2841b8981230f746b39d67d5ab9c48ef9222.png
    wind = forcing.sel(latitude=3.5, method="nearest").sel(time=subset.time)[
        ["uas", "vas"]
    ]  # .assign_coords(latitude=xr.full_like(subset.time, 3.5))
    
    
    quiver(wind.expand_dims("latitude"), u="uas", v="vas", x="time", y="latitude")
    quiver(
        subset[["u", "v"]].isel(depth=5).expand_dims("latitude").compute(),
        u="u",
        v="v",
        x="time",
        y="latitude",
        scale=6,
        color="r",
    )
    
    <matplotlib.quiver.Quiver at 0x2aef0f765690>
    
    _images/e5701d73a9ac3cdad0b9a1031e84ae478ef76a0daea460e8b6c8681fedb0fda8.png

    Inferring KPP hbl#

    offeq = (
        station.sel(latitude=3.5, method="nearest")
        .sel(depth=slice(-150), time=slice("1999-11-21", "1999-11-22"))
        .pipe(pump.calc_reduced_shear)
    )
    
    eq = (
        station.sel(latitude=0, method="nearest")
        .sel(depth=slice(-150), time=slice("1999-11-21", "1999-11-22"))
        .pipe(pump.calc_reduced_shear)
    )
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    subset = eq[
        [
            "u",
            "v",
            "theta",
            "salt",
            "tau",
            "usr",
            "uas",
            "vas",
            "netflux",
            "short",
            "KPPhbl",
            "Jq",
            "KPPdiffKzT",
            "taux",
            "tauy",
        ]
    ].compute()
    
    subset_o = offeq[
        [
            "u",
            "v",
            "theta",
            "salt",
            "tau",
            "usr",
            "uas",
            "vas",
            "netflux",
            "short",
            "KPPhbl",
            "Jq",
            "KPPdiffKzT",
            "taux",
            "tauy",
        ]
    ].load()
    
    pump.plot.debug_kpp_plot(subset_o.isel(depth=slice(25), time=slice(240)))
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/core/computation.py:604: RuntimeWarning: divide by zero encountered in log10
      result_data = func(*input_data)
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/plot/plot.py:906: UserWarning: The following kwargs were not used by contour: 'label'
      primitive = ax.contour(x, y, z, **kwargs)
    
    _images/7afbb1fde9b5c991f7863ac9b327290779910c903b74e469d51efa71001f34b9.png
    subset = (
        station.sel(latitude=0, method="nearest")
        .sel(time=slice("1999-05-19", "1999-05-21"))[
            [
                "u",
                "v",
                "theta",
                "salt",
                "tau",
                "usr",
                "uas",
                "vas",
                "netflux",
                "short",
                "KPPhbl",
                "Jq",
                "KPPdiffKzT",
                "taux",
                "tauy",
            ]
        ]
        .load()
    )
    
    pump.plot.debug_kpp_plot(subset.sel(depth=slice(-40)))
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/core/computation.py:604: RuntimeWarning: divide by zero encountered in log10
      result_data = func(*input_data)
    /glade/u/home/dcherian/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/plot/plot.py:906: UserWarning: The following kwargs were not used by contour: 'label'
      primitive = ax.contour(x, y, z, **kwargs)
    
    _images/601af969dea5e185c040a11bd1055fc771310e82cc9cef34d50c3f1d54c6a40f.png
    pump.calc.calc_kpp_terms(subset_o.isel(time=slice(120)), debug=False)
    
    21.562137693168097
    hbl_top = 23.75, hbl_bottom = 21.25
    21.508353306605443
    hbl_top = 23.75, hbl_bottom = 21.25
    21.645652719144437
    hbl_top = 23.75, hbl_bottom = 21.25
    21.71008658196208
    hbl_top = 23.75, hbl_bottom = 21.25
    22.01677270574992
    hbl_top = 23.75, hbl_bottom = 21.25
    21.948488957295535
    hbl_top = 23.75, hbl_bottom = 21.25
    22.08246661873677
    hbl_top = 23.75, hbl_bottom = 21.25
    22.145413632993883
    hbl_top = 23.75, hbl_bottom = 21.25
    22.195302295606304
    hbl_top = 23.75, hbl_bottom = 21.25
    22.066310006841196
    hbl_top = 23.75, hbl_bottom = 21.25
    22.24133188754695
    hbl_top = 23.75, hbl_bottom = 21.25
    22.323145858177032
    hbl_top = 23.75, hbl_bottom = 21.25
    22.054759928208135
    hbl_top = 23.75, hbl_bottom = 21.25
    21.74766525119885
    hbl_top = 23.75, hbl_bottom = 21.25
    21.96514183635163
    hbl_top = 23.75, hbl_bottom = 21.25
    22.06654327265203
    hbl_top = 23.75, hbl_bottom = 21.25
    21.947758413989142
    hbl_top = 23.75, hbl_bottom = 21.25
    21.63542539179921
    hbl_top = 23.75, hbl_bottom = 21.25
    21.819160014704995
    hbl_top = 23.75, hbl_bottom = 21.25
    21.905131451567286
    hbl_top = 23.75, hbl_bottom = 21.25
    21.675680029445495
    hbl_top = 23.75, hbl_bottom = 21.25
    21.399447172041846
    hbl_top = 23.75, hbl_bottom = 21.25
    21.548286334707633
    hbl_top = 23.75, hbl_bottom = 21.25
    21.61795460845824
    hbl_top = 23.75, hbl_bottom = 21.25
    20.37833714859105
    hbl_top = 21.25, hbl_bottom = 18.75
    19.140231830217452
    hbl_top = 21.25, hbl_bottom = 18.75
    19.096249865203298
    hbl_top = 21.25, hbl_bottom = 18.75
    23.382178043646125
    hbl_top = 23.75, hbl_bottom = 21.25
    23.50966158578035
    hbl_top = 23.75, hbl_bottom = 21.25
    23.585500953976588
    hbl_top = 23.75, hbl_bottom = 21.25
    23.175004482337314
    hbl_top = 23.75, hbl_bottom = 21.25
    23.384766310970008
    hbl_top = 23.75, hbl_bottom = 21.25
    23.528257604716416
    hbl_top = 23.75, hbl_bottom = 21.25
    22.072581679580615
    hbl_top = 23.75, hbl_bottom = 21.25
    22.34555184575829
    hbl_top = 23.75, hbl_bottom = 21.25
    22.547326046697705
    hbl_top = 23.75, hbl_bottom = 21.25
    20.566370443381764
    hbl_top = 21.25, hbl_bottom = 18.75
    20.885728731343622
    hbl_top = 21.25, hbl_bottom = 18.75
    21.135747235870983
    hbl_top = 21.25, hbl_bottom = 18.75
    17.714394601459023
    hbl_top = 18.75, hbl_bottom = 16.25
    18.10017036092813
    hbl_top = 18.75, hbl_bottom = 16.25
    18.414005608084878
    hbl_top = 18.75, hbl_bottom = 16.25
    15.924321361017425
    hbl_top = 16.25, hbl_bottom = 13.75
    16.223217566875334
    hbl_top = 16.25, hbl_bottom = 13.75
    16.467129401164126
    hbl_top = 18.75, hbl_bottom = 16.25
    19.072772221913507
    hbl_top = 21.25, hbl_bottom = 18.75
    19.274353175531903
    hbl_top = 21.25, hbl_bottom = 18.75
    19.40389903137693
    hbl_top = 21.25, hbl_bottom = 18.75
    23.00510599628578
    hbl_top = 23.75, hbl_bottom = 21.25
    23.081517310258004
    hbl_top = 23.75, hbl_bottom = 21.25
    25.29325671831957
    hbl_top = 26.25, hbl_bottom = 23.75
    23.0226086847083
    hbl_top = 23.75, hbl_bottom = 21.25
    20.552656354372083
    hbl_top = 21.25, hbl_bottom = 18.75
    18.28252336519945
    hbl_top = 18.75, hbl_bottom = 16.25
    18.779560889008007
    hbl_top = 21.25, hbl_bottom = 18.75
    18.008655349586295
    hbl_top = 18.75, hbl_bottom = 16.25
    19.280331854438167
    hbl_top = 21.25, hbl_bottom = 18.75
    19.309814493463044
    hbl_top = 21.25, hbl_bottom = 18.75
    19.41810992085268
    hbl_top = 21.25, hbl_bottom = 18.75
    18.85041107862146
    hbl_top = 21.25, hbl_bottom = 18.75
    18.960659903799932
    hbl_top = 21.25, hbl_bottom = 18.75
    19.089269173136927
    hbl_top = 21.25, hbl_bottom = 18.75
    17.199039569411184
    hbl_top = 18.75, hbl_bottom = 16.25
    17.34087264407167
    hbl_top = 18.75, hbl_bottom = 16.25
    17.46837905655693
    hbl_top = 18.75, hbl_bottom = 16.25
    16.576202668448467
    hbl_top = 18.75, hbl_bottom = 16.25
    16.72000617012054
    hbl_top = 18.75, hbl_bottom = 16.25
    16.82070902151038
    hbl_top = 18.75, hbl_bottom = 16.25
    14.311303502352393
    hbl_top = 16.25, hbl_bottom = 13.75
    14.449883474952593
    hbl_top = 16.25, hbl_bottom = 13.75
    12.97664444256843
    hbl_top = 13.75, hbl_bottom = 11.25
    12.308063213597052
    hbl_top = 13.75, hbl_bottom = 11.25
    11.629846090776118
    hbl_top = 13.75, hbl_bottom = 11.25
    11.302498463693176
    hbl_top = 13.75, hbl_bottom = 11.25
    11.689271294818639
    hbl_top = 13.75, hbl_bottom = 11.25
    12.551872559607364
    hbl_top = 13.75, hbl_bottom = 11.25
    12.899624972263439
    hbl_top = 13.75, hbl_bottom = 11.25
    15.320320872532465
    hbl_top = 16.25, hbl_bottom = 13.75
    13.266098910964843
    hbl_top = 13.75, hbl_bottom = 11.25
    20.185909412052297
    hbl_top = 21.25, hbl_bottom = 18.75
    20.263276129684527
    hbl_top = 21.25, hbl_bottom = 18.75
    21.451838066266646
    hbl_top = 23.75, hbl_bottom = 21.25
    21.572420735693957
    hbl_top = 23.75, hbl_bottom = 21.25
    21.646085937821635
    hbl_top = 23.75, hbl_bottom = 21.25
    22.099115445591085
    hbl_top = 23.75, hbl_bottom = 21.25
    22.229340914866313
    hbl_top = 23.75, hbl_bottom = 21.25
    22.312718087711616
    hbl_top = 23.75, hbl_bottom = 21.25
    22.356680388175935
    hbl_top = 23.75, hbl_bottom = 21.25
    22.497350973679385
    hbl_top = 23.75, hbl_bottom = 21.25
    22.591083279557186
    hbl_top = 23.75, hbl_bottom = 21.25
    21.9087378738579
    hbl_top = 23.75, hbl_bottom = 21.25
    22.06556794313892
    hbl_top = 23.75, hbl_bottom = 21.25
    22.173620796320574
    hbl_top = 23.75, hbl_bottom = 21.25
    22.669471057444387
    hbl_top = 23.75, hbl_bottom = 21.25
    22.799594958203578
    hbl_top = 23.75, hbl_bottom = 21.25
    22.8833885305723
    hbl_top = 23.75, hbl_bottom = 21.25
    24.208945276986924
    hbl_top = 26.25, hbl_bottom = 23.75
    24.299756917753438
    hbl_top = 26.25, hbl_bottom = 23.75
    24.353854355505064
    hbl_top = 26.25, hbl_bottom = 23.75
    25.84316562291642
    hbl_top = 26.25, hbl_bottom = 23.75
    25.87783520542498
    hbl_top = 26.25, hbl_bottom = 23.75
    26.962273062442545
    hbl_top = 28.75, hbl_bottom = 26.25
    25.19759209741487
    hbl_top = 26.25, hbl_bottom = 23.75
    25.151653710482968
    hbl_top = 26.25, hbl_bottom = 23.75
    25.130125445174507
    hbl_top = 26.25, hbl_bottom = 23.75
    21.668189094329772
    hbl_top = 23.75, hbl_bottom = 21.25
    19.98708492183505
    hbl_top = 21.25, hbl_bottom = 18.75
    20.045446275133962
    hbl_top = 21.25, hbl_bottom = 18.75
    19.427630219412183
    hbl_top = 21.25, hbl_bottom = 18.75
    18.75707976358253
    hbl_top = 21.25, hbl_bottom = 18.75
    18.9889746172224
    hbl_top = 21.25, hbl_bottom = 18.75
    19.599299529504425
    hbl_top = 21.25, hbl_bottom = 18.75
    19.266948848627543
    hbl_top = 21.25, hbl_bottom = 18.75
    19.47056143556383
    hbl_top = 21.25, hbl_bottom = 18.75
    21.684969131391153
    hbl_top = 23.75, hbl_bottom = 21.25
    21.659742256487426
    hbl_top = 23.75, hbl_bottom = 21.25
    21.808345541212656
    hbl_top = 23.75, hbl_bottom = 21.25
    21.877846769970848
    hbl_top = 23.75, hbl_bottom = 21.25
    22.023883452697486
    hbl_top = 23.75, hbl_bottom = 21.25
    22.034244267607754
    hbl_top = 23.75, hbl_bottom = 21.25
    22.157669929831194
    hbl_top = 23.75, hbl_bottom = 21.25
    22.215620204514106
    hbl_top = 23.75, hbl_bottom = 21.25
    21.831126611702437
    hbl_top = 23.75, hbl_bottom = 21.25
    21.86102003826511
    hbl_top = 23.75, hbl_bottom = 21.25
    21.993609792830966
    hbl_top = 23.75, hbl_bottom = 21.25
    22.05571209633549
    hbl_top = 23.75, hbl_bottom = 21.25
    21.572837583359252
    hbl_top = 23.75, hbl_bottom = 21.25
    21.627671765482592
    hbl_top = 23.75, hbl_bottom = 21.25
    21.772180410250826
    hbl_top = 23.75, hbl_bottom = 21.25
    21.83976707521497
    hbl_top = 23.75, hbl_bottom = 21.25
    20.797675805190554
    hbl_top = 21.25, hbl_bottom = 18.75
    20.703021585772692
    hbl_top = 21.25, hbl_bottom = 18.75
    20.989311927329435
    hbl_top = 21.25, hbl_bottom = 18.75
    
    Show/Hide data repr Show/Hide attributes
    xarray.Dataset
      • depth: 60
      • time: 48
      • time
        (time)
        datetime64[ns]
        1999-11-21 ... 1999-11-22T23:00:00
        array(['1999-11-21T00:00:00.000000000', '1999-11-21T01:00:00.000000000',
               '1999-11-21T02:00:00.000000000', '1999-11-21T03:00:00.000000000',
               '1999-11-21T04:00:00.000000000', '1999-11-21T05:00:00.000000000',
               '1999-11-21T06:00:00.000000000', '1999-11-21T07:00:00.000000000',
               '1999-11-21T08:00:00.000000000', '1999-11-21T09:00:00.000000000',
               '1999-11-21T10:00:00.000000000', '1999-11-21T11:00:00.000000000',
               '1999-11-21T12:00:00.000000000', '1999-11-21T13:00:00.000000000',
               '1999-11-21T14:00:00.000000000', '1999-11-21T15:00:00.000000000',
               '1999-11-21T16:00:00.000000000', '1999-11-21T17:00:00.000000000',
               '1999-11-21T18:00:00.000000000', '1999-11-21T19:00:00.000000000',
               '1999-11-21T20:00:00.000000000', '1999-11-21T21:00:00.000000000',
               '1999-11-21T22:00:00.000000000', '1999-11-21T23:00:00.000000000',
               '1999-11-22T00:00:00.000000000', '1999-11-22T01:00:00.000000000',
               '1999-11-22T02:00:00.000000000', '1999-11-22T03:00:00.000000000',
               '1999-11-22T04:00:00.000000000', '1999-11-22T05:00:00.000000000',
               '1999-11-22T06:00:00.000000000', '1999-11-22T07:00:00.000000000',
               '1999-11-22T08:00:00.000000000', '1999-11-22T09:00:00.000000000',
               '1999-11-22T10:00:00.000000000', '1999-11-22T11:00:00.000000000',
               '1999-11-22T12:00:00.000000000', '1999-11-22T13:00:00.000000000',
               '1999-11-22T14:00:00.000000000', '1999-11-22T15:00:00.000000000',
               '1999-11-22T16:00:00.000000000', '1999-11-22T17:00:00.000000000',
               '1999-11-22T18:00:00.000000000', '1999-11-22T19:00:00.000000000',
               '1999-11-22T20:00:00.000000000', '1999-11-22T21:00:00.000000000',
               '1999-11-22T22:00:00.000000000', '1999-11-22T23:00:00.000000000'],
              dtype='datetime64[ns]')
      • latitude
        ()
        float64
        3.525
        array(3.5250001)
      • longitude
        ()
        float32
        -110.025
        array(-110.025, dtype=float32)
      • depth
        (depth)
        float32
        -1.25 -3.75 ... -146.25 -148.75
        array([  -1.25,   -3.75,   -6.25,   -8.75,  -11.25,  -13.75,  -16.25,  -18.75,
                -21.25,  -23.75,  -26.25,  -28.75,  -31.25,  -33.75,  -36.25,  -38.75,
                -41.25,  -43.75,  -46.25,  -48.75,  -51.25,  -53.75,  -56.25,  -58.75,
                -61.25,  -63.75,  -66.25,  -68.75,  -71.25,  -73.75,  -76.25,  -78.75,
                -81.25,  -83.75,  -86.25,  -88.75,  -91.25,  -93.75,  -96.25,  -98.75,
               -101.25, -103.75, -106.25, -108.75, -111.25, -113.75, -116.25, -118.75,
               -121.25, -123.75, -126.25, -128.75, -131.25, -133.75, -136.25, -138.75,
               -141.25, -143.75, -146.25, -148.75], dtype=float32)
      • hbl
        (time)
        float32
        22.5 22.5 22.5 ... 22.5 22.5 20.0
        units :
        m
        long_name :
        KPP boundary layer depth
        array([22.5      , 22.5      , 22.5      , 22.5      , 22.5      ,
               22.5      , 20.       ,  6.381697 ,  4.263205 ,  3.4403372,
                2.9695106,  2.6451426,  3.6016703,  5.0653596,  7.9433293,
               15.794245 , 17.5      , 17.5      , 20.       , 20.       ,
               17.5      , 17.5      , 15.       , 12.5      , 12.5      ,
               12.5      , 12.5      , 12.5      , 12.5      , 12.5      ,
               12.5      ,  7.532503 ,  5.94778  ,  5.227539 ,  4.692258 ,
                4.279661 ,  5.1836925,  6.4958186,  9.302697 , 22.322956 ,
               20.       , 20.       , 20.       , 22.5      , 22.5      ,
               22.5      , 22.5      , 20.       ], dtype=float32)
      • hekman
        (time)
        float32
        nan nan nan nan ... nan nan nan nan
        units :
        m
        long_name :
        Ekman depth
        array([          nan,           nan,           nan,           nan,
                         nan,           nan, 4.5774882e+17, 4.7896335e+17,
               5.0082648e+17, 5.0251086e+17, 5.0428256e+17, 5.0616406e+17,
               5.2138254e+17, 5.3779629e+17, 5.5541012e+17, 5.4295485e+17,
                         nan,           nan,           nan,           nan,
                         nan,           nan,           nan,           nan,
                         nan,           nan,           nan,           nan,
                         nan,           nan, 4.6887079e+17, 5.1898498e+17,
               5.7419720e+17, 5.7926588e+17, 5.8443565e+17, 5.8969482e+17,
               5.8385772e+17, 5.7795458e+17, 5.7205707e+17, 5.6601821e+17,
                         nan,           nan,           nan,           nan,
                         nan,           nan,           nan,           nan],
              dtype=float32)
      • hmonob
        (time)
        float32
        nan nan nan nan ... nan nan nan nan
        units :
        m
        long_name :
        Monin Obukhov length scale
        array([       nan,        nan,        nan,        nan,        nan,
                      nan, 20.855568 ,  6.381697 ,  4.263205 ,  3.4403372,
                2.9695106,  2.6451426,  3.6016703,  5.0653596,  7.9433293,
               15.794245 ,        nan,        nan,        nan,        nan,
                      nan,        nan,        nan,        nan,        nan,
                      nan,        nan,        nan,        nan,        nan,
               22.86214  ,  7.532503 ,  5.94778  ,  5.227539 ,  4.692258 ,
                4.279661 ,  5.1836925,  6.4958186,  9.302697 , 22.322956 ,
                      nan,        nan,        nan,        nan,        nan,
                      nan,        nan,        nan], dtype=float32)
      • hunlimit
        (time)
        float32
        22.5 22.5 22.5 ... 22.5 22.5 20.0
        units :
        m
        long_name :
        KPP boundary layer depth before limiting to min(hekman, hmonob) under stable forcing
        array([22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 20. , 22.5, 22.5, 22.5, 20. ,
               17.5, 17.5, 20. , 22.5, 22.5, 17.5, 17.5, 20. , 20. , 17.5, 17.5,
               15. , 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 20. , 22.5,
               22.5, 22.5, 22.5, 22.5, 25. , 25. , 25. , 20. , 20. , 20. , 22.5,
               22.5, 22.5, 22.5, 20. ], dtype=float32)
      • Rib
        (time, depth)
        float32
        -0.0 -0.0043675723 ... 10.773784
        long_name :
        KPP bulk Ri
        array([[-0.0000000e+00, -4.3675723e-03,  4.2244170e-02, ...,
                 7.7815323e+00,  7.8425851e+00,  7.8425851e+00],
               [-0.0000000e+00, -6.9185831e-03,  3.6911014e-02, ...,
                 7.9089103e+00,  7.9628172e+00,  7.9628172e+00],
               [-0.0000000e+00, -1.2001271e-02,  3.7520770e-02, ...,
                 8.1349211e+00,  8.1810265e+00,  8.1810265e+00],
               ...,
               [-0.0000000e+00,  1.5479587e-03,  6.0123704e-02, ...,
                 1.0430234e+01,  1.0703924e+01,  1.0703924e+01],
               [-0.0000000e+00,  3.2030668e-03,  5.7468832e-02, ...,
                 1.0437504e+01,  1.0726508e+01,  1.0726508e+01],
               [-0.0000000e+00,  1.6819524e-03,  6.5243363e-02, ...,
                 1.0474560e+01,  1.0773784e+01,  1.0773784e+01]], dtype=float32)
      • db
        (time, depth)
        float32
        -0.0 -7.231339e-07 ... 0.0
        long_name :
        KPP bulk Ri Δb
        array([[-0.0000000e+00, -7.2313389e-07,  2.6032822e-05, ...,
                 4.0595579e+00,  4.1478744e+00,  0.0000000e+00],
               [-0.0000000e+00, -1.0847009e-06,  2.2778719e-05, ...,
                 4.0506921e+00,  4.1388516e+00,  0.0000000e+00],
               [-0.0000000e+00, -1.8078348e-06,  2.2778719e-05, ...,
                 4.0408864e+00,  4.1288724e+00,  0.0000000e+00],
               ...,
               [-0.0000000e+00,  3.6156695e-07,  4.6642137e-05, ...,
                 4.2691140e+00,  4.3606405e+00,  0.0000000e+00],
               [-0.0000000e+00,  7.2313389e-07,  4.3388034e-05, ...,
                 4.2715244e+00,  4.3630934e+00,  0.0000000e+00],
               [-0.0000000e+00,  3.6156695e-07,  4.6642137e-05, ...,
                 4.2739353e+00,  4.3653803e+00,  0.0000000e+00]], dtype=float32)
      • dV2
        (time, depth)
        float32
        0.0 4.941014e-05 ... 0.37995458 0.0
        long_name :
        KPP bulk Ri ΔV^2 (resolved)
        array([[0.0000000e+00, 4.9410140e-05, 2.7091338e-04, ..., 4.9504235e-01,
                5.0191677e-01, 0.0000000e+00],
               [0.0000000e+00, 5.0319199e-05, 2.7736116e-04, ..., 4.8523474e-01,
                4.9237049e-01, 0.0000000e+00],
               [0.0000000e+00, 4.8988302e-05, 2.6826747e-04, ..., 4.6952727e-01,
                4.7700959e-01, 0.0000000e+00],
               ...,
               [0.0000000e+00, 6.2482315e-05, 3.4160132e-04, ..., 3.8168761e-01,
                3.7987494e-01, 0.0000000e+00],
               [0.0000000e+00, 5.9221282e-05, 3.2668465e-04, ..., 3.8159496e-01,
                3.7949473e-01, 0.0000000e+00],
               [0.0000000e+00, 5.5920602e-05, 3.1129509e-04, ..., 3.8229433e-01,
                3.7995458e-01, 0.0000000e+00]], dtype=float32)
      • dVt2
        (time, depth)
        float32
        0.00038809222 0.00011615871 ... 0.0
        long_name :
        KPP bulk Ri ΔV_t^2 (unresolved)
        array([[0.00038809, 0.00011616, 0.00034533, ..., 0.02664895, 0.02697443,
                0.        ],
               [0.0003921 , 0.00010646, 0.00033976, ..., 0.02693341, 0.02740182,
                0.        ],
               [0.00039596, 0.00010165, 0.00033883, ..., 0.02720605, 0.0276792 ,
                0.        ],
               ...,
               [0.00041859, 0.00017109, 0.00043417, ..., 0.02761424, 0.02751215,
                0.        ],
               [0.00041561, 0.00016654, 0.0004283 , ..., 0.02765273, 0.02726333,
                0.        ],
               [0.00041283, 0.00015905, 0.0004036 , ..., 0.02573573, 0.02523087,
                0.        ]], dtype=float32)
      • KT
        (time, depth)
        float32
        0.0050009997 0.012616122 ... 1e-06
        array([[5.0009997e-03, 1.2616122e-02, 1.9529518e-02, ..., 1.0000000e-06,
                1.0000000e-06, 1.0000000e-06],
               [5.0009997e-03, 1.2785150e-02, 1.9790806e-02, ..., 1.0000000e-06,
                1.0000000e-06, 1.0000000e-06],
               [5.0009997e-03, 1.2957962e-02, 2.0076469e-02, ..., 1.0000000e-06,
                1.0000000e-06, 1.0000000e-06],
               ...,
               [4.9999743e-03, 1.3126186e-02, 2.0311574e-02, ..., 1.0000000e-06,
                1.0000000e-06, 1.0000000e-06],
               [4.9964371e-03, 1.3064079e-02, 2.0179978e-02, ..., 1.0000000e-06,
                1.0000000e-06, 1.0000000e-06],
               [4.9997200e-03, 1.2097055e-02, 1.8087992e-02, ..., 1.0000000e-06,
                1.0000000e-06, 1.0000000e-06]], dtype=float32)
      • KM
        (time, depth)
        float32
        0.0050999997 0.008073231 ... 1e-04
        array([[5.09999972e-03, 8.07323121e-03, 1.25805112e-02, ...,
                9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
               [5.09999972e-03, 8.12131632e-03, 1.26566077e-02, ...,
                9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
               [5.09999972e-03, 8.18027463e-03, 1.27679305e-02, ...,
                9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
               ...,
               [5.09897433e-03, 8.72506946e-03, 1.35796582e-02, ...,
                9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
               [5.09543717e-03, 8.56258348e-03, 1.32943578e-02, ...,
                9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
               [5.09872008e-03, 8.02413933e-03, 1.21125169e-02, ...,
                9.99999975e-05, 9.99999975e-05, 9.99999975e-05]], dtype=float32)
    h = pump.calc.calc_kpp_terms(subset_o.isel(time=slice(120)))
    
    h.hbl.plot(marker=".")
    oldh.hbl.plot(color="r")
    subset_o.KPPhbl.plot(yincrease=False)
    plt.legend(["with interp", "no interp", "MIT"])
    plt.gcf().savefig("../images/kpp-interp-check.png")
    
    _images/e52f0cdf14cc8390319f636016be67277e5dfaa828d6651d89626b9aed03c10c.png

    KPP boundary layer depth vs Monin Obukhov length vs Rib contour over 20 years.#

    import pump.KPP
    
    kpp = pump.calc.calc_kpp_terms(
        station.sel(latitude=[0, 3.5], method="nearest")
        .sel(time=slice("1999-01-02", "1999-12-30"))
        .chunk({"depth": -1, "time": 1000}),
        debug=False,
    )
    kpp["hmonob"] = kpp.hmonob.where(kpp.hmonob < 100)
    
    kpp.load(scheduler=client)
    
    Show/Hide data repr Show/Hide attributes
    xarray.Dataset
      • depth: 125
      • latitude: 2
      • time: 8712
      • depth
        (depth)
        float32
        -1.25 -3.75 ... -487.70044
        array([  -1.25   ,   -3.75   ,   -6.25   ,   -8.75   ,  -11.25   ,  -13.75   ,
                -16.25   ,  -18.75   ,  -21.25   ,  -23.75   ,  -26.25   ,  -28.75   ,
                -31.25   ,  -33.75   ,  -36.25   ,  -38.75   ,  -41.25   ,  -43.75   ,
                -46.25   ,  -48.75   ,  -51.25   ,  -53.75   ,  -56.25   ,  -58.75   ,
                -61.25   ,  -63.75   ,  -66.25   ,  -68.75   ,  -71.25   ,  -73.75   ,
                -76.25   ,  -78.75   ,  -81.25   ,  -83.75   ,  -86.25   ,  -88.75   ,
                -91.25   ,  -93.75   ,  -96.25   ,  -98.75   , -101.25   , -103.75   ,
               -106.25   , -108.75   , -111.25   , -113.75   , -116.25   , -118.75   ,
               -121.25   , -123.75   , -126.25   , -128.75   , -131.25   , -133.75   ,
               -136.25   , -138.75   , -141.25   , -143.75   , -146.25   , -148.75   ,
               -151.25   , -153.75   , -156.25   , -158.75   , -161.25   , -163.75   ,
               -166.25   , -168.75   , -171.25   , -173.75   , -176.25   , -178.75   ,
               -181.25   , -183.75   , -186.25   , -188.75   , -191.25   , -193.75   ,
               -196.25   , -198.75   , -201.25   , -203.75   , -206.25   , -208.75   ,
               -211.25   , -213.75   , -216.25   , -218.75   , -221.25   , -223.75   ,
               -226.25   , -228.75   , -231.25   , -233.75   , -236.25   , -238.75   ,
               -241.25   , -243.75   , -246.25   , -248.75   , -251.36874, -254.2363 ,
               -257.37625, -260.8145 , -264.5794 , -268.70193, -273.21616, -278.1592 ,
               -283.57184, -289.4987 , -295.98856, -303.0949 , -310.8764 , -319.39716,
               -328.72736, -338.94394, -350.13116, -362.3811 , -375.79474, -390.4827 ,
               -406.56604, -424.17734, -443.4617 , -464.57806, -487.70044],
              dtype=float32)
      • longitude
        ()
        float32
        -110.025
        array(-110.025, dtype=float32)
      • latitude
        (latitude)
        float64
        0.025 3.525
        array([0.025, 3.525])
      • time
        (time)
        datetime64[ns]
        1999-01-02 ... 1999-12-30T23:00:00
        array(['1999-01-02T00:00:00.000000000', '1999-01-02T01:00:00.000000000',
               '1999-01-02T02:00:00.000000000', ..., '1999-12-30T21:00:00.000000000',
               '1999-12-30T22:00:00.000000000', '1999-12-30T23:00:00.000000000'],
              dtype='datetime64[ns]')
      • hbl
        (time, latitude)
        float32
        5.0 10.0 5.0 10.0 ... 30.0 7.5 32.5
        units :
        m
        long_name :
        KPP boundary layer depth
        array([[ 5. , 10. ],
               [ 5. , 10. ],
               [ 5. , 15. ],
               ...,
               [ 7.5, 30. ],
               [ 7.5, 30. ],
               [ 7.5, 32.5]], dtype=float32)
      • hekman
        (time, latitude)
        float32
        nan nan nan nan ... nan nan nan nan
        units :
        m
        long_name :
        Ekman depth
        array([[nan, nan],
               [nan, nan],
               [nan, nan],
               ...,
               [nan, nan],
               [nan, nan],
               [nan, nan]], dtype=float32)
      • hmonob
        (time, latitude)
        float32
        nan nan nan nan ... nan nan nan nan
        units :
        m
        long_name :
        Monin Obukhov length scale
        array([[nan, nan],
               [nan, nan],
               [nan, nan],
               ...,
               [nan, nan],
               [nan, nan],
               [nan, nan]], dtype=float32)
      • hunlimit
        (time, latitude)
        float32
        5.0 10.0 5.0 10.0 ... 30.0 7.5 32.5
        units :
        m
        long_name :
        KPP boundary layer depth before limiting to min(hekman, hmonob) under stable forcing
        array([[ 5. , 10. ],
               [ 5. , 10. ],
               [ 5. , 15. ],
               ...,
               [ 7.5, 30. ],
               [ 7.5, 30. ],
               [ 7.5, 32.5]], dtype=float32)
      • Rib
        (time, latitude, depth)
        float32
        -0.0 0.2503229 ... 235.58582
        long_name :
        KPP bulk Ri
        array([[[-0.0000000e+00,  2.5032291e-01,  4.8184463e-01, ...,
                  8.5198547e+01,  7.9783852e+01,  7.9783852e+01],
                [-0.0000000e+00,  6.3407227e-02,  1.6666980e-01, ...,
                  1.4464644e+02,  1.5555121e+02,  1.5555121e+02]],
        
               [[-0.0000000e+00,  2.1697785e-01,  4.8251191e-01, ...,
                  8.2865799e+01,  7.7752548e+01,  7.7752548e+01],
                [-0.0000000e+00,  2.3602573e-02,  1.5087619e-01, ...,
                  1.4718178e+02,  1.5820285e+02,  1.5820285e+02]],
        
               [[-0.0000000e+00,  2.0862587e-01,  4.8596352e-01, ...,
                  7.9324699e+01,  7.4693375e+01,  7.4693375e+01],
                [-0.0000000e+00,  2.6829834e-03,  7.4484199e-02, ...,
                  1.4657593e+02,  1.5752759e+02,  1.5752759e+02]],
        
               ...,
        
               [[-0.0000000e+00,  1.5106463e-01,  2.1721765e-01, ...,
                  3.3305534e+01,  3.4165131e+01,  3.4165131e+01],
                [-0.0000000e+00, -2.2021918e-02, -1.3400100e-02, ...,
                  2.3884598e+02,  2.4341263e+02,  2.4341263e+02]],
        
               [[-0.0000000e+00,  1.3765422e-01,  2.0930561e-01, ...,
                  3.3610939e+01,  3.4511612e+01,  3.4511612e+01],
                [-0.0000000e+00, -2.6850004e-02, -2.5710473e-02, ...,
                  2.3948860e+02,  2.4501222e+02,  2.4501222e+02]],
        
               [[-0.0000000e+00,  1.3321401e-01,  2.0516455e-01, ...,
                  3.3925499e+01,  3.4867664e+01,  3.4867664e+01],
                [-0.0000000e+00, -2.7953496e-02, -3.2485351e-02, ...,
                  2.2933173e+02,  2.3558582e+02,  2.3558582e+02]]], dtype=float32)
      • db
        (time, latitude, depth)
        float32
        -0.0 0.0002921461 ... 18.329153 0.0
        long_name :
        KPP bulk Ri Δb
        array([[[-0.00000000e+00,  2.92146113e-04,  2.81154457e-03, ...,
                  9.64758301e+00,  1.02288885e+01,  0.00000000e+00],
                [-0.00000000e+00,  1.15701423e-05,  6.94208575e-05, ...,
                  2.16456642e+01,  2.28267021e+01,  0.00000000e+00]],
        
               [[-0.00000000e+00,  1.93799890e-04,  2.28510308e-03, ...,
                  9.60716248e+00,  1.01870747e+01,  0.00000000e+00],
                [-0.00000000e+00,  4.33880359e-06,  6.36357872e-05, ...,
                  2.16410599e+01,  2.28218784e+01,  0.00000000e+00]],
        
               [[-0.00000000e+00,  1.47519313e-04,  1.86857802e-03, ...,
                  9.57851028e+00,  1.01570539e+01,  0.00000000e+00],
                [-0.00000000e+00,  3.61566947e-07,  2.71175213e-05, ...,
                  2.15756779e+01,  2.27569656e+01,  0.00000000e+00]],
        
               ...,
        
               [[-0.00000000e+00,  9.97924799e-05,  5.81399654e-04, ...,
                  1.48661089e+01,  1.56966076e+01,  0.00000000e+00],
                [-0.00000000e+00, -3.25410269e-06, -5.42350426e-06, ...,
                  1.73361778e+01,  1.83598938e+01,  0.00000000e+00]],
        
               [[-0.00000000e+00,  8.53298043e-05,  5.14871324e-04, ...,
                  1.48435965e+01,  1.56708765e+01,  0.00000000e+00],
                [-0.00000000e+00, -4.70037048e-06, -9.76230785e-06, ...,
                  1.73198528e+01,  1.83443890e+01,  0.00000000e+00]],
        
               [[-0.00000000e+00,  7.52059277e-05,  4.62805707e-04, ...,
                  1.48244095e+01,  1.56507730e+01,  0.00000000e+00],
                [-0.00000000e+00, -5.42350426e-06, -1.19317092e-05, ...,
                  1.73048019e+01,  1.83291531e+01,  0.00000000e+00]]],
              dtype=float32)
      • dV2
        (time, latitude, depth)
        float32
        0.0 0.00049714063 ... 0.0
        long_name :
        KPP bulk Ri ΔV^2 (resolved)
        array([[[0.00000000e+00, 4.97140631e-04, 4.21184534e-03, ...,
                 8.76374915e-02, 9.84975249e-02, 0.00000000e+00],
                [0.00000000e+00, 2.31424783e-05, 6.10678326e-05, ...,
                 1.04122072e-01, 1.02895468e-01, 0.00000000e+00]],
        
               [[0.00000000e+00, 2.98121187e-04, 3.22474726e-03, ...,
                 9.06843692e-02, 1.01800725e-01, 0.00000000e+00],
                [0.00000000e+00, 2.88854189e-05, 6.92425747e-05, ...,
                 1.00757688e-01, 9.96746123e-02, 0.00000000e+00]],
        
               [[0.00000000e+00, 1.77986658e-04, 2.44946941e-03, ...,
                 9.58900973e-02, 1.07278921e-01, 0.00000000e+00],
                [0.00000000e+00, 8.93922697e-06, 3.50564369e-05, ...,
                 9.83087644e-02, 9.73211378e-02, 0.00000000e+00]],
        
               ...,
        
               [[0.00000000e+00, 2.94306810e-04, 1.71662017e-03, ...,
                 4.11460787e-01, 4.27512527e-01, 0.00000000e+00],
                [0.00000000e+00, 3.77778924e-05, 1.74939283e-04, ...,
                 6.99972967e-03, 9.26842261e-03, 0.00000000e+00]],
        
               [[0.00000000e+00, 2.84027221e-04, 1.57086982e-03, ...,
                 4.07791436e-01, 4.23078984e-01, 0.00000000e+00],
                [0.00000000e+00, 3.93800074e-05, 1.75155816e-04, ...,
                 7.55817862e-03, 9.58914496e-03, 0.00000000e+00]],
        
               [[0.00000000e+00, 2.54923420e-04, 1.42970495e-03, ...,
                 4.04223919e-01, 4.18756485e-01, 0.00000000e+00],
                [0.00000000e+00, 4.20315264e-05, 1.81414740e-04, ...,
                 8.54127109e-03, 1.03969378e-02, 0.00000000e+00]]], dtype=float32)
      • dVt2
        (time, latitude, depth)
        float32
        0.00014306219 0.00066993636 ... 0.0
        long_name :
        KPP bulk Ri ΔV_t^2 (unresolved)
        array([[[0.00014306, 0.00066994, 0.00162312, ..., 0.02559898,
                 0.02970997, 0.        ],
                [0.0003225 , 0.00015933, 0.00035545, ..., 0.04552326,
                 0.04385172, 0.        ]],
        
               [[0.00014078, 0.00059506, 0.0015111 , ..., 0.02525203,
                 0.02921846, 0.        ],
                [0.00032754, 0.00015494, 0.00035253, ..., 0.04627858,
                 0.04458245, 0.        ]],
        
               [[0.00013828, 0.00052911, 0.00139563, ..., 0.02486057,
                 0.02870441, 0.        ],
                [0.00033144, 0.00012582, 0.00032901, ..., 0.04888919,
                 0.04714222, 0.        ]],
        
               ...,
        
               [[0.00021248, 0.00036629, 0.00095996, ..., 0.03489474,
                 0.03192103, 0.        ],
                [0.00026127, 0.00010999, 0.0002298 , ..., 0.06558336,
                 0.06615862, 0.        ]],
        
               [[0.00020689, 0.00033586, 0.00088903, ..., 0.0338385 ,
                 0.03099648, 0.        ],
                [0.00026154, 0.00013568, 0.00020455, ..., 0.06476197,
                 0.06528218, 0.        ]],
        
               [[0.00020105, 0.00030963, 0.00082607, ..., 0.03274563,
                 0.03010559, 0.        ],
                [0.00026222, 0.00015199, 0.00018588, ..., 0.06691624,
                 0.06740551, 0.        ]]], dtype=float32)
      • KT
        (time, latitude, depth)
        float32
        0.00012966603 ... 1e-06
        array([[[1.29666034e-04, 2.18233955e-03, 9.19872400e-05, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07],
                [5.88858093e-04, 7.83956889e-03, 7.58001441e-03, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07]],
        
               [[1.40170687e-05, 2.16404232e-03, 1.03821752e-04, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07],
                [4.34163306e-03, 8.00566562e-03, 7.86850788e-03, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07]],
        
               [[9.99999997e-07, 2.14412622e-03, 1.17710180e-04, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07],
                [4.95108636e-03, 1.13102421e-02, 1.49047645e-02, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07]],
        
               ...,
        
               [[2.24266201e-03, 4.82293451e-03, 3.10947536e-03, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07],
                [5.00099966e-03, 1.46211786e-02, 2.62511652e-02, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07]],
        
               [[2.71571265e-03, 4.70282603e-03, 3.04097799e-03, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07],
                [5.00099966e-03, 1.45563791e-02, 2.61273608e-02, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07]],
        
               [[2.78192759e-03, 4.58586263e-03, 2.99450336e-03, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07],
                [5.00099966e-03, 1.46936942e-02, 2.76978035e-02, ...,
                 9.99999997e-07, 9.99999997e-07, 9.99999997e-07]]], dtype=float32)
      • KM
        (time, latitude, depth)
        float32
        0.00022866603 ... 1e-04
        array([[[2.28666031e-04, 1.07810984e-03, 1.90987237e-04, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
                [6.87858090e-04, 3.68432608e-03, 3.92221520e-03, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05]],
        
               [[1.13017064e-04, 1.06433465e-03, 2.02821742e-04, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
                [4.44063311e-03, 3.84459435e-03, 4.20552772e-03, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05]],
        
               [[9.99999975e-05, 1.05444994e-03, 2.16710177e-04, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
                [5.05008642e-03, 5.27657289e-03, 7.19794771e-03, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05]],
        
               ...,
        
               [[2.34166207e-03, 3.19488416e-03, 2.35595019e-03, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
                [5.09999972e-03, 9.05576814e-03, 1.57470144e-02, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05]],
        
               [[2.81471270e-03, 3.11372965e-03, 2.30692979e-03, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
                [5.09999972e-03, 9.21308808e-03, 1.60208605e-02, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05]],
        
               [[2.88092764e-03, 3.03988135e-03, 2.28201272e-03, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05],
                [5.09999972e-03, 9.49921738e-03, 1.70747973e-02, ...,
                 9.99999975e-05, 9.99999975e-05, 9.99999975e-05]]], dtype=float32)
    kpp = pump.calc.calc_kpp_terms(
        station.sel(latitude=[3.5], method="nearest")
        .sel(time=slice("1999-01-02", "1999-01-06"))
        .chunk({"depth": -1, "time": 1000}),
        debug=True,
    )
    
    ---------------------------------------------------------------------------
    KeyboardInterrupt                         Traceback (most recent call last)
    <ipython-input-75-276c3fdda056> in <module>
          3     .sel(time=slice("1999-01-02", "1999-01-06"))
          4     .chunk({"depth": -1, "time": 1000}),
    ----> 5     debug=True,
          6 )
    
    ~/pump/pump/calc.py in calc_kpp_terms(station, debug)
       1132     h.dVt2.attrs["long_name"] = "KPP bulk Ri ΔV_t^2 (unresolved)"
       1133     if debug:
    -> 1134         h.hbl.plot()
       1135         # kpp.KPPhbl.plot()
       1136         station.KPPhbl.plot()
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/plot/plot.py in __call__(self, **kwargs)
        444 
        445     def __call__(self, **kwargs):
    --> 446         return plot(self._da, **kwargs)
        447 
        448     @functools.wraps(hist)
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/plot/plot.py in plot(darray, row, col, col_wrap, ax, hue, rtol, subplot_kws, **kwargs)
        162 
        163     """
    --> 164     darray = darray.squeeze().compute()
        165 
        166     plot_dims = set(darray.dims)
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/core/dataarray.py in compute(self, **kwargs)
        826         """
        827         new = self.copy(deep=False)
    --> 828         return new.load(**kwargs)
        829 
        830     def persist(self, **kwargs) -> "DataArray":
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/core/dataarray.py in load(self, **kwargs)
        800         dask.array.compute
        801         """
    --> 802         ds = self._to_temp_dataset().load(**kwargs)
        803         new = self._from_temp_dataset(ds)
        804         self._variable = new._variable
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/xarray/core/dataset.py in load(self, **kwargs)
        652 
        653             # evaluate all the dask arrays simultaneously
    --> 654             evaluated_data = da.compute(*lazy_data.values(), **kwargs)
        655 
        656             for k, data in zip(lazy_data, evaluated_data):
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/dask/base.py in compute(*args, **kwargs)
        435     keys = [x.__dask_keys__() for x in collections]
        436     postcomputes = [x.__dask_postcompute__() for x in collections]
    --> 437     results = schedule(dsk, keys, **kwargs)
        438     return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
        439 
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/distributed/client.py in get(self, dsk, keys, restrictions, loose_restrictions, resources, sync, asynchronous, direct, retries, priority, fifo_timeout, actors, **kwargs)
       2593                     should_rejoin = False
       2594             try:
    -> 2595                 results = self.gather(packed, asynchronous=asynchronous, direct=direct)
       2596             finally:
       2597                 for f in futures.values():
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/distributed/client.py in gather(self, futures, errors, direct, asynchronous)
       1892                 direct=direct,
       1893                 local_worker=local_worker,
    -> 1894                 asynchronous=asynchronous,
       1895             )
       1896 
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/distributed/client.py in sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
        776         else:
        777             return sync(
    --> 778                 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
        779             )
        780 
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/site-packages/distributed/utils.py in sync(loop, func, callback_timeout, *args, **kwargs)
        343     else:
        344         while not e.is_set():
    --> 345             e.wait(10)
        346     if error[0]:
        347         typ, exc, tb = error[0]
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/threading.py in wait(self, timeout)
        550             signaled = self._flag
        551             if not signaled:
    --> 552                 signaled = self._cond.wait(timeout)
        553             return signaled
        554 
    
    ~/miniconda3/envs/dcpy2/lib/python3.7/threading.py in wait(self, timeout)
        298             else:
        299                 if timeout > 0:
    --> 300                     gotit = waiter.acquire(True, timeout)
        301                 else:
        302                     gotit = waiter.acquire(False)
    
    KeyboardInterrupt: 
    
    kpp.hbl.sel(time="1999-01").plot.line(hue="latitude")
    
    [<matplotlib.lines.Line2D at 0x2b543fbe8490>,
     <matplotlib.lines.Line2D at 0x2b543658ad10>]
    
    _images/5ab414e9b72c28c7afaa2e0487aee0417adf5455d7895a6df7a8b46ee94c8eb0.png
    xr.Dataset(
        {"mit": station.KPPhbl.reindex_like(kpp.hbl), "smyth": kpp.hbl}
    ).plot.scatter(x="mit", y="smyth", hue="latitude", hue_style="discrete", s=4)
    dcpy.plots.line45()
    
    _images/e69227c4517f4676af2c4a6221f8127d10285332f17eb4a513a28e71d5d5f336.png
    kpp.hunlimit.hvplot.line() * kpp.hmonob.hvplot.line()
    
    v2 = (
        (station.v.sel(time=dh.time, depth=slice(-100), latitude=slice(-2, 2)) ** 2)
        .mean(["depth", "latitude"])
        .compute()
    )
    v2.attrs["long_name"] = "$v^2$"
    v2
    
    Show/Hide data repr Show/Hide attributes
    xarray.DataArray
    'v'
    • time: 1802
    • 0.011888596 0.012170398 0.015604051 ... 0.024090406 0.023737494
      array([0.0118886 , 0.0121704 , 0.01560405, ..., 0.03052988, 0.02409041,
             0.02373749], dtype=float32)
      • longitude
        ()
        float32
        -110.025
        array(-110.025, dtype=float32)
      • time
        (time)
        datetime64[ns]
        1999-01-03T07:00:00 ... 1999-12-30T08:00:00
        array(['1999-01-03T07:00:00.000000000', '1999-01-03T08:00:00.000000000',
               '1999-01-05T07:00:00.000000000', ..., '1999-12-29T14:00:00.000000000',
               '1999-12-30T07:00:00.000000000', '1999-12-30T08:00:00.000000000'],
              dtype='datetime64[ns]')
    • long_name :
      $v^2$
    v = station.v.sel(time=dh.time, depth=slice(-100), latitude=slice(-2, 2)).compute()
    tiwv = pump.calc.tiw_avg_filter_v(v.sel(latitude=[0], method="nearest"))
    
    /glade/u/home/dcherian/python/xfilter/xfilter/xfilter.py:175: UserWarning: The 'gappy' kwarg is now deprecated.
      warnings.warn("The 'gappy' kwarg is now deprecated.")
    
    tiwv.mean("latitude").plot(x="time")
    v.mean(["latitude", "depth"]).plot(x="time")
    
    [<matplotlib.lines.Line2D at 0x2b0a3540cc18>]
    
    _images/2037fc906924600f87c99b13fcb5e6a861ac612716399550f57c46b4dd9a2258.png
    xfilter.bandpass(
        v.chunk({"time": -1}),
        coord="time",
        freq=[1 / 15, 1 / 50],
        cycles_per="D",
        num_discard=0,
    ).plot()
    
    (array([  27751.,   63152.,   90067.,  218473.,  704834., 1188229.,
             783223.,  270191.,  102573.,   11347.]),
     array([-0.19458834, -0.15993737, -0.1252864 , -0.09063542, -0.05598445,
            -0.02133348,  0.01331749,  0.04796846,  0.08261943,  0.11727041,
             0.15192138]),
     <a list of 10 Patch objects>)
    
    _images/a69ff71c8106f212cc1a08b4a399cb5cb12fe3dd7dc52ceb3b45fbaecb0e8268.png
    station.theta.reindex_like(kpp[["time"]]).isel(
        depth=0, time=slice(None, None, 24)
    ).plot(x="time", robust=True)
    (2 * v2 / v2.max()).plot.line(x="time")
    
    [<matplotlib.lines.Line2D at 0x2b0a355ff0f0>]
    
    _images/58b380beff240b560d4c8b558e081e75d769bac02f89c76357146e776fcd9332.png
    v2.plot.line(hue="latitude")
    
    [<matplotlib.lines.Line2D at 0x2b0a34eb54e0>]
    
    _images/e938086d259ebc6c255f59bbc90ea7e616d3954495d3f48887980e1e8c16935c.png
    dh = kpp.hunlimit - kpp.hmonob
    dh = dh.where(dh > 0, drop=True)
    dh = dh.to_dataset(name="dh").merge(v2)
    dh.dh.plot.hist(bins=100)
    dh["month"] = dh.time.dt.month
    dh = dh.assign_coords(latitude=[0, 3.5])
    dh.dh.attrs["long_name"] = "$H_{0.3} - L_{MO}$"
    
    _images/63d0957fbf64c5dca947b3bdda4fef1d5483a86cc77e530d621eb45f42042759.png
    import seaborn as sns
    
    df = dh.to_dataframe()
    
    sns.catplot(data=df.reset_index(), x="month", y="dh", kind="box", hue="latitude")
    
    <seaborn.axisgrid.FacetGrid at 0x2b0a49b521d0>
    
    _images/67067976688753cdd9ef8bdaeedea4415e43572ef91790846e5afe8dc59a1d7d.png
    dh.sortby("latitude", ascending=False).plot.scatter(
        row="latitude", x="month", y="dh", s=3
    )
    
    <xarray.plot.facetgrid.FacetGrid at 0x2b0a48768240>
    
    _images/145adeb9942aa9563b6887fd1c7d06d24f0dfef3b24618fa067b6738ed907411.png
    kpp.hunlimit.plot.hist()
    kpp.hbl.plot.hist()
    
    (array([3095., 1072., 1050.,  935.,  878.,  586.,  537.,  315.,  187.,
              57.]),
     array([ 1.25 ,  8.125, 15.   , 21.875, 28.75 , 35.625, 42.5  , 49.375,
            56.25 , 63.125, 70.   ], dtype=float32),
     <a list of 10 Patch objects>)
    
    _images/fceee20d2510539b0d7241e8af3190db7aa96e7d1e3b76222778d4dbeba4240c.png

    Debugging: Double check with augmented output#

    exf = xr.open_mfdataset(
        "/glade/scratch/bachman/TPOS_MITgcm_20_year/HOLD/*sfc.nc", parallel=True
    )
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/ipykernel_launcher.py:2: FutureWarning: In xarray version 0.15 the default behaviour of `open_mfdataset`
    will change. To retain the existing behavior, pass
    combine='nested'. To use future default behavior, pass
    combine='by_coords'. See
    http://xarray.pydata.org/en/stable/combining.html#combining-multi
    
      
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/backends/api.py:941: FutureWarning: The datasets supplied have global dimension coordinates. You may want
    to use the new `combine_by_coords` function (or the
    `combine='by_coords'` option to `open_mfdataset`) to order the datasets
    before concatenation. Alternatively, to continue concatenating based
    on the order the datasets are supplied in future, please use the new
    `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset).The datasets supplied require both concatenation and merging. From
    xarray version 0.15 this will operation will require either using the
    new `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset), with a nested list structure such that you can combine
    along the dimensions None. Alternatively if your datasets have global
    dimension coordinates then you can use the new `combine_by_coords`
    function.
      from_openmfds=True,
    
    kpp2 = xr.open_mfdataset(
        "/glade/scratch/bachman/TPOS_MITgcm_20_year/HOLD/*KPP2D.nc",
        chunks=500,
        parallel=True,
        concat_dim="time",
    )
    kpp3 = xr.open_mfdataset(
        "/glade/scratch/bachman/TPOS_MITgcm_20_year/HOLD/*KPP3D.nc",
        chunks=500,
        parallel=True,
        concat_dim="time",
    )
    
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/ipykernel_launcher.py:5: FutureWarning: In xarray version 0.15 the default behaviour of `open_mfdataset`
    will change. To retain the existing behavior, pass
    combine='nested'. To use future default behavior, pass
    combine='by_coords'. See
    http://xarray.pydata.org/en/stable/combining.html#combining-multi
    
      """
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/backends/api.py:941: FutureWarning: Also `open_mfdataset` will no longer accept a `concat_dim` argument.
    To get equivalent behaviour from now on please use the new
    `combine_nested` function instead (or the `combine='nested'` option to
    `open_mfdataset`).The datasets supplied have global dimension coordinates. You may want
    to use the new `combine_by_coords` function (or the
    `combine='by_coords'` option to `open_mfdataset`) to order the datasets
    before concatenation. Alternatively, to continue concatenating based
    on the order the datasets are supplied in future, please use the new
    `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset).The datasets supplied require both concatenation and merging. From
    xarray version 0.15 this will operation will require either using the
    new `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset), with a nested list structure such that you can combine
    along the dimensions None. Alternatively if your datasets have global
    dimension coordinates then you can use the new `combine_by_coords`
    function.
      from_openmfds=True,
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/ipykernel_launcher.py:11: FutureWarning: In xarray version 0.15 the default behaviour of `open_mfdataset`
    will change. To retain the existing behavior, pass
    combine='nested'. To use future default behavior, pass
    combine='by_coords'. See
    http://xarray.pydata.org/en/stable/combining.html#combining-multi
    
      # This is added back by InteractiveShellApp.init_path()
    /glade/u/home/dcherian/miniconda3/envs/dcpy/lib/python3.6/site-packages/xarray/backends/api.py:941: FutureWarning: Also `open_mfdataset` will no longer accept a `concat_dim` argument.
    To get equivalent behaviour from now on please use the new
    `combine_nested` function instead (or the `combine='nested'` option to
    `open_mfdataset`).The datasets supplied have global dimension coordinates. You may want
    to use the new `combine_by_coords` function (or the
    `combine='by_coords'` option to `open_mfdataset`) to order the datasets
    before concatenation. Alternatively, to continue concatenating based
    on the order the datasets are supplied in future, please use the new
    `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset).The datasets supplied require both concatenation and merging. From
    xarray version 0.15 this will operation will require either using the
    new `combine_nested` function (or the `combine='nested'` option to
    open_mfdataset), with a nested list structure such that you can combine
    along the dimensions None. Alternatively if your datasets have global
    dimension coordinates then you can use the new `combine_by_coords`
    function.
      from_openmfds=True,
    
    eq = (
        station.sel(latitude=0, method="nearest")
        .sel(depth=slice(-150))
        .pipe(pump.calc_reduced_shear)[
            [
                "u",
                "v",
                "theta",
                "salt",
                "dens",
                "tau",
                "usr",
                "uas",
                "vas",
                "wind_angle",
                "netflux",
                "short",
                "KPPhbl",
                "taux",
                "tauy",
            ]
        ]
    )
    
    calc uz
    calc vz
    calc S2
    calc N2
    calc shred2
    Calc Ri
    
    aug = xr.merge([kpp2, kpp3])
    aug["time"] = aug.time + pd.Timedelta("23h")
    aug
    kppeq = aug.sel(longitude=eq.longitude, latitude=3.5, method="nearest")  # .load()
    kppeq
    
    Show/Hide data repr Show/Hide attributes
    xarray.Dataset
      • depth: 136
      • time: 169
      • time
        (time)
        datetime64[ns]
        1999-09-08 ... 1999-09-15
        array(['1999-09-08T00:00:00.000000000', '1999-09-08T01:00:00.000000000',
               '1999-09-08T02:00:00.000000000', '1999-09-08T03:00:00.000000000',
               '1999-09-08T04:00:00.000000000', '1999-09-08T05:00:00.000000000',
               '1999-09-08T06:00:00.000000000', '1999-09-08T07:00:00.000000000',
               '1999-09-08T08:00:00.000000000', '1999-09-08T09:00:00.000000000',
               '1999-09-08T10:00:00.000000000', '1999-09-08T11:00:00.000000000',
               '1999-09-08T12:00:00.000000000', '1999-09-08T13:00:00.000000000',
               '1999-09-08T14:00:00.000000000', '1999-09-08T15:00:00.000000000',
               '1999-09-08T16:00:00.000000000', '1999-09-08T17:00:00.000000000',
               '1999-09-08T18:00:00.000000000', '1999-09-08T19:00:00.000000000',
               '1999-09-08T20:00:00.000000000', '1999-09-08T21:00:00.000000000',
               '1999-09-08T22:00:00.000000000', '1999-09-08T23:00:00.000000000',
               '1999-09-09T00:00:00.000000000', '1999-09-09T01:00:00.000000000',
               '1999-09-09T02:00:00.000000000', '1999-09-09T03:00:00.000000000',
               '1999-09-09T04:00:00.000000000', '1999-09-09T05:00:00.000000000',
               '1999-09-09T06:00:00.000000000', '1999-09-09T07:00:00.000000000',
               '1999-09-09T08:00:00.000000000', '1999-09-09T09:00:00.000000000',
               '1999-09-09T10:00:00.000000000', '1999-09-09T11:00:00.000000000',
               '1999-09-09T12:00:00.000000000', '1999-09-09T13:00:00.000000000',
               '1999-09-09T14:00:00.000000000', '1999-09-09T15:00:00.000000000',
               '1999-09-09T16:00:00.000000000', '1999-09-09T17:00:00.000000000',
               '1999-09-09T18:00:00.000000000', '1999-09-09T19:00:00.000000000',
               '1999-09-09T20:00:00.000000000', '1999-09-09T21:00:00.000000000',
               '1999-09-09T22:00:00.000000000', '1999-09-09T23:00:00.000000000',
               '1999-09-10T00:00:00.000000000', '1999-09-10T01:00:00.000000000',
               '1999-09-10T02:00:00.000000000', '1999-09-10T03:00:00.000000000',
               '1999-09-10T04:00:00.000000000', '1999-09-10T05:00:00.000000000',
               '1999-09-10T06:00:00.000000000', '1999-09-10T07:00:00.000000000',
               '1999-09-10T08:00:00.000000000', '1999-09-10T09:00:00.000000000',
               '1999-09-10T10:00:00.000000000', '1999-09-10T11:00:00.000000000',
               '1999-09-10T12:00:00.000000000', '1999-09-10T13:00:00.000000000',
               '1999-09-10T14:00:00.000000000', '1999-09-10T15:00:00.000000000',
               '1999-09-10T16:00:00.000000000', '1999-09-10T17:00:00.000000000',
               '1999-09-10T18:00:00.000000000', '1999-09-10T19:00:00.000000000',
               '1999-09-10T20:00:00.000000000', '1999-09-10T21:00:00.000000000',
               '1999-09-10T22:00:00.000000000', '1999-09-10T23:00:00.000000000',
               '1999-09-11T00:00:00.000000000', '1999-09-11T01:00:00.000000000',
               '1999-09-11T02:00:00.000000000', '1999-09-11T03:00:00.000000000',
               '1999-09-11T04:00:00.000000000', '1999-09-11T05:00:00.000000000',
               '1999-09-11T06:00:00.000000000', '1999-09-11T07:00:00.000000000',
               '1999-09-11T08:00:00.000000000', '1999-09-11T09:00:00.000000000',
               '1999-09-11T10:00:00.000000000', '1999-09-11T11:00:00.000000000',
               '1999-09-11T12:00:00.000000000', '1999-09-11T13:00:00.000000000',
               '1999-09-11T14:00:00.000000000', '1999-09-11T15:00:00.000000000',
               '1999-09-11T16:00:00.000000000', '1999-09-11T17:00:00.000000000',
               '1999-09-11T18:00:00.000000000', '1999-09-11T19:00:00.000000000',
               '1999-09-11T20:00:00.000000000', '1999-09-11T21:00:00.000000000',
               '1999-09-11T22:00:00.000000000', '1999-09-11T23:00:00.000000000',
               '1999-09-12T00:00:00.000000000', '1999-09-12T01:00:00.000000000',
               '1999-09-12T02:00:00.000000000', '1999-09-12T03:00:00.000000000',
               '1999-09-12T04:00:00.000000000', '1999-09-12T05:00:00.000000000',
               '1999-09-12T06:00:00.000000000', '1999-09-12T07:00:00.000000000',
               '1999-09-12T08:00:00.000000000', '1999-09-12T09:00:00.000000000',
               '1999-09-12T10:00:00.000000000', '1999-09-12T11:00:00.000000000',
               '1999-09-12T12:00:00.000000000', '1999-09-12T13:00:00.000000000',
               '1999-09-12T14:00:00.000000000', '1999-09-12T15:00:00.000000000',
               '1999-09-12T16:00:00.000000000', '1999-09-12T17:00:00.000000000',
               '1999-09-12T18:00:00.000000000', '1999-09-12T19:00:00.000000000',
               '1999-09-12T20:00:00.000000000', '1999-09-12T21:00:00.000000000',
               '1999-09-12T22:00:00.000000000', '1999-09-12T23:00:00.000000000',
               '1999-09-13T00:00:00.000000000', '1999-09-13T01:00:00.000000000',
               '1999-09-13T02:00:00.000000000', '1999-09-13T03:00:00.000000000',
               '1999-09-13T04:00:00.000000000', '1999-09-13T05:00:00.000000000',
               '1999-09-13T06:00:00.000000000', '1999-09-13T07:00:00.000000000',
               '1999-09-13T08:00:00.000000000', '1999-09-13T09:00:00.000000000',
               '1999-09-13T10:00:00.000000000', '1999-09-13T11:00:00.000000000',
               '1999-09-13T12:00:00.000000000', '1999-09-13T13:00:00.000000000',
               '1999-09-13T14:00:00.000000000', '1999-09-13T15:00:00.000000000',
               '1999-09-13T16:00:00.000000000', '1999-09-13T17:00:00.000000000',
               '1999-09-13T18:00:00.000000000', '1999-09-13T19:00:00.000000000',
               '1999-09-13T20:00:00.000000000', '1999-09-13T21:00:00.000000000',
               '1999-09-13T22:00:00.000000000', '1999-09-13T23:00:00.000000000',
               '1999-09-14T00:00:00.000000000', '1999-09-14T01:00:00.000000000',
               '1999-09-14T02:00:00.000000000', '1999-09-14T03:00:00.000000000',
               '1999-09-14T04:00:00.000000000', '1999-09-14T05:00:00.000000000',
               '1999-09-14T06:00:00.000000000', '1999-09-14T07:00:00.000000000',
               '1999-09-14T08:00:00.000000000', '1999-09-14T09:00:00.000000000',
               '1999-09-14T10:00:00.000000000', '1999-09-14T11:00:00.000000000',
               '1999-09-14T12:00:00.000000000', '1999-09-14T13:00:00.000000000',
               '1999-09-14T14:00:00.000000000', '1999-09-14T15:00:00.000000000',
               '1999-09-14T16:00:00.000000000', '1999-09-14T17:00:00.000000000',
               '1999-09-14T18:00:00.000000000', '1999-09-14T19:00:00.000000000',
               '1999-09-14T20:00:00.000000000', '1999-09-14T21:00:00.000000000',
               '1999-09-14T22:00:00.000000000', '1999-09-14T23:00:00.000000000',
               '1999-09-15T00:00:00.000000000'], dtype='datetime64[ns]')
      • longitude
        ()
        float32
        -110.00916
        array(-110.00916, dtype=float32)
      • latitude
        ()
        float32
        3.4837093
        array(3.4837093, dtype=float32)
      • depth
        (depth)
        float32
        -1.25 -3.75 ... -881.6718 -944.4181
        array([  -1.25   ,   -3.75   ,   -6.25   ,   -8.75   ,  -11.25   ,  -13.75   ,
                -16.25   ,  -18.75   ,  -21.25   ,  -23.75   ,  -26.25   ,  -28.75   ,
                -31.25   ,  -33.75   ,  -36.25   ,  -38.75   ,  -41.25   ,  -43.75   ,
                -46.25   ,  -48.75   ,  -51.25   ,  -53.75   ,  -56.25   ,  -58.75   ,
                -61.25   ,  -63.75   ,  -66.25   ,  -68.75   ,  -71.25   ,  -73.75   ,
                -76.25   ,  -78.75   ,  -81.25   ,  -83.75   ,  -86.25   ,  -88.75   ,
                -91.25   ,  -93.75   ,  -96.25   ,  -98.75   , -101.25   , -103.75   ,
               -106.25   , -108.75   , -111.25   , -113.75   , -116.25   , -118.75   ,
               -121.25   , -123.75   , -126.25   , -128.75   , -131.25   , -133.75   ,
               -136.25   , -138.75   , -141.25   , -143.75   , -146.25   , -148.75   ,
               -151.25   , -153.75   , -156.25   , -158.75   , -161.25   , -163.75   ,
               -166.25   , -168.75   , -171.25   , -173.75   , -176.25   , -178.75   ,
               -181.25   , -183.75   , -186.25   , -188.75   , -191.25   , -193.75   ,
               -196.25   , -198.75   , -201.25   , -203.75   , -206.25   , -208.75   ,
               -211.25   , -213.75   , -216.25   , -218.75   , -221.25   , -223.75   ,
               -226.25   , -228.75   , -231.25   , -233.75   , -236.25   , -238.75   ,
               -241.25   , -243.75   , -246.25   , -248.75   , -251.36874, -254.2363 ,
               -257.37625, -260.8145 , -264.5794 , -268.70193, -273.21616, -278.1592 ,
               -283.57184, -289.4987 , -295.98856, -303.0949 , -310.8764 , -319.39716,
               -328.72736, -338.94394, -350.13116, -362.3811 , -375.79474, -390.4827 ,
               -406.56604, -424.17734, -443.4617 , -464.57806, -487.70044, -513.0195 ,
               -540.7438 , -571.1019 , -604.3441 , -640.7443 , -680.6025 , -724.2472 ,
               -772.03815, -824.36926, -881.6718 , -944.4181 ], dtype=float32)
      • KPPhbl
        (time)
        float32
        dask.array<chunksize=(1,), meta=np.ndarray>
        Array Chunk
        Bytes 676 B 8 B
        Shape (169,) (2,)
        Count 3874 Tasks 168 Chunks
        Type float32 numpy.ndarray
        169 1
      • KPPfrac
        (time)
        float32
        dask.array<chunksize=(1,), meta=np.ndarray>
        Array Chunk
        Bytes 676 B 8 B
        Shape (169,) (2,)
        Count 3874 Tasks 168 Chunks
        Type float32 numpy.ndarray
        169 1
      • KPPbo
        (time)
        float32
        dask.array<chunksize=(1,), meta=np.ndarray>
        Array Chunk
        Bytes 676 B 8 B
        Shape (169,) (2,)
        Count 3874 Tasks 168 Chunks
        Type float32 numpy.ndarray
        169 1
      • KPPbosol
        (time)
        float32
        dask.array<chunksize=(1,), meta=np.ndarray>
        Array Chunk
        Bytes 676 B 8 B
        Shape (169,) (2,)
        Count 3874 Tasks 168 Chunks
        Type float32 numpy.ndarray
        169 1
      • KPPviscA
        (time, depth)
        float32
        dask.array<chunksize=(1, 136), meta=np.ndarray>
        Array Chunk
        Bytes 91.94 kB 1.09 kB
        Shape (169, 136) (2, 136)
        Count 4044 Tasks 168 Chunks
        Type float32 numpy.ndarray
        136 169
      • KPPdiffT
        (time, depth)
        float32
        dask.array<chunksize=(1, 136), meta=np.ndarray>
        Array Chunk
        Bytes 91.94 kB 1.09 kB
        Shape (169, 136) (2, 136)
        Count 4044 Tasks 168 Chunks
        Type float32 numpy.ndarray
        136 169
      • KPPdbsfc
        (time, depth)
        float32
        dask.array<chunksize=(1, 136), meta=np.ndarray>
        Array Chunk
        Bytes 91.94 kB 1.09 kB
        Shape (169, 136) (2, 136)
        Count 4044 Tasks 168 Chunks
        Type float32 numpy.ndarray
        136 169
      • KPPbfsfc
        (time, depth)
        float32
        dask.array<chunksize=(1, 136), meta=np.ndarray>
        Array Chunk
        Bytes 91.94 kB 1.09 kB
        Shape (169, 136) (2, 136)
        Count 4044 Tasks 168 Chunks
        Type float32 numpy.ndarray
        136 169
      • KPPRi
        (time, depth)
        float32
        dask.array<chunksize=(1, 136), meta=np.ndarray>
        Array Chunk
        Bytes 91.94 kB 1.09 kB
        Shape (169, 136) (2, 136)
        Count 4044 Tasks 168 Chunks
        Type float32 numpy.ndarray
        136 169
      • KPPdbloc
        (time, depth)
        float32
        dask.array<chunksize=(1, 136), meta=np.ndarray>
        Array Chunk
        Bytes 91.94 kB 1.09 kB
        Shape (169, 136) (2, 136)
        Count 4044 Tasks 168 Chunks
        Type float32 numpy.ndarray
        136 169
    kppeq.KPPhbl.load()
    kppeq.KPPRi.load()
    
    Show/Hide data repr Show/Hide attributes
    xarray.DataArray
    'KPPRi'
    • time: 169
    • depth: 136
    • nan -0.072856516 -0.049158316 -0.010265699 ... nan nan nan nan
      array([[            nan, -7.28565156e-02, -4.91583161e-02, ...,
               4.15663185e+01,  4.27496376e+01,  4.35260162e+01],
             [            nan, -9.19454768e-02, -7.40848482e-02, ...,
               4.33817825e+01,  4.47163200e+01,  4.55936394e+01],
             [            nan, -1.04447804e-01, -9.60322767e-02, ...,
               4.47098045e+01,  4.61663933e+01,  4.71218681e+01],
             ...,
             [            nan, -3.40390988e-02, -3.26437652e-02, ...,
               1.78085266e+02,  2.02577866e+02,  2.19549545e+02],
             [            nan, -6.18767738e-02, -7.47275874e-02, ...,
               5.50265236e+01,  5.69808998e+01,  5.80998001e+01],
             [            nan,             nan,             nan, ...,
                          nan,             nan,             nan]], dtype=float32)
      • time
        (time)
        datetime64[ns]
        1999-09-08 ... 1999-09-15
        array(['1999-09-08T00:00:00.000000000', '1999-09-08T01:00:00.000000000',
               '1999-09-08T02:00:00.000000000', '1999-09-08T03:00:00.000000000',
               '1999-09-08T04:00:00.000000000', '1999-09-08T05:00:00.000000000',
               '1999-09-08T06:00:00.000000000', '1999-09-08T07:00:00.000000000',
               '1999-09-08T08:00:00.000000000', '1999-09-08T09:00:00.000000000',
               '1999-09-08T10:00:00.000000000', '1999-09-08T11:00:00.000000000',
               '1999-09-08T12:00:00.000000000', '1999-09-08T13:00:00.000000000',
               '1999-09-08T14:00:00.000000000', '1999-09-08T15:00:00.000000000',
               '1999-09-08T16:00:00.000000000', '1999-09-08T17:00:00.000000000',
               '1999-09-08T18:00:00.000000000', '1999-09-08T19:00:00.000000000',
               '1999-09-08T20:00:00.000000000', '1999-09-08T21:00:00.000000000',
               '1999-09-08T22:00:00.000000000', '1999-09-08T23:00:00.000000000',
               '1999-09-09T00:00:00.000000000', '1999-09-09T01:00:00.000000000',
               '1999-09-09T02:00:00.000000000', '1999-09-09T03:00:00.000000000',
               '1999-09-09T04:00:00.000000000', '1999-09-09T05:00:00.000000000',
               '1999-09-09T06:00:00.000000000', '1999-09-09T07:00:00.000000000',
               '1999-09-09T08:00:00.000000000', '1999-09-09T09:00:00.000000000',
               '1999-09-09T10:00:00.000000000', '1999-09-09T11:00:00.000000000',
               '1999-09-09T12:00:00.000000000', '1999-09-09T13:00:00.000000000',
               '1999-09-09T14:00:00.000000000', '1999-09-09T15:00:00.000000000',
               '1999-09-09T16:00:00.000000000', '1999-09-09T17:00:00.000000000',
               '1999-09-09T18:00:00.000000000', '1999-09-09T19:00:00.000000000',
               '1999-09-09T20:00:00.000000000', '1999-09-09T21:00:00.000000000',
               '1999-09-09T22:00:00.000000000', '1999-09-09T23:00:00.000000000',
               '1999-09-10T00:00:00.000000000', '1999-09-10T01:00:00.000000000',
               '1999-09-10T02:00:00.000000000', '1999-09-10T03:00:00.000000000',
               '1999-09-10T04:00:00.000000000', '1999-09-10T05:00:00.000000000',
               '1999-09-10T06:00:00.000000000', '1999-09-10T07:00:00.000000000',
               '1999-09-10T08:00:00.000000000', '1999-09-10T09:00:00.000000000',
               '1999-09-10T10:00:00.000000000', '1999-09-10T11:00:00.000000000',
               '1999-09-10T12:00:00.000000000', '1999-09-10T13:00:00.000000000',
               '1999-09-10T14:00:00.000000000', '1999-09-10T15:00:00.000000000',
               '1999-09-10T16:00:00.000000000', '1999-09-10T17:00:00.000000000',
               '1999-09-10T18:00:00.000000000', '1999-09-10T19:00:00.000000000',
               '1999-09-10T20:00:00.000000000', '1999-09-10T21:00:00.000000000',
               '1999-09-10T22:00:00.000000000', '1999-09-10T23:00:00.000000000',
               '1999-09-11T00:00:00.000000000', '1999-09-11T01:00:00.000000000',
               '1999-09-11T02:00:00.000000000', '1999-09-11T03:00:00.000000000',
               '1999-09-11T04:00:00.000000000', '1999-09-11T05:00:00.000000000',
               '1999-09-11T06:00:00.000000000', '1999-09-11T07:00:00.000000000',
               '1999-09-11T08:00:00.000000000', '1999-09-11T09:00:00.000000000',
               '1999-09-11T10:00:00.000000000', '1999-09-11T11:00:00.000000000',
               '1999-09-11T12:00:00.000000000', '1999-09-11T13:00:00.000000000',
               '1999-09-11T14:00:00.000000000', '1999-09-11T15:00:00.000000000',
               '1999-09-11T16:00:00.000000000', '1999-09-11T17:00:00.000000000',
               '1999-09-11T18:00:00.000000000', '1999-09-11T19:00:00.000000000',
               '1999-09-11T20:00:00.000000000', '1999-09-11T21:00:00.000000000',
               '1999-09-11T22:00:00.000000000', '1999-09-11T23:00:00.000000000',
               '1999-09-12T00:00:00.000000000', '1999-09-12T01:00:00.000000000',
               '1999-09-12T02:00:00.000000000', '1999-09-12T03:00:00.000000000',
               '1999-09-12T04:00:00.000000000', '1999-09-12T05:00:00.000000000',
               '1999-09-12T06:00:00.000000000', '1999-09-12T07:00:00.000000000',
               '1999-09-12T08:00:00.000000000', '1999-09-12T09:00:00.000000000',
               '1999-09-12T10:00:00.000000000', '1999-09-12T11:00:00.000000000',
               '1999-09-12T12:00:00.000000000', '1999-09-12T13:00:00.000000000',
               '1999-09-12T14:00:00.000000000', '1999-09-12T15:00:00.000000000',
               '1999-09-12T16:00:00.000000000', '1999-09-12T17:00:00.000000000',
               '1999-09-12T18:00:00.000000000', '1999-09-12T19:00:00.000000000',
               '1999-09-12T20:00:00.000000000', '1999-09-12T21:00:00.000000000',
               '1999-09-12T22:00:00.000000000', '1999-09-12T23:00:00.000000000',
               '1999-09-13T00:00:00.000000000', '1999-09-13T01:00:00.000000000',
               '1999-09-13T02:00:00.000000000', '1999-09-13T03:00:00.000000000',
               '1999-09-13T04:00:00.000000000', '1999-09-13T05:00:00.000000000',
               '1999-09-13T06:00:00.000000000', '1999-09-13T07:00:00.000000000',
               '1999-09-13T08:00:00.000000000', '1999-09-13T09:00:00.000000000',
               '1999-09-13T10:00:00.000000000', '1999-09-13T11:00:00.000000000',
               '1999-09-13T12:00:00.000000000', '1999-09-13T13:00:00.000000000',
               '1999-09-13T14:00:00.000000000', '1999-09-13T15:00:00.000000000',
               '1999-09-13T16:00:00.000000000', '1999-09-13T17:00:00.000000000',
               '1999-09-13T18:00:00.000000000', '1999-09-13T19:00:00.000000000',
               '1999-09-13T20:00:00.000000000', '1999-09-13T21:00:00.000000000',
               '1999-09-13T22:00:00.000000000', '1999-09-13T23:00:00.000000000',
               '1999-09-14T00:00:00.000000000', '1999-09-14T01:00:00.000000000',
               '1999-09-14T02:00:00.000000000', '1999-09-14T03:00:00.000000000',
               '1999-09-14T04:00:00.000000000', '1999-09-14T05:00:00.000000000',
               '1999-09-14T06:00:00.000000000', '1999-09-14T07:00:00.000000000',
               '1999-09-14T08:00:00.000000000', '1999-09-14T09:00:00.000000000',
               '1999-09-14T10:00:00.000000000', '1999-09-14T11:00:00.000000000',
               '1999-09-14T12:00:00.000000000', '1999-09-14T13:00:00.000000000',
               '1999-09-14T14:00:00.000000000', '1999-09-14T15:00:00.000000000',
               '1999-09-14T16:00:00.000000000', '1999-09-14T17:00:00.000000000',
               '1999-09-14T18:00:00.000000000', '1999-09-14T19:00:00.000000000',
               '1999-09-14T20:00:00.000000000', '1999-09-14T21:00:00.000000000',
               '1999-09-14T22:00:00.000000000', '1999-09-14T23:00:00.000000000',
               '1999-09-15T00:00:00.000000000'], dtype='datetime64[ns]')
      • longitude
        ()
        float32
        -110.00916
        array(-110.00916, dtype=float32)
      • latitude
        ()
        float32
        3.4837093
        array(3.4837093, dtype=float32)
      • depth
        (depth)
        float32
        -1.25 -3.75 ... -881.6718 -944.4181
        array([  -1.25   ,   -3.75   ,   -6.25   ,   -8.75   ,  -11.25   ,  -13.75   ,
                -16.25   ,  -18.75   ,  -21.25   ,  -23.75   ,  -26.25   ,  -28.75   ,
                -31.25   ,  -33.75   ,  -36.25   ,  -38.75   ,  -41.25   ,  -43.75   ,
                -46.25   ,  -48.75   ,  -51.25   ,  -53.75   ,  -56.25   ,  -58.75   ,
                -61.25   ,  -63.75   ,  -66.25   ,  -68.75   ,  -71.25   ,  -73.75   ,
                -76.25   ,  -78.75   ,  -81.25   ,  -83.75   ,  -86.25   ,  -88.75   ,
                -91.25   ,  -93.75   ,  -96.25   ,  -98.75   , -101.25   , -103.75   ,
               -106.25   , -108.75   , -111.25   , -113.75   , -116.25   , -118.75   ,
               -121.25   , -123.75   , -126.25   , -128.75   , -131.25   , -133.75   ,
               -136.25   , -138.75   , -141.25   , -143.75   , -146.25   , -148.75   ,
               -151.25   , -153.75   , -156.25   , -158.75   , -161.25   , -163.75   ,
               -166.25   , -168.75   , -171.25   , -173.75   , -176.25   , -178.75   ,
               -181.25   , -183.75   , -186.25   , -188.75   , -191.25   , -193.75   ,
               -196.25   , -198.75   , -201.25   , -203.75   , -206.25   , -208.75   ,
               -211.25   , -213.75   , -216.25   , -218.75   , -221.25   , -223.75   ,
               -226.25   , -228.75   , -231.25   , -233.75   , -236.25   , -238.75   ,
               -241.25   , -243.75   , -246.25   , -248.75   , -251.36874, -254.2363 ,
               -257.37625, -260.8145 , -264.5794 , -268.70193, -273.21616, -278.1592 ,
               -283.57184, -289.4987 , -295.98856, -303.0949 , -310.8764 , -319.39716,
               -328.72736, -338.94394, -350.13116, -362.3811 , -375.79474, -390.4827 ,
               -406.56604, -424.17734, -443.4617 , -464.57806, -487.70044, -513.0195 ,
               -540.7438 , -571.1019 , -604.3441 , -640.7443 , -680.6025 , -724.2472 ,
               -772.03815, -824.36926, -881.6718 , -944.4181 ], dtype=float32)
    kppeq.KPPRi.sel(depth=slice(-150)).plot(y="depth", vmin=0.1, center=0.3)
    (-1 * kppeq.KPPhbl).plot()
    
    [<matplotlib.lines.Line2D at 0x2ad5a69346a0>]
    
    _images/74bdb3113dfb3bbb0b910f5557ac96d7ca97658ccf783e8615f550fb5e1ef6c3.png
    eq = eq.sel(time=kppeq.time.values)
    
    itime = 13
    
    subset = eq.isel(time=slice(1, None)).isel(time=itime).sel(depth=slice(-50)).compute()
    
    Rib = KPP.kpp(
        subset.u.values,
        subset.v.values,
        subset.theta.values,
        subset.salt.values,
        subset.depth.values,
        np.arange(0, subset.depth[-1] - 2.5, -2.5),
        subset.taux.values / 1025,
        subset.tauy.values / 1025,
        -(subset.netflux - subset.short).values / 1035 / 3999,
        xr.zeros_like(subset.netflux).values,
        -subset.short.values / 1035 / 3999,
        COR=0,
        hbl=12,
        debug=True,
        r1=0.62,
        amu1=0.6,
        r2=1 - 0.62,
        amu2=20,
        sigma=subset.dens.values - 1000,
        rho0=1035,
    )
    
    plt.figure()
    plt.plot(Rib, subset.depth)
    kppeq.KPPRi.isel(time=itime).sel(depth=slice(-50)).plot(y="depth")
    
    using given sigma
    Net sfc buoyancy flux (without shortwave) : 8.00e-08 m²/s³, Shortwave buoyancy flux: -1.57e-07 m²/s³
    kbl=5, ksl=0
    
    
     surface layer: T=22.981, S=34.409, σ=23.491, Z=-1.250, U=-0.862, V=-0.200
    dV2 = 0.8859959840774536, dVt2 = 0.001069049035243624
    hbl_top = 3.75, hbl_bottom = 1.25
    ustar = 3.391e-03 m/s
    --- hekman: 237385246872857568.00, monin-obukhov: 4.22
    --- hbl before limiting: 2.50
    --- hbl after limiting: 2.50
    kbl=2, ksl=0
    
    
     surface layer: T=22.981, S=34.409, σ=23.491, Z=-1.250, U=-0.862, V=-0.200
    dV2 = 0.8859959840774536, dVt2 = 0.0015779611668915864
    hbl_top = 3.75, hbl_bottom = 1.25
    ustar = 3.391e-03 m/s
    --- hekman: 237385246872857568.00, monin-obukhov: 4.22
    --- hbl before limiting: 2.50
    --- hbl after limiting: 2.50
    kbl=2, ksl=0
    
    
     surface layer: T=22.981, S=34.409, σ=23.491, Z=-1.250, U=-0.862, V=-0.200
    dV2 = 0.8859959840774536, dVt2 = 0.0020708721121411094
    hbl_top = 3.75, hbl_bottom = 1.25
    ustar = 3.391e-03 m/s
    --- hekman: 237385246872857568.00, monin-obukhov: 4.22
    --- hbl before limiting: 2.50
    --- hbl after limiting: 2.50
    
    [<matplotlib.lines.Line2D at 0x2aba11f6f4a8>]
    
    _images/0cdbc74a0244e7d7cf6c9becadd8793917c3930e9d09e03bc48a8ea0751816dd.png _images/6f8ffc04ad3e6a0bed10420ae2019bb8ff45b419a8e3b87a532e851f2310c13c.png
    subset = eq.compute()  # WTF
    
    hbl = xr.apply_ufunc(
        KPP.kpp,
        subset.u,
        subset.v,
        subset.theta,
        subset.salt,
        subset.depth,
        np.arange(0, subset.depth[-1] - 2.5, -2.5),
        subset.taux / 1035,
        subset.tauy / 1035,
        -(subset.netflux - subset.short) / 1035 / 3999,
        xr.zeros_like(subset.netflux),
        -subset.short / 1035 / 3999,
        kwargs=dict(COR=0, hbl=12, debug=False, r1=0.62, amu1=0.6, r2=1 - 0.62, amu2=20),
        vectorize=True,
        input_core_dims=[["depth"]] * 5
        + [["depth2"]]
        + [
            [],
        ]
        * 5,
        # output_core_dims=[["time"]]
    )
    

    Todo#

    1. Compare diffusivities before TIW and after TIW

    2. Compare shear before and after TIW

    3. Does the change in sign of velocity matter at the equator? (usl -u(h)). Is u the same sign in the hbl at the equator too?