Пример #1
0
from typing import *

# ...from site-packages
import numpy

# ...from HydPy
from hydpy import conf
from hydpy.core import exceptiontools
from hydpy.cythons.autogen import smoothutils

if TYPE_CHECKING:
    from scipy import interpolate
    from scipy import optimize
else:
    interpolate = exceptiontools.OptionalImport("interpolate",
                                                ["scipy.interpolate"],
                                                locals())
    optimize = exceptiontools.OptionalImport("optimize", ["scipy.optimize"],
                                             locals())


def calc_smoothpar_logistic1(metapar):
    """Return the smoothing parameter corresponding to the given meta
    parameter when using |smooth_logistic1|.

    Calculate the smoothing parameter value corresponding the meta parameter
    value 2.5:

    >>> from hydpy.auxs.smoothtools import calc_smoothpar_logistic1
    >>> smoothpar = calc_smoothpar_logistic1(2.5)
Пример #2
0
from typing import *

# ...from site-packages
import numpy

# ...from HydPy
import hydpy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.auxs import statstools

if TYPE_CHECKING:
    from matplotlib import pyplot
    from scipy import integrate
else:
    pyplot = exceptiontools.OptionalImport("pyplot", ["matplotlib.pyplot"],
                                           locals())
    integrate = exceptiontools.OptionalImport("integrate", ["scipy.integrate"],
                                              locals())


class MA:
    """Moving Average Model.

    The MA coefficients can be set manually:

    >>> from hydpy import MA
    >>> ma = MA(coefs=(0.8, 0.2))
    >>> ma
    MA(coefs=(0.8, 0.2))
    >>> ma.coefs = 0.2, 0.8
    >>> ma
Пример #3
0
from typing_extensions import Literal  # type: ignore[misc]

# ...from site-packages
import numpy

# ...from HydPy
import hydpy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.core import timetools
from hydpy.core.typingtools import *

if TYPE_CHECKING:
    import pandas
else:
    pandas = exceptiontools.OptionalImport("pandas", ["pandas"], locals())


@overload
def aggregate_series(
    *,
    series: VectorInput[float],
    stepsize: Literal["daily", "d"],
    aggregator: Union[str, Callable[[VectorInput[float]], float]] = "mean",
    subperiod: bool = True,
    basetime: str = "00:00",
) -> pandas.DataFrame:
    """sim and obs as arguments, daily aggregation"""


@overload
Пример #4
0
import numpy

# ...from HydPy
import hydpy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.core import parametertools
from hydpy.core import timetools
from hydpy.core import variabletools
from hydpy.core.typingtools import *
from hydpy.cythons import interputils

if TYPE_CHECKING:
    from matplotlib import pyplot
else:
    pyplot = exceptiontools.OptionalImport("pyplot", ["matplotlib.pyplot"],
                                           locals())


class _Labeled:
    def _update_labels(self) -> None:
        xlabel = getattr(self, "XLABEL", None)
        if xlabel:
            pyplot.xlabel(xlabel)
        ylabel = getattr(self, "YLABEL", None)
        if ylabel:
            pyplot.ylabel(ylabel)


class InterpAlgorithm(abc.ABC, _Labeled):
    """Base class for defining interpolation algorithms usable by classes
    |SimpleInterpolator| and |SeasonalInterpolator|."""
Пример #5
0
from typing import *

# ...from site-packages
# from scipy but not optional due to using interp1d during module initialisation:
from scipy import interpolate
import numpy

# ...from HydPy
from hydpy import conf
from hydpy.core import exceptiontools

if TYPE_CHECKING:
    from scipy import optimize
    from hydpy.cythons import smoothutils
else:
    optimize = exceptiontools.OptionalImport("optimize", ["scipy.optimize"],
                                             locals())
    from hydpy.cythons.autogen import smoothutils


def calc_smoothpar_logistic1(metapar):
    """Return the smoothing parameter corresponding to the given meta
    parameter when using |smooth_logistic1|.

    Calculate the smoothing parameter value corresponding the meta parameter
    value 2.5:

    >>> from hydpy.auxs.smoothtools import calc_smoothpar_logistic1
    >>> smoothpar = calc_smoothpar_logistic1(2.5)

    When using this smoothing parameter value, the output of function
    |smooth_logistic1| differs by 1 % from the related "true" discontinuous
Пример #6
0
# ...from site-packages
import numpy

# ...from Hydpy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.auxs import statstools
from hydpy.auxs import armatools
from hydpy.core.typingtools import *

if TYPE_CHECKING:
    from matplotlib import pyplot
    from scipy import special
else:
    pyplot = exceptiontools.OptionalImport("pyplot", ["matplotlib.pyplot"], locals())
    special = exceptiontools.OptionalImport("special", ["scipy.special"], locals())


class ParameterIUH:
    """Descriptor base class for |PrimaryParameterIUH| and |SecondaryParameterIUH|.

    The first initialisation argument is the parameters name.  Optionally, an
    alternative type (the default type is |float|) and a documentation string can be
    passed.
    """

    name: str
    """Name of the handled |IUH| parameter."""
    type_: Type[float]
    """Type of the handled |IUH| parameter."""
Пример #7
0
# ...from site-packages
import numpy
# ...from HydPy
import hydpy
from hydpy import docs
from hydpy.core import devicetools
from hydpy.core import exceptiontools
from hydpy.core import hydpytools
from hydpy.core import objecttools
from hydpy.core import parametertools
from hydpy.core import printtools
from hydpy.core import selectiontools
from hydpy.core import sequencetools
from hydpy.core import timetools
from hydpy.tests import iotesting
models = exceptiontools.OptionalImport('models', ['bokeh.models'], locals())
palettes = exceptiontools.OptionalImport('palettes', ['bokeh.palettes'],
                                         locals())
plotting = exceptiontools.OptionalImport('plotting', ['bokeh.plotting'],
                                         locals())


class StdOutErr:
    """Replaces `sys.stdout` and `sys.stderr` temporarily when calling
    method |Tester.perform_tests| of class |Tester|."""

    indent: int
    texts: List[str]

    def __init__(self, indent: int = 0):
        self.indent = indent
Пример #8
0
# -*- coding: utf-8 -*-
"""This module provides additional features for module |iuhtools|,
related to Autoregressive-Moving Average (ARMA) models."""
# import...
# ...from standard library
import itertools
import warnings
# ...from site-packages
import numpy
# ...from HydPy
import hydpy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.auxs import statstools
pyplot = exceptiontools.OptionalImport('pyplot', ['matplotlib.pyplot'],
                                       locals())
integrate = exceptiontools.OptionalImport('integrate', [
    'scipy.integrate'
], locals(), [
    'import warnings', 'from scipy import integrate',
    'warnings.filterwarnings("error", category=integrate.IntegrationWarning)'
])


class MA:
    """Moving Average Model.

    The MA coefficients can be set manually:

    >>> from hydpy import MA
    >>> ma = MA(coefs=(0.8, 0.2))
