Skip to content

Fix SCRIP encode writing NaN into padded corners - #1914

Draft
cmdupuis3 wants to merge 1 commit into
mainfrom
cmd/scrip_nan_corner_padding
Draft

cmdupuis3 wants to merge 1 commit into
mainfrom
cmd/scrip_nan_corner_padding

Conversation

@cmdupuis3

@cmdupuis3 cmdupuis3 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1911

Overview

SCRIP stores corner coordinates rather than node indices and has no fill value for them, so _encode_scrip wrote NaN into the slots of a short face. The reader deduplicates corners into nodes, so that NaN becomes a node of its own: a 5-node grid reloads with n_node 6, one node at NaN/NaN, poisoning every downstream geometry calculation.

Pad instead the way SCRIP itself does, by repeating the last valid corner, and collapse those repeats back to fill values on read. Repeats drop keeping the first occurrence, so winding order survives and a closed ring collapses like a trailing repeat; a cell that would fall below three vertices is degenerate in the source file and is left visible rather than packed into a face no polygon routine can use.

Also adds TestIOWriteRoundTrip, covering all four writable formats: the encoders share a family of padding bugs that raise nothing and simply grow the mesh, so these assert on the reloaded topology rather than on the write succeeding. The esmf and exodus cases depend on the other fixes in this series: the Exodus face-order cases are marked strict xfail here, so the suite stays green until that fix lands and then forces the marker out.

Adapted to the reader as it now stands. The SCRIP dedup can stay lazy (dask, with chunks=), so the collapse is a Numba kernel run per block that keeps the connectivity lazy, and runs in place on the eager path to avoid a connectivity-sized copy. Corners missing from the file (NaN, from files written before this fix) are now marked INT_FILL_VALUE rather than -1, and the collapse skips fill slots: a -1 would otherwise pass through as a valid node index that wraps to the last node.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)

AI Disclosure

AI Usage: Claude Opus 5.5

  • I have tested and take responsibility for all AI-generated content in my PR.

SCRIP stores corner coordinates rather than node indices and has no fill
value for them, so `_encode_scrip` wrote NaN into the slots of a
short face. The reader deduplicates corners into nodes, so that NaN
becomes a node of its own: a 5-node grid reloads with `n_node` 6, one node
at NaN/NaN, poisoning every downstream geometry calculation.

Pad instead the way SCRIP itself does, by repeating the last valid corner,
and collapse those repeats back to fill values on read. Repeats drop keeping
the first occurrence, so winding order survives and a closed ring collapses
like a trailing repeat; a cell that would fall below three vertices is
degenerate in the source file and is left visible rather than packed into a
face no polygon routine can use.

Also adds `TestIOWriteRoundTrip`, covering all four writable formats: the
encoders share a family of padding bugs that raise nothing and simply grow
the mesh, so these assert on the reloaded topology rather than on the write
succeeding. The esmf and exodus cases depend on the other fixes in this
series: the Exodus face-order cases are marked strict xfail here, so the
suite stays green until that fix lands and then forces the marker out.

Adapted to the reader as it now stands. The SCRIP dedup can stay lazy
(dask, with chunks=), so the collapse is a Numba kernel run per block that
keeps the connectivity lazy, and runs in place on the eager path to avoid a
connectivity-sized copy. Corners missing from the file (NaN, from files
written before this fix) are now marked INT_FILL_VALUE rather than -1, and the
collapse skips fill slots: a -1 would otherwise pass through as a valid node
index that wraps to the last node.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cmdupuis3 cmdupuis3 self-assigned this Nov 20, 2026
@cmdupuis3 cmdupuis3 added bug Something isn't working accuracy Related to mathematical accuracy of operations, such as numerical precision or rounding errors labels Nov 20, 2026
@cmdupuis3
cmdupuis3 requested a review from rajeeja November 20, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accuracy Related to mathematical accuracy of operations, such as numerical precision or rounding errors bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCRIP encode writes NaN into padded corners, leaving an extra NaN node on read

1 participant