Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conda_package/docs/ocean/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ constructs a vertical coordinate for a transect and computes interpolation
weights that can be used in ``interp_mpas_to_transect_nodes()`` to performed
linear interpolation.

The transect is a slice through triangular prisms, one for each edge of each
MPAS cell, with the cell center and the edge's two vertices as corners. Layer
interfaces are computed at cell centers from ``bottomDepth`` and
``layerThickness``. At each vertex, an interface lies at the
kite-area-weighted average of that interface over the adjacent cells in which
it is valid (with a small adjustment where this would put an interface below
the one beneath it). Interfaces vary linearly along each side of a triangle,
so a transect node, where the transect crosses a side, takes a linear
combination of the interfaces at the two ends of that side. Levels that are
valid on only one side of a node end in a vertical wall there.

The function
:py:func:`mpas_tools.ocean.viz.transect.interp_mpas_to_transect_cells()`
interpolates an MPAS-Ocean DataArray to transect cells, keeping constant values
Expand Down
42 changes: 33 additions & 9 deletions conda_package/mpas_tools/ocean/viz/transect/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,18 @@ def _plot_interfaces(
x_int, z_int, color=interface_color, linewidth=linewidth, zorder=2
)

if ssh_color is not None or seafloor_color is not None:
x_seg, z_top, z_bot = _get_top_and_bottom_lines(ds_transect)

if ssh_color is not None:
valid = ds_transect.validNodes.any(dim='nVertNodes')
x_ssh = 1e-3 * ds_transect.dNode.values
z_ssh = ds_transect.ssh.where(valid).values
ax.plot(x_ssh, z_ssh, color=ssh_color, linewidth=linewidth, zorder=4)
ax.plot(
1e-3 * x_seg, z_top, color=ssh_color, linewidth=linewidth, zorder=4
)

if seafloor_color is not None:
valid = ds_transect.validNodes.any(dim='nVertNodes')
x_floor = 1e-3 * ds_transect.dNode.values
z_floor = ds_transect.zSeafloor.where(valid).values
ax.plot(
x_floor,
z_floor,
1e-3 * x_seg,
z_bot,
color=seafloor_color,
linewidth=linewidth,
zorder=5,
Expand All @@ -482,6 +481,31 @@ def _plot_interfaces(
ax.spines['right'].set_linewidth(4 * linewidth)


def _get_top_and_bottom_lines(ds_transect):
"""
Get lines along the top (sea surface or ice draft) and bottom (seafloor)
of the valid layers in each segment, with vertical steps between
segments where the top or bottom layer changes and breaks across
invalid segments
"""
valid = ds_transect.validCells.values
z = ds_transect.zTransectNode.values
d = ds_transect.dNode.values
n_segments, n_half_levels = valid.shape

segments = np.arange(n_segments)
any_valid = valid.any(axis=1)
top = np.argmax(valid, axis=1)
bottom = n_half_levels - np.argmax(valid[:, ::-1], axis=1)

x_seg = np.stack([d[segments], d[segments + 1]], axis=1)
z_top = np.stack([z[segments, top], z[segments + 1, top]], axis=1)
z_bot = np.stack([z[segments, bottom], z[segments + 1, bottom]], axis=1)
z_top[~any_valid, :] = np.nan
z_bot[~any_valid, :] = np.nan
return x_seg.ravel(), z_top.ravel(), z_bot.ravel()


def _plot_outline(
x, z, valid_cells, ax, outline_color, linewidth, epsilon=1e-6
):
Expand Down
Loading
Loading