Skip to content

Commit 03e60fc

Browse files
committed
Dask in now a true optional dep.
1 parent e6cb54d commit 03e60fc

27 files changed

+312
-70
lines changed

xrspatial/aspect.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
from __future__ import annotations
2+
13
from functools import partial
24
from math import atan2
35
from typing import Optional
46

5-
import dask.array as da
7+
try:
8+
import dask.array as da
9+
except ImportError:
10+
da = None
11+
12+
613
import numpy as np
714
import xarray as xr
815
from numba import cuda
916

10-
from xrspatial.utils import ArrayTypeFunctionMapping, cuda_args, ngjit, not_implemented_func
17+
from xrspatial.utils import ArrayTypeFunctionMapping, cuda_args, ngjit
1118

1219
# 3rd-party
1320
try:

xrspatial/classify.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import warnings
24
from functools import partial
35
from typing import List, Optional
@@ -12,7 +14,11 @@
1214
class cupy(object):
1315
ndarray = False
1416

15-
import dask.array as da
17+
try:
18+
import dask.array as da
19+
except ImportError:
20+
da = None
21+
1622
import numba as nb
1723
import numpy as np
1824

xrspatial/curvature.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
# std lib
24
from functools import partial
35
from typing import Optional, Union
@@ -9,7 +11,11 @@
911
class cupy(object):
1012
ndarray = False
1113

12-
import dask.array as da
14+
try:
15+
import dask.array as da
16+
except ImportError:
17+
da = None
18+
1319
import numpy as np
1420
import xarray as xr
1521
from numba import cuda

xrspatial/datasets/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import os
22

3-
import dask.array as da
3+
try:
4+
import dask.array as da
5+
except ImportError:
6+
da = None
7+
48
import datashader as ds
59
import noise
610
import numpy as np
@@ -76,6 +80,10 @@ def make_terrain(
7680
terrain : xarray.DataArray
7781
2D array of generated terrain values.
7882
"""
83+
84+
if da is None:
85+
raise Exception("make terrain requires dask.Array (pip install dask)")
86+
7987
def _func(arr, block_id=None):
8088
block_ystart = block_id[0] * arr.shape[0]
8189
block_xstart = block_id[1] * arr.shape[1]

xrspatial/focal.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1+
from __future__ import annotations
2+
3+
14
import copy
25
from functools import partial
36
from math import isnan
47
import math
58

6-
import dask.array as da
79
import numba as nb
810
import numpy as np
911
import pandas as pd
1012
import xarray as xr
13+
1114
from numba import cuda, prange
1215
from xarray import DataArray
1316

17+
18+
try:
19+
import dask.array as da
20+
except ImportError:
21+
da = None
22+
23+
1424
try:
1525
import cupy
1626
except ImportError:

xrspatial/hillshade.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
from functools import partial
33
from typing import Optional
44

5-
import dask.array as da
65
import numpy as np
6+
7+
try:
8+
import dask.array as da
9+
except ImportError:
10+
da = None
11+
712
import xarray as xr
813
from numba import cuda
914

@@ -178,12 +183,12 @@ def hillshade(agg: xr.DataArray,
178183
out = _run_cupy(agg.data, azimuth, angle_altitude)
179184

180185
# dask + cupy case
181-
elif (has_cuda_and_cupy() and isinstance(agg.data, da.Array) and
186+
elif (has_cuda_and_cupy() and da is not None and isinstance(agg.data, da.Array) and
182187
is_cupy_backed(agg)):
183188
raise NotImplementedError("Dask/CuPy hillshade not implemented")
184189

185190
# dask + numpy case
186-
elif isinstance(agg.data, da.Array):
191+
elif da is not None and isinstance(agg.data, da.Array):
187192
out = _run_dask_numpy(agg.data, azimuth, angle_altitude)
188193

189194
else:

xrspatial/multispectral.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
from __future__ import annotations
2+
13
import warnings
24
from math import sqrt
35

4-
import dask.array as da
56
import numba as nb
67
import numpy as np
78
import xarray as xr
@@ -18,6 +19,11 @@
1819
class cupy(object):
1920
ndarray = False
2021

22+
try:
23+
import dask.array as da
24+
except ImportError:
25+
da = None
26+
2127

2228
@ngjit
2329
def _arvi_cpu(nir_data, red_data, blue_data):

xrspatial/perlin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
# std lib
24
from functools import partial
35

@@ -11,7 +13,11 @@
1113
class cupy(object):
1214
ndarray = False
1315

14-
import dask.array as da
16+
try:
17+
import dask.array as da
18+
except ImportError:
19+
da = None
20+
1521
import numba as nb
1622
from numba import cuda, jit
1723

xrspatial/proximity.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from math import sqrt
22

3-
import dask.array as da
3+
try:
4+
import dask.array as da
5+
except ImportError:
6+
da = None
7+
48
import numpy as np
59
import xarray as xr
610
from numba import prange
@@ -619,7 +623,7 @@ def _process_dask(raster, xs, ys):
619623
# numpy case
620624
result = _process_numpy(raster.data, xs, ys)
621625

622-
elif isinstance(raster.data, da.Array):
626+
elif da is not None and isinstance(raster.data, da.Array):
623627
# dask + numpy case
624628
xs = da.from_array(xs, chunks=(raster.chunks))
625629
ys = da.from_array(ys, chunks=(raster.chunks))

xrspatial/slope.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
# std lib
24
from functools import partial
35
from math import atan
@@ -10,14 +12,17 @@
1012
class cupy(object):
1113
ndarray = False
1214

13-
import dask.array as da
15+
try:
16+
import dask.array as da
17+
except ImportError:
18+
da = None
19+
1420
import numpy as np
1521
import xarray as xr
1622
from numba import cuda
1723

1824
# local modules
19-
from xrspatial.utils import (ArrayTypeFunctionMapping, cuda_args, get_dataarray_resolution, ngjit,
20-
not_implemented_func)
25+
from xrspatial.utils import (ArrayTypeFunctionMapping, cuda_args, get_dataarray_resolution, ngjit)
2126

2227

2328
@ngjit
@@ -64,6 +69,7 @@ def _run_dask_numpy(data: da.Array,
6469
meta=np.array(()))
6570
return out
6671

72+
6773
def _run_dask_cupy(data: da.Array,
6874
cellsize_x: Union[int, float],
6975
cellsize_y: Union[int, float]) -> da.Array:
@@ -79,7 +85,6 @@ def _run_dask_cupy(data: da.Array,
7985
return out
8086

8187

82-
8388
@cuda.jit(device=True)
8489
def _gpu(arr, cellsize_x, cellsize_y):
8590
a = arr[2, 0]

0 commit comments

Comments
 (0)