Fix gradient returning all NaN on SCRIP-derived grids#1533
Conversation
a716a42 to
869903b
Compare
…re face Fixes #1452 — gradient() returned all NaN on SCRIP-derived grids (ne120np4) because _check_face_on_boundary falsely flagged every face as boundary.
869903b to
353f5c6
Compare
jpan84
left a comment
There was a problem hiding this comment.
Thank you for the quick workaround @rajeeja! These changes appear to fix #1452. Using the MVCE I provided there, the output of _compute_gradient() is global array of numerical values (zero NaNs), and the values of d(U200)/dy in units of s^-1 look reasonable:
[<xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(-0.00528834)
Coordinates:
quantile float64 8B 0.0, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(-0.00030125)
Coordinates:
quantile float64 8B 0.1, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(-0.00017363)
Coordinates:
quantile float64 8B 0.2, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(-0.00010098)
Coordinates:
quantile float64 8B 0.3, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(-4.57090395e-05)
Coordinates:
quantile float64 8B 0.4, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(3.17519363e-06)
Coordinates:
quantile float64 8B 0.5, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(5.10507316e-05)
Coordinates:
quantile float64 8B 0.6, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(0.00010479)
Coordinates:
quantile float64 8B 0.7, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(0.00017359)
Coordinates:
quantile float64 8B 0.8, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(0.00029627)
Coordinates:
quantile float64 8B 0.9, <xarray.UxDataArray 'meridional_gradient' ()> Size: 8B
array(0.01029345)
Coordinates:
quantile float64 8B 1.0]
Skip edges with incomplete
edge_face_connectivityin the gradient stencil instead of NaN-ing the entire face. Fixes #1452.The ne120np4 grid in #1452 is a spectral element cubed-sphere mesh read through SCRIP format. UXarray's SCRIP reader deduplicates corner coordinates with exact floating-point comparison, but SE grids compute shared boundary nodes independently per element, so coordinates at element junctions can differ by machine epsilon. This prevents node merging and produces edges that only one face claims, leaving
INT_FILL_VALUEinedge_face_connectivityfor most edges. The boundary check then falsely flags nearly every face and sets the gradient to NaN — exactly what @jpan84 observed (1 non-NaN value out of 777,602 faces).This fix skips those incomplete edges per-edge rather than rejecting the whole face, which is sufficient for exploratory analysis of smooth fields. The proper long-term fix is tolerance-based node deduplication in the SCRIP reader or native SE grid support (#1402).