def trim(self: 'Variable', lower=None, upper=None) -> None:
    """Trim the value(s) of a |Variable| instance.

    Usually, users do not need to apply function |trim| directly.
    Instead, some |Variable| subclasses implement their own `trim`
    methods relying on function |trim|.  Model developers should
    implement individual `trim` methods for their |Parameter| or
    |Sequence| subclasses when their boundary values depend on the
    actual project configuration (one example is soil moisture;
    its lowest possible value should possibly be zero in all cases,
    but its highest possible value could depend on another parameter
    defining the maximum storage capacity).

    For the following examples, we prepare a simple (not fully
    functional) |Variable| subclass, making use of function |trim|
    without any modifications.  Function |trim| works slightly
    different for variables handling |float|, |int|, and |bool|
    values.  We start with the most common content type |float|:

    >>> from hydpy.core.variabletools import trim, Variable
    >>> class Var(Variable):
    ...     NDIM = 0
    ...     TYPE = float
    ...     SPAN = 1.0, 3.0
    ...     trim = trim
    ...     initinfo = 2.0, False
    ...     __hydpy__connect_variable2subgroup__ = None

    First, we enable the printing of warning messages raised by function
    |trim|:

    >>> from hydpy import pub
    >>> pub.options.warntrim = True

    When not passing boundary values, function |trim| extracts them from
    class attribute `SPAN` of the given |Variable| instance, if available:

    >>> var = Var(None)
    >>> var.value = 2.0
    >>> var.trim()
    >>> var
    var(2.0)

    >>> var.value = 0.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `0.0` and `1.0`, respectively.
    >>> var
    var(1.0)

    >>> var.value = 4.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `4.0` and `3.0`, respectively.
    >>> var
    var(3.0)

    In the examples above, outlier values are set to the respective
    boundary value, accompanied by suitable warning messages.  For very
    tiny deviations, which might be due to precision problems only,
    outliers are trimmed but not reported:

    >>> var.value = 1.0 - 1e-15
    >>> var == 1.0
    False
    >>> trim(var)
    >>> var == 1.0
    True

    >>> var.value = 3.0 + 1e-15
    >>> var == 3.0
    False
    >>> var.trim()
    >>> var == 3.0
    True

    Use arguments `lower` and `upper` to override the (eventually)
    available `SPAN` entries:

    >>> var.trim(lower=4.0)
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `3.0` and `4.0`, respectively.

    >>> var.trim(upper=3.0)
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `4.0` and `3.0`, respectively.

    Function |trim| interprets both |None| and |numpy.nan| values as if
    no boundary value exists:

    >>> import numpy
    >>> var.value = 0.0
    >>> var.trim(lower=numpy.nan)
    >>> var.value = 5.0
    >>> var.trim(upper=numpy.nan)

    You can disable function |trim| via option |Options.trimvariables|:

    >>> with pub.options.trimvariables(False):
    ...     var.value = 5.0
    ...     var.trim()
    >>> var
    var(5.0)

    Alternatively, you can omit the warning messages only:

    >>> with pub.options.warntrim(False):
    ...     var.value = 5.0
    ...     var.trim()
    >>> var
    var(3.0)

    If a |Variable| subclass does not have (fixed) boundaries, give it
    either no `SPAN` attribute or a |tuple| containing |None| values:

    >>> del Var.SPAN
    >>> var.value = 5.0
    >>> var.trim()
    >>> var
    var(5.0)

    >>> Var.SPAN = (None, None)
    >>> var.trim()
    >>> var
    var(5.0)

    The above examples deal with a 0-dimensional |Variable| subclass.
    The following examples repeat the most relevant examples for a
    2-dimensional subclass:

    >>> Var.SPAN = 1.0, 3.0
    >>> Var.NDIM = 2
    >>> var.shape = 1, 3
    >>> var.values = 2.0
    >>> var.trim()

    >>> var.values = 0.0, 1.0, 2.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 0.  1.  2.]]` and `[[ 1.  1.  2.]]`, \
respectively.
    >>> var
    var([[1.0, 1.0, 2.0]])

    >>> var.values = 2.0, 3.0, 4.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 2.  3.  4.]]` and `[[ 2.  3.  3.]]`, \
respectively.
    >>> var
    var([[2.0, 3.0, 3.0]])

    >>> var.values = 1.0-1e-15, 2.0, 3.0+1e-15
    >>> var.values == (1.0, 2.0, 3.0)
    array([[False,  True, False]], dtype=bool)
    >>> var.trim()
    >>> var.values == (1.0, 2.0, 3.0)
    array([[ True,  True,  True]], dtype=bool)

    >>> var.values = 0.0, 2.0, 4.0
    >>> var.trim(lower=numpy.nan, upper=numpy.nan)
    >>> var
    var([[0.0, 2.0, 4.0]])

    >>> var.trim(lower=[numpy.nan, 3.0, 3.0])
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 0.  2.  4.]]` and `[[ 0.  3.  3.]]`, \
respectively.

    >>> var.values = 0.0, 2.0, 4.0
    >>> var.trim(upper=[numpy.nan, 1.0, numpy.nan])
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 0.  2.  4.]]` and `[[ 1.  1.  4.]]`, \
respectively.

    For |Variable| subclasses handling |float| values, setting outliers
    to the respective boundary value might often be an acceptable approach.
    However, this is often not the case for subclasses handling |int|
    values, which often serve as option flags (e.g. to enable/disable
    a certain hydrological process for different land-use types). Hence,
    function |trim| raises an exception instead of a warning and does
    not modify the wrong |int| value:

    >>> Var.TYPE = int
    >>> Var.NDIM = 0
    >>> Var.SPAN = 1, 3

    >>> var.value = 2
    >>> var.trim()
    >>> var
    var(2)

    >>> var.value = 0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `0` of parameter `var` of element `?` is not valid.
    >>> var
    var(0)
    >>> var.value = 4
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `4` of parameter `var` of element `?` is not valid.
    >>> var
    var(4)

    >>> from hydpy import INT_NAN
    >>> var.value = 0
    >>> var.trim(lower=0)
    >>> var.trim(lower=INT_NAN)

    >>> var.value = 4
    >>> var.trim(upper=4)
    >>> var.trim(upper=INT_NAN)

    >>> Var.SPAN = 1, None
    >>> var.value = 0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `0` of parameter `var` of element `?` is not valid.
    >>> var
    var(0)

    >>> Var.SPAN = None, 3
    >>> var.value = 0
    >>> var.trim()
    >>> var.value = 4
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `4` of parameter `var` of element `?` is not valid.

    >>> del Var.SPAN
    >>> var.value = 0
    >>> var.trim()
    >>> var.value = 4
    >>> var.trim()

    >>> Var.SPAN = 1, 3
    >>> Var.NDIM = 2
    >>> var.shape = (1, 3)
    >>> var.values = 2
    >>> var.trim()

    >>> var.values = 0, 1, 2
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: At least one value of parameter `var` of element `?` \
is not valid.
    >>> var
    var([[0, 1, 2]])
    >>> var.values = 2, 3, 4
    >>> var.trim()
    Traceback (most recent call last):
     ...
    ValueError: At least one value of parameter `var` of element `?` \
is not valid.
    >>> var
    var([[2, 3, 4]])


    >>> var.values = 0, 0, 2
    >>> var.trim(lower=[0, INT_NAN, 2])

    >>> var.values = 2, 4, 4
    >>> var.trim(upper=[2, INT_NAN, 4])

    For |bool| values, defining outliers does not make much sense,
    which is why function |trim| does nothing when applied on
    variables handling |bool| values:

    >>> Var.TYPE = bool
    >>> var.trim()

    If function |trim| encounters an unmanageable type, it raises an
    exception like the following:

    >>> Var.TYPE = str
    >>> var.trim()
    Traceback (most recent call last):
    ...
    NotImplementedError: Method `trim` can only be applied on parameters \
handling floating point, integer, or boolean values, but the "value type" \
of parameter `var` is `str`.

    >>> pub.options.warntrim = False
    """
    if hydpy.pub.options.trimvariables:
        if lower is None:
            lower = self.SPAN[0]
        if upper is None:
            upper = self.SPAN[1]
        type_ = getattr(self, 'TYPE', float)
        if type_ is float:
            if self.NDIM == 0:
                _trim_float_0d(self, lower, upper)
            else:
                _trim_float_nd(self, lower, upper)
        elif type_ is int:
            if self.NDIM == 0:
                _trim_int_0d(self, lower, upper)
            else:
                _trim_int_nd(self, lower, upper)
        elif type_ is bool:
            pass
        else:
            raise NotImplementedError(
                f'Method `trim` can only be applied on parameters '
                f'handling floating point, integer, or boolean values, '
                f'but the "value type" of parameter `{self.name}` is '
                f'`{objecttools.classname(self.TYPE)}`.')
