Skip to content

Commit 5499949

Browse files
snowman2keewis
andauthored
DEP: Deprecate rasterio backend (#5808)
* DEP: Deprecate rasterio backend * DOC: remove experimental Co-authored-by: keewis <[email protected]> * DOC: open rasterio in what's new Co-authored-by: keewis <[email protected]> * add a note to update deprecations on version change before releasing * add the github handle [skip-ci] Co-authored-by: keewis <[email protected]> Co-authored-by: Keewis <[email protected]>
1 parent a62e313 commit 5499949

File tree

6 files changed

+62
-34
lines changed

6 files changed

+62
-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.19.1
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.

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ What's New
1919

2020
v0.19.1 (unreleased)
2121
---------------------
22+
.. TODO(by keewis): update deprecations if we decide to skip 0.19.1
2223
2324
New Features
2425
~~~~~~~~~~~~
@@ -56,6 +57,8 @@ Breaking changes
5657
Deprecations
5758
~~~~~~~~~~~~
5859

60+
- Deprecate :py:func:`open_rasterio` (:issue:`4697`, :pull:`5808`).
61+
By `Alan Snow <https://github.com/snowman2>`_.
5962
- Set the default argument for `roll_coords` to `False` for :py:meth:`DataArray.roll`
6063
and :py:meth:`Dataset.roll`. (:pull:`5653`)
6164
By `Tom Nicholas <https://github.com/TomNicholas>`_.

xarray/backends/rasterio_.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ def open_rasterio(
170170
lock=None,
171171
**kwargs,
172172
):
173-
"""Open a file with rasterio (experimental).
173+
"""Open a file with rasterio.
174+
175+
.. deprecated:: 0.19.1
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
174180
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
@@ -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
@@ -4212,15 +4212,15 @@ class TestRasterio:
42124212
def test_serialization(self):
42134213
with create_tmp_geotiff(additional_attrs={}) as (tmp_file, expected):
42144214
# Write it to a netcdf and read again (roundtrip)
4215-
with xr.open_rasterio(tmp_file) as rioda:
4215+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42164216
with create_tmp_file(suffix=".nc") as tmp_nc_file:
42174217
rioda.to_netcdf(tmp_nc_file)
42184218
with xr.open_dataarray(tmp_nc_file) as ncds:
42194219
assert_identical(rioda, ncds)
42204220

42214221
def test_utm(self):
42224222
with create_tmp_geotiff() as (tmp_file, expected):
4223-
with xr.open_rasterio(tmp_file) as rioda:
4223+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42244224
assert_allclose(rioda, expected)
42254225
assert rioda.attrs["scales"] == (1.0, 1.0, 1.0)
42264226
assert rioda.attrs["offsets"] == (0.0, 0.0, 0.0)
@@ -4236,7 +4236,9 @@ def test_utm(self):
42364236
)
42374237

42384238
# Check no parse coords
4239-
with xr.open_rasterio(tmp_file, parse_coordinates=False) as rioda:
4239+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4240+
tmp_file, parse_coordinates=False
4241+
) as rioda:
42404242
assert "x" not in rioda.coords
42414243
assert "y" not in rioda.coords
42424244

@@ -4248,7 +4250,7 @@ def test_non_rectilinear(self):
42484250
transform=from_origin(0, 3, 1, 1).rotation(45), crs=None
42494251
) as (tmp_file, _):
42504252
# Default is to not parse coords
4251-
with xr.open_rasterio(tmp_file) as rioda:
4253+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42524254
assert "x" not in rioda.coords
42534255
assert "y" not in rioda.coords
42544256
assert "crs" not in rioda.attrs
@@ -4276,7 +4278,7 @@ def test_platecarree(self):
42764278
crs="+proj=latlong",
42774279
open_kwargs={"nodata": -9765},
42784280
) as (tmp_file, expected):
4279-
with xr.open_rasterio(tmp_file) as rioda:
4281+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
42804282
assert_allclose(rioda, expected)
42814283
assert rioda.attrs["scales"] == (1.0,)
42824284
assert rioda.attrs["offsets"] == (0.0,)
@@ -4324,7 +4326,7 @@ def test_notransform(self):
43244326
"x": [0.5, 1.5, 2.5, 3.5],
43254327
},
43264328
)
4327-
with xr.open_rasterio(tmp_file) as rioda:
4329+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
43284330
assert_allclose(rioda, expected)
43294331
assert rioda.attrs["scales"] == (1.0, 1.0, 1.0)
43304332
assert rioda.attrs["offsets"] == (0.0, 0.0, 0.0)
@@ -4339,7 +4341,9 @@ def test_indexing(self):
43394341
with create_tmp_geotiff(
43404342
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
43414343
) as (tmp_file, expected):
4342-
with xr.open_rasterio(tmp_file, cache=False) as actual:
4344+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4345+
tmp_file, cache=False
4346+
) as actual:
43434347

