Skip to content

check_delta

Classes:

Name Description
CheckDelta

Checks for deltas between consecutive values larger than a specified threshold.

Classes#

CheckDelta #

Bases: ThresholdChecker, ABC

Checks for deltas between consecutive values larger than a specified threshold.

Checks the difference between consecutive values and reports a failure if the difference is less than the threshold specified by the value in the attribute provided to this check.

Classes:

Name Description
Parameters

Methods:

Name Description
run

Attributes:

Name Type Description
parameters Parameters

Attributes#

parameters class-attribute instance-attribute #
parameters: Parameters = Parameters()

Classes#

Parameters #

Bases: BaseModel

Attributes:

Name Type Description
dim str

The dimension on which to perform the diff.

Attributes#
dim class-attribute instance-attribute #
dim: str = 'time'

The dimension on which to perform the diff.

Functions#

run #
run(
    dataset: xr.Dataset, variable_name: str
) -> Union[NDArray[np.bool_], None]
Source code in tsdat/qc/checkers/check_delta.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

    data: NDArray[Any] = var_data.data
    axis = var_data.get_axis_num(self.parameters.dim)

    prepend = np.expand_dims(np.take(data, 0, axis=axis), axis=axis)  # type: ignore
    diff: NDArray[Any] = np.absolute(np.diff(data, axis=axis, prepend=prepend))  # type: ignore
    failures = diff > threshold if self.allow_equal else diff >= threshold

    return failures