From 5c15e996cbf8ed2fe4855bb3e5a62ada5c3f6398 Mon Sep 17 00:00:00 2001 From: Gabe Joseph Date: Wed, 6 Jul 2022 22:26:46 -0400 Subject: [PATCH] Remove rasterio `windows.from_bounds` workaround --- stackstac/tests/test_to_dask.py | 4 ++-- stackstac/to_dask.py | 31 +------------------------------ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/stackstac/tests/test_to_dask.py b/stackstac/tests/test_to_dask.py index 1a85bfb..b814961 100644 --- a/stackstac/tests/test_to_dask.py +++ b/stackstac/tests/test_to_dask.py @@ -16,7 +16,6 @@ ChunksParam, items_to_dask, normalize_chunks, - window_from_bounds, ) from stackstac.testing import strategies as st_stc @@ -108,7 +107,8 @@ def test_items_to_dask( continue assert url == f"fake://{i}/{j}" - window = window_from_bounds(asset["bounds"], spec_.transform) + asset_bounds: Bbox = asset["bounds"] + window = windows.from_bounds(*asset_bounds, spec_.transform) asset_windows[url] = window chunk = results[(i, j) + windows.window_index(window)] diff --git a/stackstac/to_dask.py b/stackstac/to_dask.py index 513a1c0..517f567 100644 --- a/stackstac/to_dask.py +++ b/stackstac/to_dask.py @@ -131,7 +131,7 @@ def asset_table_to_reader_and_window( url: str | None = asset_entry["url"] if url: asset_bounds: Bbox = asset_entry["bounds"] - asset_window = window_from_bounds(asset_bounds, spec.transform) + asset_window = windows.from_bounds(*asset_bounds, spec.transform) entry: ReaderTableEntry = ( reader( @@ -225,32 +225,3 @@ def normalize_chunks( # ^ Give dask some hint of the physical layout of the data, so it prefers widening # the spatial chunks over bundling together items/assets. This isn't totally accurate. ) - - -# FIXME remove this once rasterio bugs are fixed -def window_from_bounds(bounds: Bbox, transform: Affine) -> windows.Window: - "Get the window corresponding to the bounding coordinates (correcting for rasterio bugs)" - window = windows.from_bounds( - *bounds, - transform=transform, - precision=0.0 - # ^ https://github.com/rasterio/rasterio/issues/2374 - ) - - # Trim negative `row_off`/`col_off` to work around https://github.com/rasterio/rasterio/issues/2378 - # Note this does actually alter the window: it clips off anything that was out-of-bounds to the - # west/north of the `transform`'s origin. So the size and origin of the window is no longer accurate. - # This is okay for our purposes, since we only use these windows for intersection-testing to see if - # an asset intersects our current chunk. We don't care about the parts of the asset that fall - # outside our AOI. - window = windows.Window( - max(window.col_off, 0), # type: ignore "Expected 0 positional arguments" - max(window.row_off, 0), - (max(window.col_off + window.width, 0) if window.col_off < 0 else window.width), - ( - max(window.row_off + window.height, 0) - if window.row_off < 0 - else window.height - ), - ) - return window