Trim the value(s) of a |Variable| instance.

    Usually, users do not need to apply function |trim| directly.
    Instead, some |Variable| subclasses implement their own `trim`
    methods relying on function |trim|.  Model developers should
    implement individual `trim` methods for their |Parameter| or
    |Sequence| subclasses when their boundary values depend on the
    actual project configuration (one example is soil moisture;
    its lowest possible value should possibly be zero in all cases,
    but its highest possible value could depend on another parameter
    defining the maximum storage capacity).

    For the following examples, we prepare a simple (not fully
    functional) |Variable| subclass, making use of function |trim|
    without any modifications.  Function |trim| works slightly
    different for variables handling |float|, |int|, and |bool|
    values.  We start with the most common content type |float|:

    >>> from hydpy.core.variabletools import trim, Variable
    >>> class Var(Variable):
    ...     NDIM = 0
    ...     TYPE = float
    ...     SPAN = 1.0, 3.0
    ...     trim = trim
    ...     initinfo = 2.0, False
    ...     __hydpy__connect_variable2subgroup__ = None

    First, we enable the printing of warning messages raised by function
    |trim|:

    >>> from hydpy import pub
    >>> pub.options.warntrim = True

    When not passing boundary values, function |trim| extracts them from
    class attribute `SPAN` of the given |Variable| instance, if available:

    >>> var = Var(None)
    >>> var.value = 2.0
    >>> var.trim()
    >>> var
    var(2.0)

    >>> var.value = 0.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `0.0` and `1.0`, respectively.
    >>> var
    var(1.0)

    >>> var.value = 4.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `4.0` and `3.0`, respectively.
    >>> var
    var(3.0)

    In the examples above, outlier values are set to the respective
    boundary value, accompanied by suitable warning messages.  For very
    tiny deviations, which might be due to precision problems only,
    outliers are trimmed but not reported:

    >>> var.value = 1.0 - 1e-15
    >>> var == 1.0
    False
    >>> trim(var)
    >>> var == 1.0
    True

    >>> var.value = 3.0 + 1e-15
    >>> var == 3.0
    False
    >>> var.trim()
    >>> var == 3.0
    True

    Use arguments `lower` and `upper` to override the (eventually)
    available `SPAN` entries:

    >>> var.trim(lower=4.0)
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `3.0` and `4.0`, respectively.

    >>> var.trim(upper=3.0)
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `4.0` and `3.0`, respectively.

    Function |trim| interprets both |None| and |numpy.nan| values as if
    no boundary value exists:

    >>> import numpy
    >>> var.value = 0.0
    >>> var.trim(lower=numpy.nan)
    >>> var.value = 5.0
    >>> var.trim(upper=numpy.nan)

    You can disable function |trim| via option |Options.trimvariables|:

    >>> with pub.options.trimvariables(False):
    ...     var.value = 5.0
    ...     var.trim()
    >>> var
    var(5.0)

    Alternatively, you can omit the warning messages only:

    >>> with pub.options.warntrim(False):
    ...     var.value = 5.0
    ...     var.trim()
    >>> var
    var(3.0)

    If a |Variable| subclass does not have (fixed) boundaries, give it
    either no `SPAN` attribute or a |tuple| containing |None| values:

    >>> del Var.SPAN
    >>> var.value = 5.0
    >>> var.trim()
    >>> var
    var(5.0)

    >>> Var.SPAN = (None, None)
    >>> var.trim()
    >>> var
    var(5.0)

    The above examples deal with a 0-dimensional |Variable| subclass.
    The following examples repeat the most relevant examples for a
    2-dimensional subclass:

    >>> Var.SPAN = 1.0, 3.0
    >>> Var.NDIM = 2
    >>> var.shape = 1, 3
    >>> var.values = 2.0
    >>> var.trim()

    >>> var.values = 0.0, 1.0, 2.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 0.  1.  2.]]` and `[[ 1.  1.  2.]]`, \
respectively.
    >>> var
    var([[1.0, 1.0, 2.0]])

    >>> var.values = 2.0, 3.0, 4.0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 2.  3.  4.]]` and `[[ 2.  3.  3.]]`, \
