act.utils.get_missing_value#

act.utils.get_missing_value(ds, variable, default=-9999, add_if_missing_in_ds=False, use_FillValue=False, nodefault=False)[source]#

Function to get missing value from missing_value or _FillValue attribute. Works well with catching errors and allows for a default value when a missing value is not listed in the dataset. You may get strange results becaus xarray will automatically convert all missing_value or _FillValue to NaN and then remove the missing_value and _FillValue variable attribute when reading data with default settings.

Parameters:
  • ds (xarray.Dataset) – Xarray dataset containing data variable.

  • variable (str) – Variable name to use for getting missing value.

  • default (int or float) – Default value to use if missing value attribute is not in dataset.

  • add_if_missing_in_ds (bool) – Boolean to add to the dataset if does not exist. Default is False.

  • use_FillValue (bool) – Boolean to use _FillValue instead of missing_value. If missing_value does exist and _FillValue does not will add _FillValue set to missing_value value.

  • nodefault (bool) – Option to use this to check if the varible has a missing value set and do not want to get default as return. If the missing value is found will return, else will return None.

Returns:

missing (scalar int or float (or None)) – Value used to indicate missing value matching type of data or None if nodefault keyword set to True.

Examples

from act.utils import get_missing_value

missing = get_missing_value(dq_ds, "temp_mean")
print(missing)
-9999.0