validtools

This module implements features for the validation of (numerical) input data.

Module validtools implements the following members:

  • test_equal_shape() Raise a ValueError if the shapes of the objects given as keywords are not equal.

  • test_non_negative() Raise a ValueError if at least one value of the objects given as keywords is negative.


hydpy.auxs.validtools.test_equal_shape(**kwargs) None[source]

Raise a ValueError if the shapes of the objects given as keywords are not equal.

If all shapes are equal, nothing happens:

>>> from hydpy.auxs.validtools import test_equal_shape
>>> test_equal_shape(arr1=numpy.array([1.0, 2.0]),
...                  arr2=numpy.array([3.0, 4.0]),
...                  arr3=numpy.array([5.0, 6.0]))

If at least one shape differs, the following error is raised:

>>> test_equal_shape(arr1=numpy.array([1.0, 2.0]),
...                  arr2=numpy.array([3.0]),
...                  arr3=numpy.array([5.0, 6.0]))
Traceback (most recent call last):
...
ValueError: The shapes of the following objects are not equal: arr1 (2,), arr2 (1,), and arr3 (2,).

For flexibility in the functions application, it is allowed to pass only one array or no arrays at all:

>>> test_equal_shape(arr1=numpy.array([1.0, 2.0]))
>>> test_equal_shape()
hydpy.auxs.validtools.test_non_negative(**kwargs) None[source]

Raise a ValueError if at least one value of the objects given as keywords is negative.

If all values are non negative, nothing happens:

>>> from hydpy.auxs.validtools import test_non_negative
>>> test_non_negative(arr1=numpy.array([1.0, 2.0]),
...                   arr2=numpy.array([3.0, 4.0]),
...                   arr3=numpy.array([5.0, 6.0]))

If at least one value is negative, the following error is raised:

>>> test_non_negative(arr1=numpy.array([1.0, 2.0]),
...                   arr2=numpy.array([-3.0, 4.0]),
...                   arr3=numpy.array([5.0, 6.0]))
Traceback (most recent call last):
...
ValueError: For the following objects, at least one value is negative: arr2.

For flexibility in the functions application, it is allowed to pass no array at all:

>>> test_non_negative()