43444348
# tests
43454349
# assert_allclose checks all data + coordinates
@@ -4455,7 +4459,7 @@ def test_caching(self):
44554459
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
44564460
) as (tmp_file, expected):
44574461
# Cache is the default
4458-
with xr.open_rasterio(tmp_file) as actual:
4462+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as actual:
44594463

44604464
# This should cache everything
44614465
assert_allclose(actual, expected)
@@ -4471,7 +4475,9 @@ def test_chunks(self):
44714475
8, 10, 3, transform_args=[1, 2, 0.5, 2.0], crs="+proj=latlong"
44724476
) as (tmp_file, expected):
44734477
# Chunk at open time
4474-
with xr.open_rasterio(tmp_file, chunks=(1, 2, 2)) as actual:
4478+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4479+
tmp_file, chunks=(1, 2, 2)
4480+
) as actual:
44754481

44764482
import dask.array as da
44774483

@@ -4493,7 +4499,7 @@ def test_chunks(self):
44934499
def test_pickle_rasterio(self):
44944500
# regression test for https://github.com/pydata/xarray/issues/2121
44954501
with create_tmp_geotiff() as (tmp_file, expected):
4496-
with xr.open_rasterio(tmp_file) as rioda:
4502+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
44974503
temp = pickle.dumps(rioda)
44984504
with pickle.loads(temp) as actual:
44994505
assert_equal(actual, rioda)
@@ -4545,7 +4551,7 @@ def test_ENVI_tags(self):
45454551
}
45464552
expected = DataArray(data, dims=("band", "y", "x"), coords=coords)
45474553

4548-
with xr.open_rasterio(tmp_file) as rioda:
4554+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45494555
assert_allclose(rioda, expected)
45504556
assert isinstance(rioda.attrs["crs"], str)
45514557
assert isinstance(rioda.attrs["res"], tuple)
@@ -4560,7 +4566,7 @@ def test_ENVI_tags(self):
45604566
def test_geotiff_tags(self):
45614567
# Create a geotiff file with some tags
45624568
with create_tmp_geotiff() as (tmp_file, _):
4563-
with xr.open_rasterio(tmp_file) as rioda:
4569+
with pytest.warns(DeprecationWarning), xr.open_rasterio(tmp_file) as rioda:
45644570
assert isinstance(rioda.attrs["AREA_OR_POINT"], str)
45654571

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

45814589
assert isinstance(actual.data, da.Array)
@@ -4586,10 +4594,12 @@ def test_http_url(self):
45864594
# more examples urls here
45874595
# http://download.osgeo.org/geotiff/samples/
45884596
url = "http://download.osgeo.org/geotiff/samples/made_up/ntf_nord.tif"
4589-
with xr.open_rasterio(url) as actual:
4597+
with pytest.warns(DeprecationWarning), xr.open_rasterio(url) as actual:
45904598
assert actual.shape == (1, 512, 512)
45914599
# make sure chunking works
4592-
with xr.open_rasterio(url, chunks=(1, 256, 256)) as actual:
4600+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4601+
url, chunks=(1, 256, 256)
4602+
) as actual:
45934603
import dask.array as da
45944604

45954605
assert isinstance(actual.data, da.Array)
@@ -4601,7 +4611,9 @@ def test_rasterio_environment(self):
46014611
# Should fail with error since suffix not allowed
46024612
with pytest.raises(Exception):
46034613
with rasterio.Env(GDAL_SKIP="GTiff"):
4604-
with xr.open_rasterio(tmp_file) as actual:
4614+
with pytest.warns(DeprecationWarning), xr.open_rasterio(
4615+
tmp_file
4616+
) as actual:
46054617
assert_allclose(actual, expected)
46064618

46074619
@pytest.mark.xfail(reason="rasterio 1.1.1 is broken. GH3573")
@@ -4618,7 +4630,7 @@ def test_rasterio_vrt(self):
46184630
# Value of single pixel in center of image
46194631
lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2)
46204632
expected_val = next(vrt.sample([(lon, lat)]))
4621-
with xr.open_rasterio(vrt) as da:
4633+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46224634
actual_shape = (da.sizes["x"], da.sizes["y"])
46234635
actual_crs = da.crs
46244636
actual_res = da.res
@@ -4672,7 +4684,7 @@ def test_rasterio_vrt_with_src_crs(self):
46724684
with rasterio.open(tmp_file) as src:
46734685
assert src.crs is None
46744686
with rasterio.vrt.WarpedVRT(src, src_crs=src_crs) as vrt:
4675-
with xr.open_rasterio(vrt) as da:
4687+
with pytest.warns(DeprecationWarning), xr.open_rasterio(vrt) as da:
46764688
assert da.crs == src_crs
46774689

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