From a35d46fa32fdd09ffa954e0f67e6d3ad9c21b039 Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Wed, 13 May 2026 07:23:50 -0700 Subject: [PATCH 1/3] Forward VRT kwargs from dask reader (#1797) --- xrspatial/geotiff/__init__.py | 5 +- .../test_read_geotiff_dask_vrt_kwargs_1797.py | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py diff --git a/xrspatial/geotiff/__init__.py b/xrspatial/geotiff/__init__.py index 67a5fade..e0f29a6e 100644 --- a/xrspatial/geotiff/__init__.py +++ b/xrspatial/geotiff/__init__.py @@ -2154,7 +2154,10 @@ def read_geotiff_dask(source: str, *, # rather than letting the windowed-read path try to parse VRT XML as # TIFF bytes. ``read_vrt`` is the single source of truth for VRT. if isinstance(source, str) and source.lower().endswith('.vrt'): - return read_vrt(source, dtype=dtype, name=name, chunks=chunks) + return read_vrt( + source, dtype=dtype, window=window, band=band, name=name, + chunks=chunks, max_pixels=max_pixels, + ) # P5: HTTP COG sources used to fire one IFD/header GET per chunk # task. Parse metadata once here so every delayed task can reuse it. diff --git a/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py b/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py new file mode 100644 index 00000000..67df7e81 --- /dev/null +++ b/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py @@ -0,0 +1,56 @@ +"""Direct read_geotiff_dask(.vrt) must forward VRT kwargs (#1797).""" +from __future__ import annotations + +import os + +import numpy as np +import pytest + +from xrspatial.geotiff import to_geotiff, read_geotiff_dask + + +def _write_vrt(vrt_path, source_name, *, bands=1): + band_xml = [] + for i in range(bands): + band_xml.append( + f' \n' + ' \n' + f' {source_name}' + '\n' + f' {i + 1}\n' + ' \n' + ' \n' + ' \n' + ' \n' + ) + vrt_path.write_text( + '\n' + + ''.join(band_xml) + + '\n' + ) + + +def test_direct_read_geotiff_dask_vrt_forwards_window_and_band(tmp_path): + arr = np.arange(4 * 6 * 2, dtype=np.float32).reshape(4, 6, 2) + src = tmp_path / "tmp_1797_source.tif" + to_geotiff(arr, str(src), compression='none') + vrt = tmp_path / "tmp_1797_source.vrt" + _write_vrt(vrt, os.path.basename(src), bands=2) + + got = read_geotiff_dask( + str(vrt), chunks=2, window=(1, 2, 4, 6), band=1, + ) + + assert got.shape == (3, 4) + np.testing.assert_array_equal(got.values, arr[1:4, 2:6, 1]) + + +def test_direct_read_geotiff_dask_vrt_forwards_max_pixels(tmp_path): + arr = np.arange(24, dtype=np.float32).reshape(4, 6) + src = tmp_path / "tmp_1797_source_cap.tif" + to_geotiff(arr, str(src), compression='none') + vrt = tmp_path / "tmp_1797_source_cap.vrt" + _write_vrt(vrt, os.path.basename(src)) + + with pytest.raises(ValueError, match="exceed"): + read_geotiff_dask(str(vrt), chunks=2, max_pixels=10) From 4467b78bcfa7f5f71cf92858dec80807c004700a Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Wed, 13 May 2026 08:19:27 -0700 Subject: [PATCH 2/3] Correct VRT kwargs issue reference --- .../geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py b/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py index 67df7e81..eb148a7e 100644 --- a/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py +++ b/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py @@ -1,4 +1,4 @@ -"""Direct read_geotiff_dask(.vrt) must forward VRT kwargs (#1797).""" +"""Direct read_geotiff_dask(.vrt) must forward VRT kwargs (#1795).""" from __future__ import annotations import os From c37273ea150fd021e98fa9a9434241099fe7c348 Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Wed, 13 May 2026 08:22:34 -0700 Subject: [PATCH 3/3] Correct VRT kwargs test issue filename --- ...t_kwargs_1797.py => test_read_geotiff_dask_vrt_kwargs_1795.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xrspatial/geotiff/tests/{test_read_geotiff_dask_vrt_kwargs_1797.py => test_read_geotiff_dask_vrt_kwargs_1795.py} (100%) diff --git a/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py b/xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1795.py similarity index 100% rename from xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1797.py rename to xrspatial/geotiff/tests/test_read_geotiff_dask_vrt_kwargs_1795.py