libera_utils.io.netcdf.fill_in_dtype#

libera_utils.io.netcdf.fill_in_dtype(fill_value: float | int, dtype: dtype) → ndarray | None#

Return fill_value in dtype, or None when no value of that dtype can equal it.

An integer dtype holds the fill only when it is a whole number within the dtype’s range; any other fill would wrap or truncate onto a valid value, so no stored value is fill. A float fill is cast to the float dtype, which reproduces the stored bit pattern of a sentinel such as the float32 maximum.

Parameters:
  • fill_value (float or int) – The _FillValue sentinel, as declared.

  • dtype (np.dtype) – The dtype the data is stored in, against which the fill is compared.

Returns:

A zero-dimensional array holding the fill in dtype, or None when dtype is an integer dtype and fill_value is not finite, not a whole number, or outside the dtype’s range.

Return type:

np.ndarray or None