Пример #9
0
# ...from site-packages
import numpy

# ...from HydPy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.core import propertytools
from hydpy.core.typingtools import *
from hydpy.auxs import interptools
from hydpy.cythons.autogen import ppolyutils

if TYPE_CHECKING:
    from scipy import interpolate
else:
    special = exceptiontools.OptionalImport("special", ["scipy.interpolate"],
                                            locals())


class Poly(NamedTuple):
    r"""Parameter handler for a power series representation of a single polynomial
    function.

    The following |Poly| object corresponds to the polynomial function
    :math:`f(x) = 2 + 3 \cdot (x - 1) + 4 \cdot (x - 1)^2`:

    >>> from hydpy import Poly
    >>> p = Poly(x0=1.0, cs=(2.0, 3.0, 4.0))

    Proper application of the constant and all coefficients for :math:`x = 3` results
    in 24:
Пример #10
0
# -*- coding: utf-8 -*-
"""This module implements statistical functionalities frequently used in
hydrological modelling.
"""
# import...
# ...from site-packages
import numpy
# ...from HydPy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.auxs import validtools
pandas = exceptiontools.OptionalImport(
    'pandas', ['pandas'], locals())
optimize = exceptiontools.OptionalImport(
    'optimize', ['scipy.optimize'], locals())
special = exceptiontools.OptionalImport(
    'special', ['scipy.special'], locals())


def prepare_arrays(sim=None, obs=None, node=None, skip_nan=False):
    """Prepare and return two |numpy| arrays based on the given arguments.

    Note that many functions provided by module |statstools| apply function
    |prepare_arrays| internally (e.g. |nse|).  But you can also apply it
    manually, as shown in the following examples.

    Function |prepare_arrays| can extract time series data from |Node|
    objects.  To set up an example for this, we define a initialization
    time period and prepare a |Node| object:

    >>> from hydpy import pub, Node, round_, nan
Пример #11
0
Some of the implemented features are to be applied during model simulations
or are in some other way performance-critical, which is why we implement
them computationally efficient by using Cython (see the extension module
|smoothutils|.
"""

# import...
# ...from standard-library
import os
# ...from site-packages
import numpy
# ...from HydPy
from hydpy import conf
from hydpy.core import exceptiontools
from hydpy.cythons.autogen import smoothutils
interpolate = exceptiontools.OptionalImport('interpolate',
                                            ['scipy.interpolate'], locals())
optimize = exceptiontools.OptionalImport('optimize', ['scipy.optimize'],
                                         locals())


def calc_smoothpar_logistic1(metapar):
    """Return the smoothing parameter corresponding to the given meta
    parameter when using |smooth_logistic1|.

    Calculate the smoothing parameter value corresponding the meta parameter
    value 2.5:

    >>> from hydpy.auxs.smoothtools import calc_smoothpar_logistic1
    >>> smoothpar = calc_smoothpar_logistic1(2.5)

    When using this smoothing parameter value, the output of function
Пример #12
0
unit hydrograph (iuh) function or if you want to implement an additional
iuh, see the examples or the source code of class
|TranslationDiffusionEquation|.
"""
# import...
# ...from standard library
import abc
import itertools
# ...from site-packages
import numpy
# ...from Hydpy
from hydpy.core import exceptiontools
from hydpy.core import objecttools
from hydpy.auxs import statstools
from hydpy.auxs import armatools
pyplot = exceptiontools.OptionalImport('pyplot', ['matplotlib.pyplot'],
                                       locals())
special = exceptiontools.OptionalImport('special', ['scipy.special'], locals())


class ParameterIUH:
    """Descriptor base class for |PrimaryParameterIUH| and
    |SecondaryParameterIUH|.

    The first initialization argument is the parameters name.  Optionally,
    an alternative type (the default type is |float|) and a documentation
    string can be passed.
    """
    def __init__(self, name, type_=float, doc=None):
        self.name = name
        self._name = '_' + name
        self.type_ = type_