Skip to content

FIX: Preserve NaN regions in zoom_xarray - #4175

Open
thaliamontreux wants to merge 1 commit into
Unidata:mainfrom
thaliamontreux:fix-frontogenesis-arcsin
Open

thaliamontreux wants to merge 1 commit into
Unidata:mainfrom
thaliamontreux:fix-frontogenesis-arcsin

Conversation

@thaliamontreux

Copy link
Copy Markdown
Contributor

Description

Partially addresses #3672. As diagnosed there by @kgoebber, smooth_contour produces an empty plot because zoom_xarray returns all-NaN when the input contains any NaN -- scipy.ndimage.zoom's spline stencil propagates one NaN across its whole neighborhood.

When NaNs are present, this does a normalized weighted zoom instead: interpolate data with NaNs zeroed and a validity-weight field (1 valid / 0 NaN) at the same spline order, then divide. Non-positive weights (spline overshoot around holes) become NaN. NaN-free input takes the original path unchanged.

Note: the companion frontogenesis NaN issue from that thread no longer reproduces on main -- frontogenesis now computes cos(2*beta) via the 1 - 2*sin(beta)**2 identity rather than arcsin, so no arcsin domain error remains.

Checklist

@thaliamontreux
thaliamontreux requested a review from a team as a code owner October 20, 2026 09:33
@thaliamontreux
thaliamontreux requested review from dopplershift and removed request for a team October 20, 2026 09:33
@thaliamontreux
thaliamontreux force-pushed the fix-frontogenesis-arcsin branch 2 times, most recently from c9168ae to c91ce39 Compare October 24, 2026 23:49
@thaliamontreux
thaliamontreux force-pushed the fix-frontogenesis-arcsin branch from c91ce39 to 5da77a1 Compare October 27, 2026 19:49
scipy.ndimage.zoom's spline interpolation propagates a single NaN
across its whole stencil neighborhood, so data with any missing points
(as produced by e.g. frontogenesis) came back mostly or entirely NaN,
which made smooth_contour plots disappear (Unidata#3672).

When NaNs are present, do a normalized weighted zoom instead:
interpolate the data with NaNs zeroed and a validity-weight field at
the same spline order, then divide, treating non-positive weights
(spline overshoot around holes) as missing.
@thaliamontreux
thaliamontreux force-pushed the fix-frontogenesis-arcsin branch from 5da77a1 to fde681d Compare October 27, 2026 22:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant