Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`):

Expand Down
3 changes: 0 additions & 3 deletions docs/api/array.md

This file was deleted.

3 changes: 3 additions & 0 deletions docs/api/raster-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RasterArray

::: async_geotiff.RasterArray
4 changes: 2 additions & 2 deletions docs/blog/posts/introducing-async-geotiff.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/async_geotiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,11 +14,11 @@
from ._windows import Window

__all__ = [
"Array",
"BandStatistics",
"BoundingBox",
"GeoTIFF",
"Overview",
"RasterArray",
"Tile",
"Window",
"__version__",
Expand Down
16 changes: 8 additions & 8 deletions src/async_geotiff/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

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

from async_geotiff import GeoTIFF


@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)."""
Expand Down Expand Up @@ -56,8 +56,8 @@ 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,
Comment thread
kylebarron marked this conversation as resolved.
Resolved
Expand Down Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions src/async_geotiff/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Comment thread
kylebarron marked this conversation as resolved.
Resolved
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/async_geotiff/_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -59,7 +59,7 @@ async def read(
self: CanFetchTiles,
*,
window: Window | None = None,
) -> Array:
) -> RasterArray:
if isinstance(window, Window):
win = window
else:
Expand Down Expand Up @@ -114,7 +114,7 @@ async def read(
win.row_off,
)

return Array(
return RasterArray(
data=output_data,
mask=output_mask,
width=win.width,
Expand Down
4 changes: 2 additions & 2 deletions src/async_geotiff/_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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."""


Expand Down
Loading