Skip to content

Compute ocean transect interfaces as slices through triangular prisms - #784

Merged
xylar merged 3 commits into
MPAS-Dev:masterfrom
xylar:fix-transect-edges
Nov 21, 2026
Merged

xylar merged 3 commits into
MPAS-Dev:masterfrom
xylar:fix-transect-edges

Conversation

@xylar

@xylar xylar commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #783

compute_transect() misplaced layer interfaces at transect nodes wherever the cells used at a node have different numbers of layers. It took SSH averaged over all of those cells, minus a cumulative sum of layer thicknesses, but each layer's thickness was averaged only over the cells where that layer is valid. Under ice shelves and on steep slopes this moves interfaces and the seafloor by more than 100 m. On the Filchner–Ronne section from #783, columns of deep cells were drawn up to 145 m too shallow.

With this PR, the transect is a slice through triangular prisms, one per cell edge, with the cell center and the edge's two vertices as corners. These are the triangles mesh_to_triangles() already uses for the horizontal part of the transect.

  • Interfaces at cell centers are built up from bottomDepth using layerThickness.
  • At each vertex, each interface is the kite-area-weighted average of that interface over the adjacent cells where it is valid.
    • In rare cases, this would put an interface below the one beneath it: about 0.025% of vertex interfaces on the E3SM meshes with ice-shelf cavities that were checked.
    • There, that vertex's interfaces are replaced by the closest non-increasing set in the least-squares sense (pool adjacent violators).
  • Interfaces vary linearly along each triangle side. A node, where the transect crosses a side, combines the interfaces at the side's two ends.
  • A level that is valid in only one of the two segments next to a node ends in a vertical wall there.

Other fixes

  • interp_mpas_to_transect_nodes(), used by method='bilinear' in plot_transect():
    • Vertical weights are now linear in z between layer middles, as the docs describe. Before, they were thickness-weighted.
    • Horizontal weights are renormalized over valid cells separately at each end of the triangle side.
  • Land cells (maxLevelCell of 0) in the middle of a transect now give invalid (masked) segments. Before, they failed an assertion.
  • Cell 0 and triangle 0 are no longer treated as invalid.
  • plot_transect() draws the SSH and seafloor lines as steps that follow each segment's valid layers. Before, they were diagonals across empty space.

Compatibility

Output variables and dimensions are unchanged. Two behavior changes:

  • ssh and zSeafloor at a node are the top and bottom of the valid layers in the segments on either side. They are NaN between two invalid segments.
  • Interpolation weights are 0, not NaN, where invalid.

Not in this PR

The transect's end points and bend points are not nodes. Sections start and end where they first and last cross a triangle side, and a bend inside a triangle is drawn straight. Adding these points would change nHorizWeights, which MPAS-Analysis relies on, so that is left for a separate PR.

Testing

New tests in conda_package/tests/test_ocean_viz_transect.py use a planar hex mesh:

  • Random layers: with random layer counts and thicknesses, compute_transect() matches an independent, loop-based implementation of the prism geometry.
  • Flat layers: layers of uniform depth come out flat.
  • Linear in z: interpolating zMid and zInterface to the nodes reproduces the node elevations.
  • Land mid-transect: land cells in the mesh, in the middle of the transect, give masked segments.

The random-layer, linear-in-z and land tests fail on master. Results and before/after plots on the case from #783 are in a comment below.

🤖 Generated with Claude Code

xylar and others added 3 commits November 21, 2026 13:52
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Interfaces at transect nodes were computed as the average SSH minus the
cumulative sum of average layer thicknesses, where SSH was averaged over
all interpolation cells but each layer's thickness only over the cells
where that layer is valid.  Where neighboring cells have different
numbers of layers, this put interfaces (and the seafloor) below the beds
of every cell used at the node.

Now, interfaces are computed at cell centers from the bed up.  At each
vertex (the ends of the triangle side a node lies on), each interface is
the kite-area-weighted average over the cells in which it is valid,
adjusted to be non-increasing with depth where needed.  Interfaces are
then linear between the two ends.  Interpolation weights for fields are
renormalized over valid cells separately at each end, and vertical
weights are now linear in z between layer middles, as documented.

Land cells in the middle of a transect now produce invalid segments
rather than an error, and cell 0 is no longer treated as invalid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SSH and seafloor lines now follow the top and bottom of the valid
layers in each segment, with vertical steps between segments and breaks
across invalid segments, rather than cutting diagonally between nodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xylar

xylar commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Testing

Filchner–Ronne section from #783

Setup:

  • so12to30km mesh with ice-shelf cavities and z-star layers, on Chrysalis.
  • The same 400-point great-circle transect as in Transect interfaces at edges mix in cells that don't share the edge #783.
  • master and this branch run in the same environment.
  • Reference below means an independent, loop-based implementation of the prism geometry, included in the script used for these checks.
master this PR
Interfaces more than 1 cm from the reference 150 of 12,840 (max 145 m) 0 (max 7e-12 m)
Interfaces that increase with depth 0 0
Nodes with zSeafloor below the beds of all cells used at the node 0 0

The same check on a regional subset of an E3SM SOwISC12to60 restart, along the same line:

master this PR
Interfaces more than 1 cm from the reference 757 of 7,028 (max 87 m) 0 (max 3e-12 m)
Nodes with zSeafloor below the beds of all cells used at the node 49 of 270 (max 66 m) 0

What the plots show:

  • Between about 930 and 1005 km, the section runs along the boundary between a row of cells and a row 200–300 m deeper, clipping corners of the deep cells.
  • On master, those cells' columns end 40–145 m above their beds. For example, cell 22357 has its bed at −1665 m but its column ends at −1520 m. The seafloor line is also drawn diagonally across empty space.
  • With this PR, the columns reach within a few meters of their beds. The seafloor line follows the columns, with vertical steps between segments.

Temperature from the initial state:

Grounding zone, master

Grounding zone, this PR

Full section

master

This PR

Other checks

  • QU240 meshes, with and without ice-shelf cavities, on four transects (Drake Passage, Atlantic, Ross Sea, and one across the Pacific that leaves the mesh over land). As on master:
    • Interfaces are finite and non-increasing.
    • Temperature interpolated to the nodes stays within the range of the cells used.
  • Unit tests: test_ocean_viz_transect.py, test_viz_transects.py and test_transects.py pass (19 tests).

Posted by Claude Code on xylar's behalf. The testing and wording above are AI-authored; please check them accordingly.

@xylar
xylar merged commit 52caa61 into MPAS-Dev:master Nov 21, 2026
5 checks passed
@xylar
xylar deleted the fix-transect-edges branch November 21, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transect interfaces at edges mix in cells that don't share the edge

1 participant