Fix ESMF encode truncating the fill value into a valid node index - #1744
Open
cmdupuis3 wants to merge 1 commit into
Open
Fix ESMF encode truncating the fill value into a valid node index#1744cmdupuis3 wants to merge 1 commit into
cmdupuis3 wants to merge 1 commit into
Conversation
`_encode_esmf` applied the 0-based to 1-based offset to the whole connectivity array, padding included, and `elementConn` is encoded as int32. `INT_FILL_VALUE + 1` is `-2**63 + 1`, which the narrowing truncates to `1`: every padded slot lands on disk as node 0. Nothing raises. The file is well formed, so any reader -- including this one -- takes those slots for real vertices, giving faces spurious extra nodes and incorrect polygons. Offset only the valid indices and write ESMF's own -1 into the padding. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
cmdupuis3
marked this pull request as ready for review
September 11, 2026 18:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1745
Overview
_encode_esmf applies the UGRID→ESMF index offset to the whole face_node_connectivity array, padding included, and then encodes elementConn as int32. INT_FILL_VALUE + 1 is -2**63 + 1, and narrowing that to int32 truncates it to 1, so every padded slot of a ragged mesh is written to disk as node 0.
Nothing raises, and the resulting file is structurally valid, so any reader — including uxarray's own — takes those slots for real vertices. Faces gain spurious extra nodes and produce incorrect polygons. This is the case that originally surfaced this family of bugs.
The fix offsets only the valid indices and writes ESMF's own -1 into the padding, which is what the variable's _FillValue attribute already advertises. The test asserts on the encoded array and on what lands on disk after the int32 narrowing, rather than on a round trip: a round trip can hide an encode bug when the reader's inverse offset happens to cancel it.
PR Checklist
General
Testing & Benchmarking
Documentation and Examples
AI Disclosure
AI Usage: Claude Opus 5