Skip to content

Commit bd43095

Browse files
authored
Merge pull request #82 from scottyhq/http-raster
Logic for remote versus local filepaths for RasterIOSource + GitHub Actions CI
2 parents aa40818 + 4e959ca commit bd43095

File tree

10 files changed

+98
-24
lines changed

10 files changed

+98
-24
lines changed

.github/workflows/main.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ on:
88

99
jobs:
1010
test:
11-
name: ${{ matrix.CONDA_ENV }}-build
11+
name: ${{ matrix.CONDA_ENV }}-pytest
1212
runs-on: ubuntu-latest
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
CONDA_ENV: [36, 36-defaults, 37-nodefaults]
16+
CONDA_ENV: [36, 37, 38, 37-upstream]
1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v2
@@ -24,7 +24,7 @@ jobs:
2424
auto-update-conda: true
2525
auto-activate-base: false
2626
activate-environment: test_env
27-
environment-file: ci/environment-${{ matrix.CONDA_ENV }}.yml
27+
environment-file: ci/environment-py${{ matrix.CONDA_ENV }}.yml
2828

2929
- name: Development Install Intake-Xarray
3030
shell: bash -l {0}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# intake-xarray
22

3-
[![Build Status](https://travis-ci.org/intake/intake-xarray.svg?branch=master)](https://travis-ci.org/intake/intake-xarray)
3+
![CI](https://github.com/intake/intake-xarray/workflows/CI/badge.svg)
44

55
Intake-xarray: xarray Plugin for [Intake](https://github.com/intake/intake)
66

ci/environment-py36.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ channels:
33
- conda-forge
44
dependencies:
55
- python=3.6
6-
- intake>=0.4.1
7-
- xarray>=0.11.2
8-
- zarr
9-
- pytest
6+
- aiohttp
7+
- intake
108
- netcdf4
119
- pip
1210
- pydap
11+
- pytest
1312
- rasterio
1413
- scikit-image
14+
- xarray
15+
- zarr
16+
- pip:
17+
- rangehttpserver

ci/environment-py37-upstream.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: test_env
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python=3.7
6+
- aiohttp
7+
- netcdf4
8+
- pip
9+
- pydap
10+
- pytest
11+
- rasterio
12+
- scikit-image
13+
- xarray
14+
- zarr
15+
- pip:
16+
- git+https://github.com/intake/filesystem_spec.git
17+
- git+https://github.com/intake/intake.git
18+
- rangehttpserver
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name: test_env
22
channels:
33
- conda-forge
4-
- defaults
54
dependencies:
65
- python=3.7
7-
- intake>=0.4.1
8-
- xarray
9-
- zarr
10-
- pytest
6+
- aiohttp
7+
- intake
118
- netcdf4
129
- pip
1310
- pydap
11+
- pytest
1412
- rasterio
1513
- scikit-image
14+
- xarray
15+
- zarr
16+
- pip:
17+
- rangehttpserver
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
name: test_env
2+
channels:
3+
- conda-forge
24
dependencies:
3-
- python=3.6
5+
- python=3.8
6+
- aiohttp
47
- intake
5-
- xarray
6-
- zarr
7-
- pytest
88
- netcdf4
9+
- pip
10+
- pydap
11+
- pytest
912
- rasterio
1013
- scikit-image
11-
- pip
14+
- xarray
15+
- zarr
16+
- pip:
17+
- rangehttpserver

intake_xarray/raster.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(self, urlpath, chunks, concat_dim='concat_dim',
5151
self.storage_options = storage_options or {}
5252
self._kwargs = xarray_kwargs or {}
5353
self._ds = None
54+
if isinstance(self.urlpath, list):
55+
self._can_be_local = fsspec.utils.can_be_local(self.urlpath[0])
56+
else:
57+
self._can_be_local = fsspec.utils.can_be_local(self.urlpath)
5458
super(RasterIOSource, self).__init__(metadata=metadata)
5559

5660
def _open_files(self, files):
@@ -74,7 +78,10 @@ def _open_files(self, files):
7478

7579
def _open_dataset(self):
7680
import xarray as xr
77-
files = fsspec.open_local(self.urlpath, **self.storage_options)
81+
if self._can_be_local:
82+
files = fsspec.open_local(self.urlpath, **self.storage_options)
83+
else:
84+
files = self.urlpath
7885
if isinstance(files, list):
7986
self._ds = self._open_files(files)
8087
else:

intake_xarray/tests/test_intake_xarray.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ def test_discover(source, netcdf_source, zarr_source, dataset):
1616
source = {'netcdf': netcdf_source, 'zarr': zarr_source}[source]
1717
r = source.discover()
1818

19-
assert r['datashape'] is None
2019
assert r['dtype'] is None
2120
assert r['metadata'] is not None
2221

23-
assert source.datashape is None
2422
assert source.metadata['dims'] == dict(dataset.dims)
2523
assert set(source.metadata['data_vars']) == set(dataset.data_vars.keys())
2624
assert set(source.metadata['coords']) == set(dataset.coords.keys())

intake_xarray/tests/test_remote.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,53 @@
55
import subprocess
66
import time
77
import xarray as xr
8+
import fsspec
89

9-
10-
PORT = 8425
10+
PORT = 8425 # for intake-server tests
1111
here = os.path.abspath(os.path.dirname(__file__))
1212
cat_file = os.path.join(here, 'data', 'catalog.yaml')
13+
DIRECTORY = os.path.join(here, 'data')
14+
15+
16+
@pytest.fixture(scope='module')
17+
def data_server():
18+
''' Serves test/data folder to http://localhost:8000 '''
19+
pwd = os.getcwd()
20+
os.chdir(DIRECTORY)
21+
command = ['python', '-m', 'RangeHTTPServer']
22+
try:
23+
P = subprocess.Popen(command)
24+
timeout = 10
25+
while True:
26+
try:
27+
requests.get('http://localhost:8000')
28+
break
29+
except:
30+
time.sleep(0.1)
31+
timeout -= 0.1
32+
assert timeout > 0
33+
yield 'http://localhost:8000'
34+
finally:
35+
os.chdir(pwd)
36+
P.terminate()
37+
P.communicate()
38+
39+
40+
def test_list(data_server):
41+
h = fsspec.filesystem("http")
42+
out = h.glob(data_server + '/')
43+
assert len(out) > 0
44+
assert data_server+'/RGB.byte.tif' in out
45+
46+
47+
def test_open_rasterio(data_server):
48+
url = f'{data_server}/RGB.byte.tif'
49+
source = intake.open_rasterio(url, chunks={})
50+
da = source.to_dask()
51+
assert isinstance(da, xr.core.dataarray.DataArray)
1352

1453

54+
# Remote catalogs with intake-server
1555
@pytest.fixture(scope='module')
1656
def intake_server():
1757
command = ['intake-server', '-p', str(PORT), cat_file]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from setuptools import setup, find_packages
1010
import versioneer
1111

12-
INSTALL_REQUIRES = ['intake >=0.5.2', 'xarray >=0.12.0', 'zarr', 'dask >=2.2', 'netcdf4']
12+
INSTALL_REQUIRES = ['intake >=0.5.2', 'xarray >=0.12.0', 'zarr', 'dask >=2.2', 'netcdf4', 'fsspec>0.8.3']
1313

1414
setup(
1515
name='intake-xarray',

0 commit comments

Comments
 (0)