Skip to content

Commit 88bd1a4

Browse files
committed
DEP: Deprecate rasterio backend
1 parent 7a65d59 commit 88bd1a4

File tree

5 files changed

+61
-34
lines changed

5 files changed

+61
-34
lines changed

doc/user-guide/io.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,12 @@ GeoTIFFs and other gridded raster datasets can be opened using `rasterio`_, if
742742
rasterio is installed. Here is an example of how to use
743743
:py:func:`open_rasterio` to read one of rasterio's `test files`_:
744744

745+
.. deprecated:: 0.20
746+
747+
Deprecated in favor of rioxarray.
748+
For information about transitioning, see:
749+
https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html
750+
745751
.. ipython::
746752
:verbatim:
747753

@@ -769,12 +775,6 @@ coordinates defined in the file's projection provided by the ``crs`` attribute.
769775
See :ref:`/examples/visualization_gallery.ipynb#Parsing-rasterio-geocoordinates`
770776
for an example of how to convert these to longitudes and latitudes.
771777

772-
.. warning::
773-
774-
This feature has been added in xarray v0.9.6 and should still be
775-
considered experimental. Please report any bugs you may find
776-
on xarray's github repository.
777-
778778

779779
Additionally, you can use `rioxarray`_ for reading in GeoTiff, netCDF or other
780780
GDAL readable raster data using `rasterio`_ as well as for exporting to a geoTIFF.

xarray/backends/rasterio_.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ def open_rasterio(
172172
):
173173
"""Open a file with rasterio (experimental).
174174
175+
.. deprecated:: 0.20
176+
177+
Deprecated in favor of rioxarray.
178+
For information about transitioning, see:
179+
https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html
180+
175181
This should work with any file that rasterio can open (most often:
176182
geoTIFF). The x and y coordinates are generated automatically from the
177183
file's geoinformation, shifted to the center of each pixel (see
@@ -252,6 +258,13 @@ def open_rasterio(
252258
data : DataArray
253259
The newly created DataArray.
254260
"""
261+
warnings.warn(
262+
"open_rasterio is Deprecated in favor of rioxarray. "
263+
"For information about transitioning, see: "
264+
"https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html",
265+
DeprecationWarning,
266+
stacklevel=2,
267+
)
255268
import rasterio
256269
from rasterio.vrt import WarpedVRT
257270

xarray/tests/test_backends.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,15 +4215,15 @@ class TestRasterio:
42154215
def test_serialization(self):
42164216
with create_tmp_geotiff(additional_attrs={}) as (tmp_file, expected):
42174217
# Write it to a netcdf and read again (roundtrip)
4218-
with xr.open_rasterio(tmp_file) as rioda:
4218+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42194219
with create_tmp_file(suffix=".nc") as tmp_nc_file:
42204220
rioda.to_netcdf(tmp_nc_file)
42214221
with xr.open_dataarray(tmp_nc_file) as ncds:
42224222
assert_identical(rioda, ncds)
42234223

42244224
def test_utm(self):
42254225
with create_tmp_geotiff() as (tmp_file, expected):
4226-
with xr.open_rasterio(tmp_file) as rioda:
4226+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42274227
assert_allclose(rioda, expected)
42284228
assert rioda.attrs["scales"] == (1.0, 1.0, 1.0)
42294229
assert rioda.attrs["offsets"] == (0.0, 0.0, 0.0)
@@ -4239,7 +4239,9 @@ def test_utm(self):
42394239
)
42404240

42414241
# Check no parse coords
4242-
with xr.open_rasterio(tmp_file, parse_coordinates=False) as rioda:
4242+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4243+
tmp_file, parse_coordinates=False
4244+
) as rioda:
42434245
assert "x" not in rioda.coords
42444246
assert "y" not in rioda.coords
42454247

@@ -4251,7 +4253,7 @@ def test_non_rectilinear(self):
42514253
transform=from_origin(0, 3, 1, 1).rotation(45), crs=None
42524254
) as (tmp_file, _):
42534255
# Default is to not parse coords
4254-
with xr.open_rasterio(tmp_file) as rioda:
4256+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42554257
assert "x" not in rioda.coords
42564258
assert "y" not in rioda.coords
42574259
assert "crs" not in rioda.attrs
@@ -4266,7 +4268,9 @@ def test_non_rectilinear(self):
42664268

