libera_utils.io.netcdf.apply_fill_and_valid_range#
- libera_utils.io.netcdf.apply_fill_and_valid_range(raw: ndarray, fill_value: float | int | None = None, valid_range: tuple[float, float] | None = None) ndarray#
Return
rawas float64 with fill / out-of-range values set toNaN.netCDF variables flag missing data in two ways that must both be honored: an explicit
_FillValuesentinel (e.g.-999.0for a float field,32767for int16) and avalid_rangeattribute outside of which values are invalid. The fill comparison is made on the raw array, in its own dtype, before any cast, so an integer sentinel that float32 cannot represent exactly still matches. A fill the raw integer dtype cannot hold (-999onuint8,1.5onint16) matches nothing, rather than wrapping onto a valid value.- Parameters:
raw (np.ndarray) – Raw values read from the file. May be a
numpy.ma.MaskedArray.fill_value (float or int, optional) – Sentinel value to treat as missing, compared in the raw dtype.
Noneskips the fill check.valid_range (tuple of (float, float), optional) – Inclusive
(low, high)bounds; values outside are set toNaN. The order is normalized internally, so(1100, 10)is treated the same as(10, 1100).Noneskips the range check.
- Returns:
float64 array, same shape as
raw, with invalid entries asNaN.- Return type:
np.ndarray