Skip to content

Commit 588c8d0

Browse files
authored
Merge pull request #132 from martindurant/updates
fix things that have gone old
2 parents 0366621 + 301f519 commit 588c8d0

File tree

9 files changed

+25
-13
lines changed

9 files changed

+25
-13
lines changed

ci/environment-py310.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ dependencies:
2121
- zarr
2222
- moto < 3
2323
- s3fs
24+
- rioxarray
2425
- werkzeug < 2.2.0

ci/environment-py38.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ dependencies:
2121
- zarr
2222
- moto < 3
2323
- s3fs
24+
- rioxarray
2425
- werkzeug < 2.2.0

ci/environment-py39.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ dependencies:
2121
- zarr
2222
- moto < 3
2323
- s3fs
24+
- rioxarray
2425
- werkzeug < 2.2.0

ci/environment-upstream.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies:
2424
- rioxarray
2525
- gdal
2626
- werkzeug < 2.2.0
27+
- rioxarray
2728
- pip:
2829
- git+https://github.com/fsspec/filesystem_spec.git
2930
- git+https://github.com/intake/intake.git

intake_xarray/raster.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from intake.source.utils import reverse_formats
55
from .base import DataSourceMixin, Schema
66

7-
import glob
8-
97

108
class RasterIOSource(DataSourceMixin, PatternMixin):
119
"""Open a xarray dataset via RasterIO.
@@ -59,7 +57,9 @@ def __init__(self, urlpath, chunks=None, concat_dim='concat_dim',
5957

6058
def _open_files(self, files):
6159
import xarray as xr
62-
das = [xr.open_rasterio(f, chunks=self.chunks, **self._kwargs)
60+
import rioxarray as rio
61+
62+
das = [rio.open_rasterio(f, chunks=self.chunks, **self._kwargs)
6363
for f in files]
6464
out = xr.concat(das, dim=self.dim)
6565

@@ -78,6 +78,7 @@ def _open_files(self, files):
7878

7979
def _open_dataset(self):
8080
import xarray as xr
81+
import rioxarray as rio
8182
if self._can_be_local:
8283
files = fsspec.open_local(self.urlpath, **self.storage_options)
8384
else:
@@ -87,8 +88,8 @@ def _open_dataset(self):
8788
if isinstance(files, list):
8889
self._ds = self._open_files(files)
8990
else:
90-
self._ds = xr.open_rasterio(files, chunks=self.chunks,
91-
**self._kwargs)
91+
self._ds = rio.open_rasterio(files, chunks=self.chunks,
92+
**self._kwargs)
9293

9394
def _get_schema(self):
9495
"""Make schema object, which embeds xarray object and some details"""

intake_xarray/tests/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_coerce_shape_array_non_int():
125125
expected = np.append(array[:2, :], [[0], [0]], axis=1)
126126
actual = _coerce_shape(array, shape)
127127
assert (expected == actual).all()
128-
assert expected.dtype == np.float
128+
assert expected.dtype == "float"
129129

130130

131131
def test_read_image():

intake_xarray/tests/test_network.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import intake
33
import pytest
44
import xarray as xr
5-
import s3fs
6-
import gcsfs
5+
76

87
# RasterIOSource
8+
@pytest.mark.xfail
99
def test_open_rasterio_http():
1010
prefix = 'https://landsat-pds.s3.us-west-2.amazonaws.com/L8/139/045'
1111
image = 'LC81390452014295LGN00/LC81390452014295LGN00_B1.TIF'
@@ -37,9 +37,10 @@ def test_open_netcdf_gs():
3737
xarray_kwargs=dict(engine='h5netcdf'),
3838
)
3939
ds = source.to_dask()
40-
assert isinstance(ds._file_obj, xr.backends.h5netcdf_.H5NetCDFStore)
4140
assert isinstance(ds, xr.core.dataarray.Dataset)
4241

42+
43+
@pytest.mark.xfail
4344
def test_open_netcdf_s3():
4445
bucket = 's3://its-live-data.jpl.nasa.gov'
4546
key = 'icesat2/alt06/rel003/ATL06_20181230162257_00340206_003_01.h5'
@@ -53,6 +54,7 @@ def test_open_netcdf_s3():
5354
assert isinstance(ds, xr.core.dataarray.Dataset)
5455

5556

57+
@pytest.mark.xfail
5658
def test_open_netcdf_s3_simplecache():
5759
bucket = 's3://its-live-data.jpl.nasa.gov'
5860
key = 'icesat2/alt06/rel003/ATL06_20181230162257_00340206_003_01.h5'

intake_xarray/tests/test_remote.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def test_http_read_rasterio(data_server):
6565
source = intake.open_rasterio(url)
6666
da = source.read()
6767
# Following line: original file CRS appears to be updated
68-
assert "+init" in da.attrs['crs'] or "+proj" in da.attrs['crs']
68+
assert ("+init" in da.attrs.get('crs', "") or "+proj" in da.attrs.get('crs', "") or
69+
"PROJCS" in da.spatial_ref.attrs["crs_wkt"])
6970
assert da.attrs['AREA_OR_POINT'] == 'Area'
7071
assert da.dtype == 'uint8'
7172
assert da.isel(band=2,x=300,y=500).values == 129
@@ -231,7 +232,8 @@ def test_s3_read_rasterio(s3):
231232
source = intake.open_rasterio(url)
232233
da = source.read()
233234
# Following line: original file CRS appears to be updated
234-
assert "+init" in da.attrs['crs'] or "+proj" in da.attrs['crs']
235+
assert ("+init" in da.attrs.get('crs', "") or "+proj" in da.attrs.get('crs', "") or
236+
"PROJCS" in da.spatial_ref.attrs["crs_wkt"])
235237
assert da.attrs['AREA_OR_POINT'] == 'Area'
236238
assert da.dtype == 'uint8'
237239
assert da.isel(band=2,x=300,y=500).values == 129

intake_xarray/xarray_container.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ def _get_schema(self):
9797
# recreate dask arrays
9898
name = '-'.join(['remote-xarray', var, self._source_id])
9999
arr = self._ds[var].data
100-
chunks = arr.chunks
101-
nparts = (range(len(n)) for n in chunks)
100+
if hasattr(arr, "chunks"):
101+
chunks = arr.chunks
102+
nparts = (range(len(n)) for n in chunks)
103+
else:
104+
nparts = ((1,), )
102105
if self.metadata.get('array', False):
103106
# original was an array, not dataset - no variable name
104107
extra = ()

0 commit comments

Comments
 (0)