42674269
# See if a warning is raised if we force it
42684270
with pytest.warns(Warning, match="transformation isn't rectilinear"):
4269-
with xr.open_rasterio(tmp_file, parse_coordinates=True) as rioda:
4271+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4272+
tmp_file, parse_coordinates=True
4273+
) as rioda:
42704274
assert "x" not in rioda.coords
42714275
assert "y" not in rioda.coords
42724276

@@ -4279,7 +4283,7 @@ def test_platecarree(self):
42794283
crs="+proj=latlong",
42804284
open_kwargs={"nodata": -9765},
42814285
) as (tmp_file, expected):
4282-
with xr.open_rasterio(tmp_file) as rioda:
4286+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42834287
assert_allclose(rioda, expected)
42844288
assert rioda.attrs["scales"] == (1.0,)
42854289
assert rioda.attrs["offsets"] == (0.0,)
@@ -4327,7 +4331,7 @@ def test_notransform(self):
43274331
"x": [0.5, 1.5, 2.5, 3.5],
43284332
},
43294333
)
4330-
with xr.open_rasterio(tmp_file) as rioda:
4334+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
43314335
assert_allclose(rioda, expected)
43324336
assert rioda.attrs["scales"] == (1.0, 1.0, 1.0)
43334337
assert rioda.attrs["offsets"] == (0.0, 0.0, 0.0)
@@ -4342,7 +4346,9 @@ def test_indexing(self):
43424346
with create_tmp_geotiff(
43434347
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
43444348
) as (tmp_file, expected):
4345-
with xr.open_rasterio(tmp_file, cache=False) as actual:
4349+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4350+
tmp_file, cache=False
4351+
) as actual:
43464352

43474353
# tests
43484354
# assert_allclose checks all data + coordinates
@@ -4458,7 +4464,7 @@ def test_caching(self):
44584464
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
44594465
) as (tmp_file, expected):
44604466
# Cache is the default
4461-
with xr.open_rasterio(tmp_file) as actual:
4467+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as actual:
44624468

44634469
# This should cache everything
44644470
assert_allclose(actual, expected)
@@ -4474,7 +4480,9 @@ def test_chunks(self):
44744480
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
44754481
) as (tmp_file, expected):
44764482
# Chunk at open time
4477-
with xr.open_rasterio(tmp_file, chunks=(1, 2, 2)) as actual:
4483+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4484+
tmp_file, chunks=(1, 2, 2)
4485+
) as actual:
44784486

44794487
import dask.array as da
44804488

@@ -4496,7 +4504,7 @@ def test_chunks(self):
44964504
def test_pickle_rasterio(self):
44974505
# regression test for https://github.com/pydata/xarray/issues/2121
44984506
with create_tmp_geotiff() as (tmp_file, expected):
4499-
with xr.open_rasterio(tmp_file) as rioda:
4507+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45004508
temp = pickle.dumps(rioda)
45014509
with pickle.loads(temp) as actual:
45024510
assert_equal(actual, rioda)
@@ -4548,7 +4556,7 @@ def test_ENVI_tags(self):
45484556
}
45494557
expected = DataArray(data, dims=("band", "y", "x"), coords=coords)
45504558

4551-
with xr.open_rasterio(tmp_file) as rioda:
4559+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45524560
assert_allclose(rioda, expected)
45534561
assert isinstance(rioda.attrs["crs"], str)
45544562
assert isinstance(rioda.attrs["res"], tuple)
@@ -4563,7 +4571,7 @@ def test_ENVI_tags(self):
45634571
def test_geotiff_tags(self):
45644572
# Create a geotiff file with some tags
45654573
with create_tmp_geotiff() as (tmp_file, _):
4566-
with xr.open_rasterio(tmp_file) as rioda:
4574+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45674575
assert isinstance(rioda.attrs["AREA_OR_POINT"], str)
45684576

45694577
@requires_dask
@@ -4578,7 +4586,9 @@ def test_no_mftime(self):
45784586
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
45794587
) as (tmp_file, expected):
45804588
with mock.patch("os.path.getmtime", side_effect=OSError):
4581-
with xr.open_rasterio(tmp_file, chunks=(1, 2, 2)) as actual:
4589+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4590+
tmp_file, chunks=(1, 2, 2)
4591+
) as actual:
45824592
import dask.array as da
45834593

