Skip to content

FIX: Preserve masks in saturation pressure/mixing ratio selection - #4169

Open
thaliamontreux wants to merge 1 commit into
Unidata:mainfrom
thaliamontreux:fix-masked-saturation
Open

thaliamontreux wants to merge 1 commit into
Unidata:mainfrom
thaliamontreux:fix-masked-saturation

Conversation

@thaliamontreux

Copy link
Copy Markdown

Description Of Changes

Masked temperatures produce finite, meaningless values from saturation_vapor_pressure(..., phase='auto') and saturation_mixing_ratio because both selection sites use np.where, which evaluates on plain arrays and silently drops the input mask. Explicit phase='liquid'/'solid' and the composed mixing_ratio(saturation_vapor_pressure(t), p) path preserve masks correctly.

Both sites now select with np.ma.where, which propagates masks from the condition and the selected operand, converting back to a plain ndarray when nothing ended up masked (the same convention as units.concatenate). Unmasked inputs are unchanged — same values, same type.

Fixes #4154.

Checklist

  • Tests added
  • Fully documented

The phase='auto' branch of saturation_vapor_pressure and the undefined-
state branch of saturation_mixing_ratio both selected results with
np.where, which evaluates on plain arrays and silently drops any mask
carried by the inputs. A masked (missing) temperature therefore produced
a finite, meaningless humidity or pressure instead of staying masked.

Switch both sites to np.ma.where so masks on the condition and the
selected operand propagate, converting back to a plain array when
nothing ended up masked (matching the convention in units.concatenate).

Fixes Unidata#4154
@thaliamontreux
thaliamontreux requested a review from a team as a code owner October 20, 2026 07:39
@thaliamontreux
thaliamontreux requested review from dopplershift and removed request for a team October 20, 2026 07:39
@thaliamontreux

Copy link
Copy Markdown
Author

Note for reviewers: the three failing macOS legs are pre-existing on main (see the latest Nightly run on 7910b5c, which fails the same jobs). This is #4148 -- image-test warnings (max_open_warning / shapely create_collection) promoted to errors on the conda macOS envs -- and is addressed by #4170. No part of this diff is responsible; the identical jobs pass on #4147 which carries the filter fix.

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