respectively.
    >>> var
    var([[2.0, 3.0, 3.0]])

    >>> var.values = 1.0-1e-15, 2.0, 3.0+1e-15
    >>> var.values == (1.0, 2.0, 3.0)
    array([[False,  True, False]], dtype=bool)
    >>> var.trim()
    >>> var.values == (1.0, 2.0, 3.0)
    array([[ True,  True,  True]], dtype=bool)

    >>> var.values = 0.0, 2.0, 4.0
    >>> var.trim(lower=numpy.nan, upper=numpy.nan)
    >>> var
    var([[0.0, 2.0, 4.0]])

    >>> var.trim(lower=[numpy.nan, 3.0, 3.0])
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 0.  2.  4.]]` and `[[ 0.  3.  3.]]`, \
respectively.

    >>> var.values = 0.0, 2.0, 4.0
    >>> var.trim(upper=[numpy.nan, 1.0, numpy.nan])
    Traceback (most recent call last):
    ...
    UserWarning: For variable `var` at least one value needed to be trimmed.  \
The old and the new value(s) are `[[ 0.  2.  4.]]` and `[[ 1.  1.  4.]]`, \
respectively.

    For |Variable| subclasses handling |float| values, setting outliers
    to the respective boundary value might often be an acceptable approach.
    However, this is often not the case for subclasses handling |int|
    values, which often serve as option flags (e.g. to enable/disable
    a certain hydrological process for different land-use types). Hence,
    function |trim| raises an exception instead of a warning and does
    not modify the wrong |int| value:

    >>> Var.TYPE = int
    >>> Var.NDIM = 0
    >>> Var.SPAN = 1, 3

    >>> var.value = 2
    >>> var.trim()
    >>> var
    var(2)

    >>> var.value = 0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `0` of parameter `var` of element `?` is not valid.
    >>> var
    var(0)
    >>> var.value = 4
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `4` of parameter `var` of element `?` is not valid.
    >>> var
    var(4)

    >>> from hydpy import INT_NAN
    >>> var.value = 0
    >>> var.trim(lower=0)
    >>> var.trim(lower=INT_NAN)

    >>> var.value = 4
    >>> var.trim(upper=4)
    >>> var.trim(upper=INT_NAN)

    >>> Var.SPAN = 1, None
    >>> var.value = 0
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `0` of parameter `var` of element `?` is not valid.
    >>> var
    var(0)

    >>> Var.SPAN = None, 3
    >>> var.value = 0
    >>> var.trim()
    >>> var.value = 4
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: The value `4` of parameter `var` of element `?` is not valid.

    >>> del Var.SPAN
    >>> var.value = 0
    >>> var.trim()
    >>> var.value = 4
    >>> var.trim()

    >>> Var.SPAN = 1, 3
    >>> Var.NDIM = 2
    >>> var.shape = (1, 3)
    >>> var.values = 2
    >>> var.trim()

    >>> var.values = 0, 1, 2
    >>> var.trim()
    Traceback (most recent call last):
    ...
    ValueError: At least one value of parameter `var` of element `?` \
is not valid.
    >>> var
    var([[0, 1, 2]])
    >>> var.values = 2, 3, 4
    >>> var.trim()
    Traceback (most recent call last):
     ...
    ValueError: At least one value of parameter `var` of element `?` \
is not valid.
    >>> var
    var([[2, 3, 4]])


    >>> var.values = 0, 0, 2
    >>> var.trim(lower=[0, INT_NAN, 2])

    >>> var.values = 2, 4, 4
    >>> var.trim(upper=[2, INT_NAN, 4])

    For |bool| values, defining outliers does not make much sense,
    which is why function |trim| does nothing when applied on
    variables handling |bool| values:

    >>> Var.TYPE = bool
    >>> var.trim()

    If function |trim| encounters an unmanageable type, it raises an
    exception like the following:

    >>> Var.TYPE = str
    >>> var.trim()
    Traceback (most recent call last):
    ...
    NotImplementedError: Method `trim` can only be applied on parameters \
handling floating point, integer, or boolean values, but the "value type" \
of parameter `var` is `str`.

    >>> pub.options.warntrim = False