Skip to content

check_std

Classes:

Name Description
CheckStd

Checks data for elements greater than a specified number of standard deviations

Classes#

CheckStd #

Bases: ThresholdChecker, ABC

Checks data for elements greater than a specified number of standard deviations away from the mean.

The value of the threshold is specified by an attribute on each data variable, and the attribute to search for is specified as a property of this base class.

If the specified attribute does not exist on the variable being checked then no failures will be reported.

Methods:

Name Description
run

Functions#

run #
run(
    dataset: xr.Dataset, variable_name: str
) -> Union[NDArray[np.bool_], None]
Source code in tsdat/qc/checkers/check_std.py
def run(
    self,
    dataset: xr.Dataset,
    variable_name: str,
) -> Union[NDArray[np.bool_], None]:

    var_data = dataset[variable_name]
    if hasattr(var_data, "_FillValue"):
        var_data = var_data.where(
            dataset[variable_name] != dataset[variable_name]._FillValue
        )
    failures: NDArray[np.bool_] = np.zeros_like(var_data, dtype=np.bool_)  # type: ignore

    threshold = self._get_threshold(dataset, variable_name, True)
    if threshold is None:
        return None

    std_dev = var_data.std(dim="time", ddof=1)
    mean = var_data.mean(dim="time")
    failures = (var_data > mean + std_dev * threshold).values

    return failures