Skip to content

Commit

Permalink
DEP: rasterio 1.3+ (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Dec 22, 2023
1 parent 4357409 commit a7c81e6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 133 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include_package_data = True
python_requires = >=3.10
install_requires =
packaging
rasterio>=1.2
rasterio>=1.3
xarray>=0.17
pyproj>=2.2
numpy>=1.21
Expand Down
5 changes: 0 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
TEST_COMPARE_DATA_DIR = os.path.join(TEST_DATA_DIR, "compare")
PYPROJ_VERSION = version.parse(importlib.metadata.version("pyproj"))
PYPROJ_LT_3 = PYPROJ_VERSION < version.parse("3")
RASTERIO_VERSION = version.parse(importlib.metadata.version("rasterio"))
RASTERIO_LT_122 = RASTERIO_VERSION < version.parse("1.2.2")
RASTERIO_EQ_122 = RASTERIO_VERSION == version.parse("1.2.2")
RASTERIO_GE_125 = RASTERIO_VERSION >= version.parse("1.2.5")
RASTERIO_GE_13 = version.parse(RASTERIO_VERSION.base_version) >= version.parse("1.3.0")
GDAL_GE_36 = version.parse(rasterio.__gdal_version__) >= version.parse("3.6.0")
GDAL_GE_361 = version.parse(rasterio.__gdal_version__) >= version.parse("3.6.1")
GDAL_GE_364 = version.parse(rasterio.__gdal_version__) >= version.parse("3.6.4")
Expand Down
28 changes: 0 additions & 28 deletions test/integration/test_integration__io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
from test.conftest import (
GDAL_GE_36,
GDAL_GE_364,
RASTERIO_GE_13,
RASTERIO_GE_125,
RASTERIO_VERSION,
TEST_COMPARE_DATA_DIR,
TEST_INPUT_DATA_DIR,
_assert_xarrays_equal,
Expand All @@ -44,16 +41,6 @@
_create_gdal_gcps,
)

cint_skip = pytest.mark.skipif(
RASTERIO_VERSION < version.parse("1.2.4"),
reason="https://github.com/mapbox/rasterio/issues/2182",
)

python_vsi_skip = pytest.mark.skipif(
not RASTERIO_GE_13,
reason="Python VSI Support added in 1.3.0",
)


def _assert_tmmx_source(source):
# https://github.com/OSGeo/gdal/issues/7695
Expand Down Expand Up @@ -1006,10 +993,6 @@ def test_rasterio_vrt_gcps(tmp_path):
)


