From bf0d84658ce5a5d24bc853af0004f1fe08a837d3 Mon Sep 17 00:00:00 2001 From: Kristen Thyng Date: Fri, 28 Jan 2022 17:21:25 -0600 Subject: [PATCH 1/3] added mfdataset to opendap --- intake_xarray/opendap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/intake_xarray/opendap.py b/intake_xarray/opendap.py index 3c1fc7e..4955e5b 100644 --- a/intake_xarray/opendap.py +++ b/intake_xarray/opendap.py @@ -90,5 +90,9 @@ def _get_store(self): def _open_dataset(self): import xarray as xr - store = self._get_store() - self._ds = xr.open_dataset(store, chunks=self.chunks, **self._kwargs) + + if "*" in self.urlpath or isinstance(self.urlpath, list): + self._ds = xr.open_mfdataset(self.urlpath, chunks=self.chunks, **self._kwargs) + else: + store = self._get_store() + self._ds = xr.open_dataset(store, chunks=self.chunks, **self._kwargs) \ No newline at end of file From 924fe1921127226b9ab0d23956f689b1292b0fb2 Mon Sep 17 00:00:00 2001 From: Kristen Thyng Date: Mon, 31 Jan 2022 10:09:06 -0600 Subject: [PATCH 2/3] added tests Added tests for opendap with 1 link and with 2 links. --- intake_xarray/tests/test_network.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/intake_xarray/tests/test_network.py b/intake_xarray/tests/test_network.py index 4526b39..a01210e 100644 --- a/intake_xarray/tests/test_network.py +++ b/intake_xarray/tests/test_network.py @@ -64,3 +64,20 @@ def test_open_netcdf_s3_simplecache(): ds = source.to_dask() assert isinstance(ds._file_obj, xr.backends.h5netcdf_.H5NetCDFStore) assert isinstance(ds, xr.core.dataarray.Dataset) + + +def test_open_opendap(): + url = 'https://www.ncei.noaa.gov/thredds/dodsC/model-cbofs-files/2021/12/nos.cbofs.fields.n001.20211231.t18z.nc' + + source = intake.open_opendap(url, engine='netcdf4', chunks={'time': 1}) + ds = source.to_dask() + assert isinstance(ds, xr.core.dataarray.Dataset) + + +def test_open_list_opendap(): + url1 = 'https://www.ncei.noaa.gov/thredds/dodsC/model-cbofs-files/2021/12/nos.cbofs.fields.n001.20211231.t18z.nc' + url2 = 'https://www.ncei.noaa.gov/thredds/dodsC/model-cbofs-files/2021/12/nos.cbofs.fields.n002.20211231.t18z.nc' + + source = intake.open_opendap([url1, url2], engine='netcdf4', chunks={'time': 1}) + ds = source.to_dask() + assert isinstance(ds, xr.core.dataarray.Dataset) From 472786bb2cd8b47fe8318a8d9c753b1ef0f112b1 Mon Sep 17 00:00:00 2001 From: Kristen Thyng Date: Mon, 31 Jan 2022 10:10:50 -0600 Subject: [PATCH 3/3] removed * for opendap --- intake_xarray/opendap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intake_xarray/opendap.py b/intake_xarray/opendap.py index 4955e5b..6c072ab 100644 --- a/intake_xarray/opendap.py +++ b/intake_xarray/opendap.py @@ -91,7 +91,7 @@ def _get_store(self): def _open_dataset(self): import xarray as xr - if "*" in self.urlpath or isinstance(self.urlpath, list): + if isinstance(self.urlpath, list): self._ds = xr.open_mfdataset(self.urlpath, chunks=self.chunks, **self._kwargs) else: store = self._get_store()