45844594
assert isinstance(actual.data, da.Array)
@@ -4589,10 +4599,12 @@ def test_http_url(self):
45894599
# more examples urls here
45904600
# http://download.osgeo.org/geotiff/samples/
45914601
url = "http://download.osgeo.org/geotiff/samples/made_up/ntf_nord.tif"
4592-
with xr.open_rasterio(url) as actual:
4602+
with pytest.warns(DeprecationWarning), xr.open_rasterio(url) as actual:
45934603
assert actual.shape == (1, 512, 512)
45944604
# make sure chunking works
4595-
with xr.open_rasterio(url, chunks=(1, 256, 256)) as actual:
4605+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4606+
url, chunks=(1, 256, 256)
4607+
) as actual:
45964608
import dask.array as da
45974609

45984610
assert isinstance(actual.data, da.Array)
@@ -4604,7 +4616,9 @@ def test_rasterio_environment(self):
46044616
# Should fail with error since suffix not allowed
46054617
with pytest.raises(Exception):
46064618
with rasterio.Env(GDAL_SKIP="GTiff"):
4607-
with xr.open_rasterio(tmp_file) as actual:
4619+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4620+
tmp_file
4621+
) as actual:
46084622
assert_allclose(actual, expected)
46094623

46104624
@pytest.mark.xfail(reason="rasterio 1.1.1 is broken. GH3573")
@@ -4621,7 +4635,7 @@ def test_rasterio_vrt(self):
46214635
# Value of single pixel in center of image
46224636
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2)
46234637
expected_val = next(vrt.sample([(lon, lat)]))
4624-
with xr.open_rasterio(vrt) as da:
4638+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46254639
actual_shape = (da.sizes["x"], da.sizes["y"])
46264640
actual_crs = da.crs
46274641
actual_res = da.res
@@ -4675,7 +4689,7 @@ def test_rasterio_vrt_with_src_crs(self):
46754689
with rasterio.open(tmp_file) as src:
46764690
assert src.crs is None
46774691
with rasterio.vrt.WarpedVRT(src, src_crs=src_crs) as vrt:
4678-
with xr.open_rasterio(vrt) as da:
4692+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46794693
assert da.crs == src_crs
46804694

46814695
@network
@@ -4695,7 +4709,7 @@ def test_rasterio_vrt_network(self):
46954709
# Value of single pixel in center of image
46964710
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2)
46974711
expected_val = next(vrt.sample([(lon, lat)]))
4698-
with xr.open_rasterio(vrt) as da:
4712+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46994713
actual_shape = da.sizes["x"], da.sizes["y"]
47004714
actual_res = da.res
47014715
actual_val = da.sel(dict(x=lon, y=lat), method="nearest").data

xarray/tests/test_distributed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_dask_distributed_zarr_integration_test(loop, consolidated, compute) ->
163163
def test_dask_distributed_rasterio_integration_test(loop) -> None:
164164
with create_tmp_geotiff() as (tmp_file, expected):
165165
with cluster() as (s, [a, b]):
166-
with Client(s["address"], loop=loop):
166+
with pytest.warns(DeprecationWarning), Client(s["address"], loop=loop):
167167
da_tiff = xr.open_rasterio(tmp_file, chunks={"band": 1})
168168
assert isinstance(da_tiff.data, da.Array)
169169
actual = da_tiff.compute()

xarray/tests/test_tutorial.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def test_download_rasterio_from_github_load_without_cache(
3232
self, tmp_path, monkeypatch
3333
):
3434
cache_dir = tmp_path / tutorial._default_cache_dir_name
35-
36-
arr_nocache = tutorial.open_rasterio(
37-
"RGB.byte", cache=False, cache_dir=cache_dir
38-
).load()
39-
arr_cache = tutorial.open_rasterio(
40-
"RGB.byte", cache=True, cache_dir=cache_dir
41-
).load()
35+
with pytest.warns(DeprecationWarning):
36+
arr_nocache = tutorial.open_rasterio(
37+
"RGB.byte", cache=False, cache_dir=cache_dir
38+
).load()
39+
arr_cache = tutorial.open_rasterio(
40+
"RGB.byte", cache=True, cache_dir=cache_dir
41+
).load()
4242
assert_identical(arr_cache, arr_nocache)

0 commit comments

Comments
 (0)