stac-hash 0.0.2

Sortable spatio-temporal hashes for STAC items
Documentation
from collections.abc import Sequence
from datetime import datetime
from typing import Literal, overload

__version__: str

class Hasher:
    """Creates sortable spatio-temporal hashes.

    The hasher is built from a datetime range and, optionally, a bounding box.
    Without a `bbox` the hasher covers the whole world.
    """

    def __init__(
        self,
        start_datetime: datetime,
        end_datetime: datetime,
        bbox: tuple[float, float, float, float] | None = None,
    ) -> None: ...
    def hash(self, datetime: datetime, longitude: float, latitude: float) -> int:
        """Hashes a datetime and a point into an `int`."""

    def hash_clamped(
        self, datetime: datetime, longitude: float, latitude: float
    ) -> int:
        """Hashes a datetime and a point, clamping onto the hasher's boundary.

        Unlike `hash`, this never raises for out-of-extent input. A datetime
        before the hasher's start hashes as that start, a longitude west of
        the minimum hashes as that minimum, and so on.
        """

    @overload
    def hash_all(
        self,
        datetimes: Sequence[datetime],
        longitudes: Sequence[float],
        latitudes: Sequence[float],
        skip_invalid: Literal[False] = False,
    ) -> list[int]:
        """Hashes parallel sequences of datetimes, longitudes, and latitudes."""

    @overload
    def hash_all(
        self,
        datetimes: Sequence[datetime],
        longitudes: Sequence[float],
        latitudes: Sequence[float],
        skip_invalid: Literal[True],
    ) -> list[int | None]:
        """Hashes parallel sequences of datetimes, longitudes, and latitudes.

        Every item is checked independently; out-of-extent items become
        `None` in the result instead of raising.
        """

    @overload
    def hash_all(
        self,
        datetimes: Sequence[datetime],
        longitudes: Sequence[float],
        latitudes: Sequence[float],
        skip_invalid: bool,
    ) -> list[int | None]:
        """Hashes parallel sequences of datetimes, longitudes, and latitudes.

        Raises a `ValueError` if the sequences are not the same length, or if
        any item falls outside the hasher's extent. Pass `skip_invalid=True`
        to get `None` for out-of-extent items instead of raising.
        """

    def hash_all(
        self,
        datetimes: Sequence[datetime],
        longitudes: Sequence[float],
        latitudes: Sequence[float],
        skip_invalid: bool = False,
    ) -> list[int] | list[int | None]:
        """Hashes parallel sequences of datetimes, longitudes, and latitudes.

        Raises a `ValueError` if the sequences are not the same length, or if
        any item falls outside the hasher's extent. Pass `skip_invalid=True`
        to get `None` for out-of-extent items instead of raising.
        """

    def hash_all_clamped(
        self,
        datetimes: Sequence[datetime],
        longitudes: Sequence[float],
        latitudes: Sequence[float],
    ) -> list[int]:
        """Hashes parallel sequences, clamping onto the hasher's boundary.

        Raises a `ValueError` only if the sequences are not the same length.
        No item can fall outside the extent, so there is no `skip_invalid`.
        """