diff --git a/README.md b/README.md index 7b329b9..fc7edc0 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ window = Window(col_off=0, row_off=0, width=512, height=512) array = await overview.read(window=window) ``` -This `Array` instance has `data`, `mask`, and some other metadata about the fetched array data. +This `RasterArray` instance has `data`, `mask`, and some other metadata about the fetched array data. Plot, using [`rasterio.plot.show`](https://rasterio.readthedocs.io/en/stable/api/rasterio.plot.html#rasterio.plot.show) (requires `matplotlib`): diff --git a/docs/api/array.md b/docs/api/array.md deleted file mode 100644 index 2fe8cf9..0000000 --- a/docs/api/array.md +++ /dev/null @@ -1,3 +0,0 @@ -# Array - -::: async_geotiff.Array diff --git a/docs/api/raster-array.md b/docs/api/raster-array.md new file mode 100644 index 0000000..50ae6c8 --- /dev/null +++ b/docs/api/raster-array.md @@ -0,0 +1,3 @@ +# RasterArray + +::: async_geotiff.RasterArray diff --git a/docs/blog/posts/introducing-async-geotiff.md b/docs/blog/posts/introducing-async-geotiff.md index 5d0b72b..4ddbfba 100644 --- a/docs/blog/posts/introducing-async-geotiff.md +++ b/docs/blog/posts/introducing-async-geotiff.md @@ -77,7 +77,7 @@ window = Window(col_off=0, row_off=0, width=512, height=512) array = await overview.read(window=window) ``` -The `read` method returns an [`Array`][async_geotiff.Array] instance, which has fields including `data`, `shape`, `mask`, `transform`, and `crs`. +The `read` method returns a [`RasterArray`][async_geotiff.RasterArray] instance, which has fields including `data`, `shape`, `mask`, `transform`, and `crs`. ```py # The affine transform of the loaded array @@ -399,7 +399,7 @@ The majority of these test files are [written using Rasterio](https://github.com ### Better API for handling photometric interpretations -Currently Async-GeoTIFF doesn't decode data out of RGB color spaces like YCbCr, which doesn't match Rasterio's handling. We may add an API like `Array.to_rgb` to offer explicit conversion to an RGB color space. +Currently Async-GeoTIFF doesn't decode data out of RGB color spaces like YCbCr, which doesn't match Rasterio's handling. We may add an API like `RasterArray.to_rgb` to offer explicit conversion to an RGB color space. ### More compression support diff --git a/mkdocs.yml b/mkdocs.yml index 77d762b..995f03e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -23,7 +23,7 @@ nav: - API Reference: - api/geotiff.md - api/overview.md - - api/array.md + - api/raster-array.md - api/tile.md - api/window.md - api/colormap.md diff --git a/src/async_geotiff/__init__.py b/src/async_geotiff/__init__.py index f3ddb5b..369f6c1 100644 --- a/src/async_geotiff/__init__.py +++ b/src/async_geotiff/__init__.py @@ -4,7 +4,7 @@ """ from . import exceptions -from ._array import Array +from ._array import RasterArray from ._gdal_metadata import BandStatistics from ._geotiff import GeoTIFF from ._overview import Overview @@ -14,11 +14,11 @@ from ._windows import Window __all__ = [ - "Array", "BandStatistics", "BoundingBox", "GeoTIFF", "Overview", + "RasterArray", "Tile", "Window", "__version__", diff --git a/src/async_geotiff/_array.py b/src/async_geotiff/_array.py index 907fa8f..cd88e0a 100644 --- a/src/async_geotiff/_array.py +++ b/src/async_geotiff/_array.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from affine import Affine - from async_tiff import Array as AsyncTiffArray + from async_tiff import Array from numpy.typing import NDArray from pyproj.crs import CRS @@ -19,8 +19,8 @@ @dataclass(frozen=True, kw_only=True, eq=False) -class Array(TransformMixin): - """An array representation of data from a GeoTIFF.""" +class RasterArray(TransformMixin): + """Georeferenced array data from a GeoTIFF.""" data: NDArray """The array data with shape (bands, height, width).""" @@ -56,14 +56,14 @@ class Array(TransformMixin): def _create( # noqa: PLR0913 cls, *, - data: AsyncTiffArray, - mask: AsyncTiffArray | None, + data: Array, + mask: Array | None, planar_configuration: PlanarConfiguration, transform: Affine, geotiff: GeoTIFF, alpha_band_idx: int | None, ) -> Self: - """Create an Array from async_tiff data. + """Create a RasterArray from async_tiff data. Handles axis reordering to ensure data is always in (bands, height, width) order, matching rasterio's convention. @@ -102,15 +102,15 @@ def _create( # noqa: PLR0913 ) def as_masked(self) -> MaskedArray: - """Return the data as a masked array using the Array mask or nodata value. + """Return the data as a masked array using the array mask or nodata value. !!! warning In a numpy [`MaskedArray`][numpy.ma.MaskedArray], `True` indicates invalid (masked) data and `False` indicates valid data. This is the inverse convention of a GeoTIFF's mask. The boolean array - [`Array.mask`][async_geotiff.Array.mask] uses `True` for valid data and - `False` for invalid data. + [`RasterArray.mask`][async_geotiff.RasterArray.mask] uses `True` for valid + data and `False` for invalid data. Returns: A masked array with the same shape as `data`, where invalid data diff --git a/src/async_geotiff/_fetch.py b/src/async_geotiff/_fetch.py index e2bd70b..ed90aea 100644 --- a/src/async_geotiff/_fetch.py +++ b/src/async_geotiff/_fetch.py @@ -5,15 +5,14 @@ from affine import Affine -from async_geotiff._array import Array +from async_geotiff._array import RasterArray from async_geotiff._tile import Tile from async_geotiff._transform import HasTransform if TYPE_CHECKING: from collections.abc import Sequence - from async_tiff import Array as AsyncTiffArray - from async_tiff import ImageFileDirectory + from async_tiff import Array, ImageFileDirectory from async_geotiff import GeoTIFF @@ -85,7 +84,7 @@ async def fetch_tile( """ tile_fut = self._ifd.fetch_tile(x, y) - mask_data: AsyncTiffArray | None = None + mask_data: Array | None = None if self._mask_ifd is not None: mask_fut = self._mask_ifd.fetch_tile(x, y) tile, mask = await asyncio.gather(tile_fut, mask_fut) @@ -99,7 +98,7 @@ async def fetch_tile( y * self.tile_height, ) - array = Array._create( # noqa: SLF001 + array = RasterArray._create( # noqa: SLF001 data=tile_data, mask=mask_data, planar_configuration=self._ifd.planar_configuration, @@ -144,7 +143,7 @@ async def fetch_tiles( """ tiles_fut = self._ifd.fetch_tiles(xy) - decoded_masks: list[AsyncTiffArray | None] = [None] * len(xy) + decoded_masks: list[Array | None] = [None] * len(xy) if self._mask_ifd is not None: masks_fut = self._mask_ifd.fetch_tiles(xy) tiles, masks = await asyncio.gather(tiles_fut, masks_fut) @@ -168,7 +167,7 @@ async def fetch_tiles( x * self.tile_width, y * self.tile_height, ) - array = Array._create( # noqa: SLF001 + array = RasterArray._create( # noqa: SLF001 data=tile_data, mask=mask_data, planar_configuration=self._ifd.planar_configuration, @@ -197,8 +196,8 @@ def _clip_to_image_bounds( self: HasTiffReference, x: int, y: int, - array: Array, -) -> Array: + array: RasterArray, +) -> RasterArray: """Clip a decoded tile array to the valid image bounds. Edge tiles in a COG are always encoded at the full tile size, with the @@ -221,7 +220,7 @@ def _clip_to_image_bounds( array.mask[:clipped_height, :clipped_width] if array.mask is not None else None ) - return Array( + return RasterArray( data=clipped_data, mask=clipped_mask, width=clipped_width, diff --git a/src/async_geotiff/_read.py b/src/async_geotiff/_read.py index 8fc49e1..8709ffa 100644 --- a/src/async_geotiff/_read.py +++ b/src/async_geotiff/_read.py @@ -8,7 +8,7 @@ import numpy as np from affine import Affine -from async_geotiff._array import Array +from async_geotiff._array import RasterArray from async_geotiff._fetch import HasTiffReference from async_geotiff._windows import Window from async_geotiff.exceptions import WindowError @@ -35,7 +35,7 @@ async def read( self: CanFetchTiles, *, window: Window | None = None, - ) -> Array: + ) -> RasterArray: """Read pixel data for a window region. This method fetches all tiles that intersect the given window and @@ -46,7 +46,7 @@ async def read( If None, the entire image is read. Returns: - An Array containing the pixel data for the requested window. + A RasterArray containing the pixel data for the requested window. Raises: WindowError: If the window extends outside the image bounds. @@ -59,7 +59,7 @@ async def read( self: CanFetchTiles, *, window: Window | None = None, -) -> Array: +) -> RasterArray: if isinstance(window, Window): win = window else: @@ -114,7 +114,7 @@ async def read( win.row_off, ) - return Array( + return RasterArray( data=output_data, mask=output_mask, width=win.width, diff --git a/src/async_geotiff/_tile.py b/src/async_geotiff/_tile.py index 4aef1ba..8522b7c 100644 --- a/src/async_geotiff/_tile.py +++ b/src/async_geotiff/_tile.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Protocol if TYPE_CHECKING: - from async_geotiff._array import Array + from async_geotiff._array import RasterArray @dataclass(frozen=True, kw_only=True, eq=False) @@ -18,7 +18,7 @@ class Tile: y: int """The tile row index in the GeoTIFF or overview.""" - array: Array + array: RasterArray """The array data for this tile."""