@pytest.mark.skipif(
not RASTERIO_GE_13,
reason="warp options support added in 1.3.0",
)
def test_rasterio_vrt_warp_extras(tmp_path):
tiffname = tmp_path / "test.tif"
src_gcps = [
Expand Down Expand Up @@ -1083,7 +1066,6 @@ def test_rasterio_vrt_warp_extras(tmp_path):
assert vrt.shape == (28286, 29338)


@cint_skip
def test_rasterio_vrt_gcps__data_exists():
# https://github.com/corteva/rioxarray/issues/515
vrt_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif")
Expand Down Expand Up @@ -1352,7 +1334,6 @@ def test_rotation_affine():
assert rioda.rio.resolution() == (10, 10)


@cint_skip
@pytest.mark.parametrize("dtype", [None, "complex_int16"])
def test_cint16_dtype(dtype, tmp_path):
test_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif")
Expand All @@ -1370,10 +1351,6 @@ def test_cint16_dtype(dtype, tmp_path):
assert data.dtype == "complex64"


@pytest.mark.skipif(
not RASTERIO_GE_125,
reason="https://github.com/mapbox/rasterio/issues/2206",
)
def test_cint16_dtype_nodata(tmp_path):
test_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif")
with rioxarray.open_rasterio(test_file) as xds:
Expand All @@ -1394,7 +1371,6 @@ def test_cint16_dtype_nodata(tmp_path):
assert riofh.nodata is None


@cint_skip
@pytest.mark.parametrize("dtype", [None, "complex_int16"])
def test_cint16_dtype_masked(dtype, tmp_path):
test_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif")
Expand All @@ -1414,7 +1390,6 @@ def test_cint16_dtype_masked(dtype, tmp_path):
assert data.dtype == "complex64"


@cint_skip
def test_cint16_promote_dtype(tmp_path):
test_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif")
with rioxarray.open_rasterio(test_file) as xds:
Expand Down Expand Up @@ -1488,7 +1463,6 @@ def test_writing_gcps(tmp_path):
_check_rio_gcps(darr, *gdal_gcps)


@python_vsi_skip
def test_read_file_handle_with_dask():
with open(
os.path.join(TEST_COMPARE_DATA_DIR, "small_dem_3m_merged.tif"), "rb"
Expand All @@ -1497,14 +1471,12 @@ def test_read_file_handle_with_dask():
pass


@cint_skip
def test_read_cint16_with_dask():
test_file = os.path.join(TEST_INPUT_DATA_DIR, "cint16.tif")
with rioxarray.open_rasterio(test_file, chunks=True):
pass


@python_vsi_skip
def test_read_ascii__from_bytesio():
ascii_raster_string = """ncols 5
nrows 5
Expand Down
94 changes: 25 additions & 69 deletions test/integration/test_integration_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from rioxarray import open_rasterio
from rioxarray.merge import merge_arrays, merge_datasets
from test.conftest import RASTERIO_GE_13, RASTERIO_GE_125, TEST_INPUT_DATA_DIR
from test.conftest import TEST_INPUT_DATA_DIR


@pytest.mark.parametrize("squeeze", [True, False])
Expand All @@ -26,26 +26,12 @@ def test_merge_arrays(squeeze):
arrays = [array.squeeze() for array in arrays]
merged = merge_arrays(arrays)

if RASTERIO_GE_125:
assert_almost_equal(
merged.rio.bounds(),
(-7274009.6494863, 5003777.3385, -7227678.3778335, 5050108.6101528),
)
assert merged.rio.shape == (200, 200)
assert_almost_equal(merged.sum(), 22865733)

else:
assert_almost_equal(
merged.rio.bounds(),
(
-7274009.649486291,
5003545.682141737,
-7227446.721475236,
5050108.61015275,
),
)
assert merged.rio.shape == (201, 201)
assert_almost_equal(merged.sum(), 11368261)
assert_almost_equal(
merged.rio.bounds(),
(-7274009.6494863, 5003777.3385, -7227678.3778335, 5050108.6101528),
)
assert merged.rio.shape == (200, 200)
assert_almost_equal(merged.sum(), 22865733)

assert_almost_equal(
tuple(merged.rio.transform()),
Expand Down Expand Up @@ -91,23 +77,13 @@ def test_merge__different_crs(dataset):
test_sum = merged[merged.rio.vars[0]].sum()
else:
test_sum = merged.sum()
if RASTERIO_GE_125:
assert_almost_equal(
merged.rio.bounds(),
(-7300984.0238134, 5003618.5908794, -7224054.1109682, 5050108.6101528),
)
assert merged.rio.shape == (84, 139)
if RASTERIO_GE_13:
assert_almost_equal(test_sum, -131734881)
else:
assert_almost_equal(test_sum, -128605446)
else:
assert_almost_equal(
merged.rio.bounds(),
(-7300984.0238134, 5003618.5908794, -7223500.6583578, 5050108.6101528),
)
assert merged.rio.shape == (84, 140)
assert_almost_equal(test_sum, -131013894)
assert_almost_equal(
merged.rio.bounds(),
(-7300984.0238134, 5003618.5908794, -7224054.1109682, 5050108.6101528),
)
assert merged.rio.shape == (84, 139)
assert_almost_equal(test_sum, -131734881)

assert_almost_equal(
tuple(merged.rio.transform()),
(
Expand Down Expand Up @@ -148,18 +124,11 @@ def test_merge_arrays__res():
]
merged = merge_arrays(arrays, res=(300, 300))

if RASTERIO_GE_125:
assert_almost_equal(
merged.rio.bounds(),
(-7274009.6494863, 5003608.6101528, -7227509.6494863, 5050108.6101528),
)
assert merged.rio.shape == (155, 155)
else:
assert_almost_equal(
merged.rio.bounds(),
(-7274009.6494863, 5003308.6101528, -7227209.6494863, 5050108.6101528),
)
assert merged.rio.shape == (156, 156)
assert_almost_equal(
merged.rio.bounds(),
(-7274009.6494863, 5003608.6101528, -7227509.6494863, 5050108.6101528),
)
assert merged.rio.shape == (155, 155)

assert_almost_equal(
tuple(merged.rio.transform()),
Expand Down Expand Up @@ -214,25 +183,12 @@ def test_merge_datasets():
"sur_refl_b07_1",
]
data_var = data_vars[0]
if RASTERIO_GE_125:
assert_almost_equal(
merged[data_var].rio.bounds(),
(-4447802.078667, -10007554.677, -3335851.559, -8895604.157333),
)
assert merged.rio.shape == (2400, 2400)
assert_almost_equal(merged[data_var].sum(), 4539666606551516)
else:
assert_almost_equal(
merged[data_var].rio.bounds(),
(
-4447802.078667,
-10008017.989716524,
-3335388.246283474,
-8895604.157333,
),
)
assert merged.rio.shape == (2401, 2401)
assert_almost_equal(merged[data_var].sum(), 4543446965182987)
assert_almost_equal(
merged[data_var].rio.bounds(),
(-4447802.078667, -10007554.677, -3335851.559, -8895604.157333),
)
assert merged.rio.shape == (2400, 2400)
assert_almost_equal(merged[data_var].sum(), 4539666606551516)
assert_almost_equal(
tuple(merged[data_var].rio.transform()),
(
Expand Down
38 changes: 8 additions & 30 deletions test/integration/test_integration_rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
from test.conftest import (
GDAL_GE_361,
PYPROJ_LT_3,
RASTERIO_EQ_122,
RASTERIO_GE_13,
RASTERIO_LT_122,
TEST_COMPARE_DATA_DIR,
TEST_INPUT_DATA_DIR,
_assert_xarrays_equal,
Expand Down Expand Up @@ -382,16 +379,9 @@ def test_clip_box__auto_expand(modis_clip):

def test_clip_box__nodata_error(modis_clip):
with modis_clip["open"](modis_clip["input"]) as xdi:
var_match = ""
if hasattr(xdi, "name") and xdi.name:
var_match = " Data variable: __xarray_dataarray_variable__"
if RASTERIO_LT_122:
expected_exception = NoDataInBounds
else:
expected_exception = rasterio.errors.WindowError
var_match = "Bounds and transform are inconsistent"

with pytest.raises(expected_exception, match=var_match):
with pytest.raises(
rasterio.errors.WindowError, match="Bounds and transform are inconsistent"
):
xdi.rio.clip_box(
minx=-8272735.53951584, # xdi.x[5].values
miny=8048371.187465771, # xdi.y[7].values
Expand All @@ -405,19 +395,13 @@ def test_clip_box__one_dimension_error(modis_clip):
var_match = ""
if hasattr(xdi, "name") and xdi.name:
var_match = " Data variable: __xarray_dataarray_variable__"
if RASTERIO_EQ_122:
expected_exception = rasterio.errors.WindowError
var_match = "Bounds and transform are inconsistent"
else:
expected_exception = OneDimensionalRaster
var_match = (
"At least one of the clipped raster x,y coordinates has "
f"only one point.{var_match}"
)
# test exception after raster clipped
with pytest.raises(
expected_exception,
match=var_match,
OneDimensionalRaster,
match=(
"At least one of the clipped raster x,y coordinates has "
f"only one point.{var_match}"
),
):
xdi.rio.clip_box(
minx=-7272735.53951584, # xdi.x[5].values
Expand Down Expand Up @@ -477,10 +461,6 @@ def test_clip_box__reproject_bounds(modis_clip):
)


@pytest.mark.skipif(
not RASTERIO_GE_13,
reason="Antimeridian Support added in 1.3.0",
)
def test_clip_box__antimeridian():
xds = xarray.DataArray(
numpy.zeros((5, 5)),
Expand Down Expand Up @@ -968,7 +948,6 @@ def test_reproject__grid_mapping(modis_reproject):
with modis_reproject["open"](
modis_reproject["input"], **mask_args
) as mda, modis_reproject["open"](modis_reproject["compare"], **mask_args) as mdc:

# remove 'crs' attribute and add grid mapping
# keep a copy of the crs before setting the spatial_ref to 0 as that will
# set `rio.crs` to None.
Expand Down Expand Up @@ -1222,7 +1201,6 @@ def test_make_src_affine(open_func, modis_reproject):
with xarray.open_dataarray(
modis_reproject["input"], decode_coords="all"
) as xdi, open_func(modis_reproject["input"]) as xri:

# check the transform
attribute_transform = tuple(xdi.attrs["transform"])
attribute_transform_func = tuple(xdi.rio.transform())
Expand Down

0 comments on commit a7c81e6

Please sign in to comment.