Skip to content

continuous_timeseries.domain_helpers#

Support for our domain handling

Functions:

Name Description
check_no_times_outside_domain

Check that no times are outside the supported domain

validate_domain

Check that domain values are valid

check_no_times_outside_domain #

check_no_times_outside_domain(
    times: Union[PINT_NUMPY_ARRAY, PINT_SCALAR],
    domain: tuple[PINT_SCALAR, PINT_SCALAR],
) -> None
check_no_times_outside_domain(
    times: Union[NP_ARRAY_OF_FLOAT_OR_INT, NP_FLOAT_OR_INT],
    domain: tuple[NP_FLOAT_OR_INT, NP_FLOAT_OR_INT],
) -> None

Check that no times are outside the supported domain

Parameters:

Name Type Description Default
times Union[PINT_NUMPY_ARRAY, PINT_SCALAR, NP_ARRAY_OF_FLOAT_OR_INT, NP_FLOAT_OR_INT]

Times to check

required
domain Union[tuple[PINT_SCALAR, PINT_SCALAR], tuple[NP_FLOAT_OR_INT, NP_FLOAT_OR_INT]]

Supported domain

required

Raises:

Type Description
ValueError

There are values in time that are outside the supported domain.

Source code in src/continuous_timeseries/domain_helpers.py
def check_no_times_outside_domain(
    times: Union[
        PINT_NUMPY_ARRAY, PINT_SCALAR, NP_ARRAY_OF_FLOAT_OR_INT, NP_FLOAT_OR_INT
    ],
    domain: Union[
        tuple[PINT_SCALAR, PINT_SCALAR], tuple[NP_FLOAT_OR_INT, NP_FLOAT_OR_INT]
    ],
) -> None:
    """
    Check that no times are outside the supported domain

    Parameters
    ----------
    times
        Times to check

    domain
        Supported domain

    Raises
    ------
    ValueError
        There are values in `time` that are outside the supported domain.
    """
    validate_domain(domain)

    times = np.atleast_1d(times)

    outside_domain = np.hstack(
        [
            times[times < domain[0]],
            times[times > domain[1]],
        ]
    )

    if outside_domain.size >= 1:
        msg = (
            f"The {domain=}. "
            "There are time values that are outside this domain: "
            f"{outside_domain=}."
        )
        raise ValueError(msg)

validate_domain #

validate_domain(
    domain: Union[
        tuple[PINT_SCALAR, PINT_SCALAR],
        tuple[NP_FLOAT_OR_INT, NP_FLOAT_OR_INT],
    ],
) -> None

Check that domain values are valid

Parameters:

Name Type Description Default
domain Union[tuple[PINT_SCALAR, PINT_SCALAR], tuple[NP_FLOAT_OR_INT, NP_FLOAT_OR_INT]]

Domain to check

required

Raises:

Type Description
AssertionError

len(domain) != 2 or domain[1] <= domain[0].

Source code in src/continuous_timeseries/domain_helpers.py
def validate_domain(
    domain: Union[
        tuple[PINT_SCALAR, PINT_SCALAR], tuple[NP_FLOAT_OR_INT, NP_FLOAT_OR_INT]
    ],
) -> None:
    """
    Check that domain values are valid

    Parameters
    ----------
    domain
        Domain to check

    Raises
    ------
    AssertionError
        `len(domain) != 2` or `domain[1] <= domain[0]`.
    """
    expected_domain_length = 2
    if len(domain) != expected_domain_length:
        raise AssertionError(len(domain))

    if domain[1] <= domain[0]:
        msg = f"domain[1] must be greater than domain[0]. Received {domain=}."

        raise AssertionError(msg)