From 2b429fb1203268ab4c0c2bd454a4575fd363c2c0 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Thu, 15 Jul 2021 15:55:53 +0200 Subject: [PATCH 01/10] Added kwargs option to be passed to rasterio.open --- xarray/backends/rasterio_.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index 49a5a9ec7ae..4b70d797074 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -162,7 +162,7 @@ def default(s): return parsed_meta -def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, lock=None): +def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, lock=None, kwargs=None): """Open a file with rasterio (experimental). This should work with any file that rasterio can open (most often: @@ -272,7 +272,7 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc if lock is None: lock = RASTERIO_LOCK - manager = CachingFileManager(rasterio.open, filename, lock=lock, mode="r") + manager = CachingFileManager(rasterio.open, filename, lock=lock, mode="r",kwargs=kwargs) riods = manager.acquire() if vrt_params is not None: riods = WarpedVRT(riods, **vrt_params) From 1af777a4b3f7e342c73dbda71d841852127795ea Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Thu, 15 Jul 2021 16:12:02 +0200 Subject: [PATCH 02/10] Added description to whats-new.rst --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 0053824c87b..c15760bdabe 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -53,6 +53,8 @@ New Features - Allow removal of the coordinate attribute ``coordinates`` on variables by setting ``.attrs['coordinates']= None`` (:issue:`5510`). By `Elle Smith `_. +- Added ``kwargs`` argument to xarray.open_rasterio to access overviews (`:issue:3269`). + By Pushkar Kopparla ``_. Breaking changes ~~~~~~~~~~~~~~~~ From 86afe8a97e2ca63de89fe43947edd0f829c4c761 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Thu, 15 Jul 2021 16:23:02 +0200 Subject: [PATCH 03/10] Fixed whitespace --- xarray/backends/rasterio_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index 4b70d797074..c3f56019827 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -272,7 +272,7 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc if lock is None: lock = RASTERIO_LOCK - manager = CachingFileManager(rasterio.open, filename, lock=lock, mode="r",kwargs=kwargs) + manager = CachingFileManager(rasterio.open, filename, lock=lock, mode="r", kwargs=kwargs) riods = manager.acquire() if vrt_params is not None: riods = WarpedVRT(riods, **vrt_params) From 39a45e75c508fca5b8f8c506a77a31b8af658dfd Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla <76039838+pkopparla@users.noreply.github.com> Date: Thu, 15 Jul 2021 17:37:28 +0200 Subject: [PATCH 04/10] Update doc/whats-new.rst Co-authored-by: Deepak Cherian --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c15760bdabe..0b910b7b4b0 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -53,7 +53,7 @@ New Features - Allow removal of the coordinate attribute ``coordinates`` on variables by setting ``.attrs['coordinates']= None`` (:issue:`5510`). By `Elle Smith `_. -- Added ``kwargs`` argument to xarray.open_rasterio to access overviews (`:issue:3269`). +- Added ``kwargs`` argument to xarray.open_rasterio to access overviews (:issue:`3269`). By Pushkar Kopparla ``_. Breaking changes From 768736ca2e7e49448de27ea14e2f5939083132e1 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla <76039838+pkopparla@users.noreply.github.com> Date: Fri, 16 Jul 2021 08:39:27 +0200 Subject: [PATCH 05/10] Update doc/whats-new.rst Co-authored-by: keewis --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 0b910b7b4b0..98d2569dc29 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -54,7 +54,7 @@ New Features (:issue:`5510`). By `Elle Smith `_. - Added ``kwargs`` argument to xarray.open_rasterio to access overviews (:issue:`3269`). - By Pushkar Kopparla ``_. + By `Pushkar Kopparla `_. Breaking changes ~~~~~~~~~~~~~~~~ From d399b8179d8043c4249680a7b060d04ce0943f97 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Fri, 16 Jul 2021 09:13:35 +0200 Subject: [PATCH 06/10] Updated whats-new.rst --- doc/whats-new.rst | 2 +- xarray/backends/rasterio_.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 98d2569dc29..0a9e790863b 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -53,7 +53,7 @@ New Features - Allow removal of the coordinate attribute ``coordinates`` on variables by setting ``.attrs['coordinates']= None`` (:issue:`5510`). By `Elle Smith `_. -- Added ``kwargs`` argument to xarray.open_rasterio to access overviews (:issue:`3269`). +- Added ``backend_kwargs`` and ``**kwargs`` arguments to xarray.open_rasterio to access overviews (:issue:`3269`). By `Pushkar Kopparla `_. Breaking changes diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index c3f56019827..b15ee0cf4b7 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -162,7 +162,15 @@ def default(s): return parsed_meta -def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, lock=None, kwargs=None): +def open_rasterio( + filename, + parse_coordinates=None, + chunks=None, + cache=None, + lock=None, + backend_kwargs=None, + **kwargs, +): """Open a file with rasterio (experimental). This should work with any file that rasterio can open (most often: @@ -272,7 +280,14 @@ def open_rasterio(filename, parse_coordinates=None, chunks=None, cache=None, loc if lock is None: lock = RASTERIO_LOCK - manager = CachingFileManager(rasterio.open, filename, lock=lock, mode="r", kwargs=kwargs) + manager = CachingFileManager( + rasterio.open, + filename, + lock=lock, + mode="r", + backend_kwargs=backend_kwargs, + **kwargs, + ) riods = manager.acquire() if vrt_params is not None: riods = WarpedVRT(riods, **vrt_params) From 08c74fc16745d00e6b974f130ffe181101815686 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Fri, 16 Jul 2021 16:04:41 +0200 Subject: [PATCH 07/10] Merged backend_kwargs with kwargs --- doc/whats-new.rst | 2 +- xarray/backends/rasterio_.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 0a9e790863b..2990a9d2104 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -53,7 +53,7 @@ New Features - Allow removal of the coordinate attribute ``coordinates`` on variables by setting ``.attrs['coordinates']= None`` (:issue:`5510`). By `Elle Smith `_. -- Added ``backend_kwargs`` and ``**kwargs`` arguments to xarray.open_rasterio to access overviews (:issue:`3269`). +- Added ``**kwargs`` argument to xarray.open_rasterio to access overviews (:issue:`3269`). By `Pushkar Kopparla `_. Breaking changes diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index b15ee0cf4b7..4f7ea0bdf24 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -279,14 +279,13 @@ def open_rasterio( if lock is None: lock = RASTERIO_LOCK - + kwargs.update(backend_kwargs) manager = CachingFileManager( rasterio.open, filename, lock=lock, mode="r", - backend_kwargs=backend_kwargs, - **kwargs, + kwargs=kwargs, ) riods = manager.acquire() if vrt_params is not None: From f4ae8783394b9515ebb67d2e903b18d6c97d4e62 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Fri, 16 Jul 2021 17:14:53 +0200 Subject: [PATCH 08/10] Added check for no kwargs --- xarray/backends/rasterio_.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index 4f7ea0bdf24..02671098882 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -279,7 +279,10 @@ def open_rasterio( if lock is None: lock = RASTERIO_LOCK - kwargs.update(backend_kwargs) + + if backend_kwargs is not None: + kwargs.update(backend_kwargs) + manager = CachingFileManager( rasterio.open, filename, From bbda7baacde7d35efce14822e13217062addde11 Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla <76039838+pkopparla@users.noreply.github.com> Date: Tue, 27 Jul 2021 11:18:43 +0200 Subject: [PATCH 09/10] Update doc/whats-new.rst Co-authored-by: keewis --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 458da38ba9c..09ffbb557f5 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -97,7 +97,7 @@ New Features - Allow removal of the coordinate attribute ``coordinates`` on variables by setting ``.attrs['coordinates']= None`` (:issue:`5510`). By `Elle Smith `_. -- Added ``**kwargs`` argument to xarray.open_rasterio to access overviews (:issue:`3269`). +- Added ``**kwargs`` argument to :py:meth:`open_rasterio` to access overviews (:issue:`3269`). By `Pushkar Kopparla `_. - Added :py:meth:`DataArray.to_numpy`, :py:meth:`DataArray.as_numpy`, and :py:meth:`Dataset.as_numpy`. (:pull:`5568`). By `Tom Nicholas `_. From f0f09610b361e9a66d87201377bbb36ee45880da Mon Sep 17 00:00:00 2001 From: Pushkar Kopparla Date: Tue, 27 Jul 2021 11:20:54 +0200 Subject: [PATCH 10/10] Removed backend_kwargs --- xarray/backends/rasterio_.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index 02671098882..1891fac8668 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -168,7 +168,6 @@ def open_rasterio( chunks=None, cache=None, lock=None, - backend_kwargs=None, **kwargs, ): """Open a file with rasterio (experimental). @@ -280,9 +279,6 @@ def open_rasterio( if lock is None: lock = RASTERIO_LOCK - if backend_kwargs is not None: - kwargs.update(backend_kwargs) - manager = CachingFileManager( rasterio.open, filename,