From 9ce23963dd4a2d94c7b4ee04305fcd6b7a7f9401 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Mon, 18 May 2026 13:58:09 -0400 Subject: [PATCH] feat: Add new `Store` protocol defined in this package --- docs/api/geotiff.md | 1 + src/async_geotiff/__init__.py | 3 ++- src/async_geotiff/_geotiff.py | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/api/geotiff.md b/docs/api/geotiff.md index 4adbcdc..07b99d1 100644 --- a/docs/api/geotiff.md +++ b/docs/api/geotiff.md @@ -1,3 +1,4 @@ # GeoTIFF ::: async_geotiff.GeoTIFF +::: async_geotiff.Store diff --git a/src/async_geotiff/__init__.py b/src/async_geotiff/__init__.py index 2f65efb..683b6a1 100644 --- a/src/async_geotiff/__init__.py +++ b/src/async_geotiff/__init__.py @@ -6,7 +6,7 @@ from . import exceptions, utils from ._array import RasterArray from ._gdal_metadata import BandStatistics -from ._geotiff import GeoTIFF +from ._geotiff import GeoTIFF, Store from ._overview import Overview from ._tile import Tile from ._transform import BoundingBox @@ -19,6 +19,7 @@ "GeoTIFF", "Overview", "RasterArray", + "Store", "Tile", "Window", "__version__", diff --git a/src/async_geotiff/_geotiff.py b/src/async_geotiff/_geotiff.py index 07199d6..e53ccc2 100644 --- a/src/async_geotiff/_geotiff.py +++ b/src/async_geotiff/_geotiff.py @@ -3,7 +3,7 @@ import warnings from dataclasses import dataclass, field from types import MappingProxyType -from typing import TYPE_CHECKING, Self +from typing import TYPE_CHECKING, Protocol, Self import numpy as np from async_tiff import TIFF @@ -15,6 +15,7 @@ PlanarConfiguration, SampleFormat, ) +from obspec import GetRangeAsync, GetRangesAsync from async_geotiff._colorinterp import infer_color_interpretation from async_geotiff._crs import crs_from_geo_keys @@ -40,10 +41,18 @@ from collections.abc import Mapping from affine import Affine - from async_tiff import GeoKeyDirectory, ImageFileDirectory, ObspecInput + from async_tiff import GeoKeyDirectory, ImageFileDirectory from pyproj.crs import CRS +class Store(GetRangeAsync, GetRangesAsync, Protocol): + """Supported input to `store` param of `GeoTIFF.open`. + + Anything that implements [GetRangeAsync][obspec.GetRangeAsync] and + [GetRangesAsync][obspec.GetRangesAsync] can be used as an input to the TIFF reader. + """ + + @dataclass(frozen=True, init=False, kw_only=True, repr=False) class GeoTIFF(ReadMixin, FetchTileMixin, TiledMixin, TransformMixin): """A class representing a GeoTIFF image.""" @@ -199,7 +208,7 @@ async def open( cls, path: str, *, - store: ObspecInput, + store: Store, prefetch: int = 32768, multiplier: float = 2.0, ) -> Self: @@ -213,7 +222,7 @@ async def open( [`GCSStore`][obstore.store.GCSStore], or [`AzureStore`][obstore.store.AzureStore]. However, this can be any object that implements the interface required by - [`ObspecInput`][async_tiff.ObspecInput]. + [`Store`][async_geotiff.Store]. prefetch: The number of initial bytes to read up front. multiplier: The multiplier to use for readahead size growth. Must be greater than 1.0. For example, for a value of `2.0`, the first metadata