Skip to content

Commit 61ea6f5

Browse files
committed
DEP: Deprecate rasterio backend
1 parent bfff7f1 commit 61ea6f5

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
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: 31 additions & 19 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
@@ -4279,7 +4281,7 @@ def test_platecarree(self):
42794281
crs="+proj=latlong",
42804282
open_kwargs={"nodata": -9765},
42814283
) as (tmp_file, expected):
4282-
with xr.open_rasterio(tmp_file) as rioda:
4284+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42834285
assert_allclose(rioda, expected)
42844286
assert rioda.attrs["scales"] == (1.0,)
42854287
assert rioda.attrs["offsets"] == (0.0,)
@@ -4327,7 +4329,7 @@ def test_notransform(self):
43274329
"x": [0.5, 1.5, 2.5, 3.5],
43284330
},
43294331
)
4330-
with xr.open_rasterio(tmp_file) as rioda:
4332+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
43314333
assert_allclose(rioda, expected)
43324334
assert rioda.attrs["scales"] == (1.0, 1.0, 1.0)
43334335
assert rioda.attrs["offsets"] == (0.0, 0.0, 0.0)
@@ -4342,7 +4344,9 @@ def test_indexing(self):
43424344
with create_tmp_geotiff(
43434345
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
43444346
) as (tmp_file, expected):
4345-
with xr.open_rasterio(tmp_file, cache=False) as actual:
4347+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4348+
tmp_file, cache=False
4349+
) as actual:
43464350

43474351
# tests
43484352
# assert_allclose checks all data + coordinates
@@ -4458,7 +4462,7 @@ def test_caching(self):
44584462
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
44594463
) as (tmp_file, expected):
44604464
# Cache is the default
4461-
with xr.open_rasterio(tmp_file) as actual:
4465+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as actual:
44624466

44634467
# This should cache everything
44644468
assert_allclose(actual, expected)
@@ -4474,7 +4478,9 @@ def test_chunks(self):
44744478
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
44754479
) as (tmp_file, expected):
44764480
# Chunk at open time
4477-
with xr.open_rasterio(tmp_file, chunks=(1, 2, 2)) as actual:
4481+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4482+
tmp_file, chunks=(1, 2, 2)
4483+
) as actual:
44784484

44794485
import dask.array as da
44804486

@@ -4496,7 +4502,7 @@ def test_chunks(self):
44964502
def test_pickle_rasterio(self):
44974503
# regression test for https://github.com/pydata/xarray/issues/2121
44984504
with create_tmp_geotiff() as (tmp_file, expected):
4499-
with xr.open_rasterio(tmp_file) as rioda:
4505+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45004506
temp = pickle.dumps(rioda)
45014507
with pickle.loads(temp) as actual:
45024508
assert_equal(actual, rioda)
@@ -4548,7 +4554,7 @@ def test_ENVI_tags(self):
45484554
}
45494555
expected = DataArray(data, dims=("band", "y", "x"), coords=coords)
45504556

4551-
with xr.open_rasterio(tmp_file) as rioda:
4557+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45524558
assert_allclose(rioda, expected)
45534559
assert isinstance(rioda.attrs["crs"], str)
45544560
assert isinstance(rioda.attrs["res"], tuple)
@@ -4563,7 +4569,7 @@ def test_ENVI_tags(self):
45634569
def test_geotiff_tags(self):
45644570
# Create a geotiff file with some tags
45654571
with create_tmp_geotiff() as (tmp_file, _):
4566-
with xr.open_rasterio(tmp_file) as rioda:
4572+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45674573
assert isinstance(rioda.attrs["AREA_OR_POINT"], str)
45684574

45694575
@requires_dask
@@ -4578,7 +4584,9 @@ def test_no_mftime(self):
45784584
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
45794585
) as (tmp_file, expected):
45804586
with mock.patch("os.path.getmtime", side_effect=OSError):
4581-
with xr.open_rasterio(tmp_file, chunks=(1, 2, 2)) as actual:
4587+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4588+
tmp_file, chunks=(1, 2, 2)
4589+
) as actual:
45824590
import dask.array as da
45834591

45844592
assert isinstance(actual.data, da.Array)
@@ -4589,10 +4597,12 @@ def test_http_url(self):
45894597
# more examples urls here
45904598
# http://download.osgeo.org/geotiff/samples/
45914599
url = "http://download.osgeo.org/geotiff/samples/made_up/ntf_nord.tif"
4592-
with xr.open_rasterio(url) as actual:
4600+
with pytest.warns(DeprecationWarning), xr.open_rasterio(url) as actual:
45934601
assert actual.shape == (1, 512, 512)
45944602
# make sure chunking works
4595-
with xr.open_rasterio(url, chunks=(1, 256, 256)) as actual:
4603+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4604+
url, chunks=(1, 256, 256)
4605+
) as actual:
45964606
import dask.array as da
45974607

45984608
assert isinstance(actual.data, da.Array)
@@ -4604,7 +4614,9 @@ def test_rasterio_environment(self):
46044614
# Should fail with error since suffix not allowed
46054615
with pytest.raises(Exception):
46064616
with rasterio.Env(GDAL_SKIP="GTiff"):
4607-
with xr.open_rasterio(tmp_file) as actual:
4617+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4618+
tmp_file
4619+
) as actual:
46084620
assert_allclose(actual, expected)
46094621

46104622
@pytest.mark.xfail(reason="rasterio 1.1.1 is broken. GH3573")
@@ -4621,7 +4633,7 @@ def test_rasterio_vrt(self):
46214633
# Value of single pixel in center of image
46224634
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2)
46234635
expected_val = next(vrt.sample([(lon, lat)]))
4624-
with xr.open_rasterio(vrt) as da:
4636+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46254637
actual_shape = (da.sizes["x"], da.sizes["y"])
46264638
actual_crs = da.crs
46274639
actual_res = da.res
@@ -4675,7 +4687,7 @@ def test_rasterio_vrt_with_src_crs(self):
46754687
with rasterio.open(tmp_file) as src:
46764688
assert src.crs is None
46774689
with rasterio.vrt.WarpedVRT(src, src_crs=src_crs) as vrt:
4678-
with xr.open_rasterio(vrt) as da:
4690+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46794691
assert da.crs == src_crs
46804692

46814693
@network
@@ -4695,7 +4707,7 @@ def test_rasterio_vrt_network(self):
46954707
# Value of single pixel in center of image
46964708
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2)
46974709
expected_val = next(vrt.sample([(lon, lat)]))
4698-
with xr.open_rasterio(vrt) as da:
4710+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46994711
actual_shape = da.sizes["x"], da.sizes["y"]
47004712
actual_res = da.res
47014713
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)