Reader¶
aef_bng.reader
¶
COG reading via obstore + async-geotiff.
Reads AEF Cloud Optimised GeoTIFF tiles from Source Cooperative, optionally with windowed reads to limit data transfer.
Note on AEF COG orientation¶
AEF COGs are "bottom-up": the origin is the bottom-left corner, the y-resolution is positive, and image blocks are ordered from bottom-left to top-right. This is the inverse of a standard ("top-down") COG where the origin is the top-left and y-resolution is negative.
Source Cooperative's README advises using the companion .vrt files to correct this on-the-fly
for software that assumes standard ordering. This pipeline does not need the VRTs because:
async_geotiffreads the affine transform from the TIFF tags and returns it alongside the data, correctly reflecting the positive y-scale.rasterio.warp.reprojectuses the affine transform to map pixel coordinates to world coordinates, so it handles positive y-scale natively._bounds_to_windowcomputes the pixel window by transforming all four geographic corners (not just two) and taking the actual min/max of the resulting row/column values, which is correct for both positive and negative y-scale transforms.
bng_bounds_to_utm(bounds_bng, tile_crs, padding=500)
¶
Transform BNG bounds to a tile's UTM CRS with padding.
Transforms all four corners and takes the envelope, then adds padding to ensure the reprojection window fully covers the chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds_bng
|
tuple[int, int, int, int]
|
(minx, miny, maxx, maxy) in EPSG:27700. |
required |
tile_crs
|
str
|
CRS of the tile (e.g. "EPSG:32630"). |
required |
padding
|
int
|
Extra metres to add on each side (default 500m - generous to account for CRS distortion at zone edges). |
500
|
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float]
|
(minx, miny, maxx, maxy) in the tile's CRS. |
Source code in aef_bng/reader.py
read_tile(tile_path, window_bounds=None)
async
¶
Read an AEF COG tile, optionally with a geographic window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_path
|
str
|
S3 path to the COG tile (may include s3://bucket/ prefix). |
required |
window_bounds
|
tuple[float, float, float, float] | None
|
Optional (minx, miny, maxx, maxy) in the tile's native CRS to read a subset of the tile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, Affine, str] | None
|
Tuple of (data, transform, crs) where: |
tuple[ndarray, Affine, str] | None
|
|
tuple[ndarray, Affine, str] | None
|
|
tuple[ndarray, Affine, str] | None
|
|
tuple[ndarray, Affine, str] | None
|
Returns None if window_bounds don't overlap the tile. |