Skip to content

Commit c3ba410

Browse files
author
Emma Ai
committed
remove expr_eval
1 parent 92c45e6 commit c3ba410

File tree

8 files changed

+11
-51
lines changed

8 files changed

+11
-51
lines changed

odc/stats/_algebra.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,7 @@
55
import dask.array as da
66
import xarray as xr
77
import numpy as np
8-
import numexpr as ne
9-
import functools
108
from dask.base import tokenize
11-
from typing import Any, Dict, Optional
12-
from odc.algo._dask import flatten_kv, unflatten_kv
13-
14-
15-
def apply_numexpr_np(
16-
expr: str,
17-
data: Optional[Dict[str, Any]] = None,
18-
dtype=None,
19-
casting="safe",
20-
order="K",
21-
**params,
22-
) -> np.ndarray:
23-
"""
24-
Apply numexpr to numpy arrays
25-
"""
26-
27-
if data is None:
28-
data = params
29-
else:
30-
data.update(params)
31-
32-
out = ne.evaluate(expr, local_dict=data, casting=casting, order=order)
33-
if dtype is None:
34-
return out
35-
else:
36-
return out.astype(dtype)
37-
38-
39-
def expr_eval(expr, data, dtype="float32", name="expr_eval", **kwargs):
40-
tk = tokenize(apply_numexpr_np, *flatten_kv(data))
41-
op = functools.partial(
42-
apply_numexpr_np, expr, dtype=dtype, casting="unsafe", order="K", **kwargs
43-
)
44-
45-
return da.map_blocks(
46-
lambda op, *data: op(unflatten_kv(data)),
47-
op,
48-
*flatten_kv(data),
49-
name=f"{name}_{tk}",
50-
dtype=dtype,
51-
meta=np.array((), dtype=dtype),
52-
)
539

5410

5511
def _median_by_ind(a):

odc/stats/plugins/lc_fc_wo_a0.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
to_float,
1717
_nodata_fuser,
1818
)
19-
from odc.stats._algebra import expr_eval, median_ds
19+
from odc.stats._algebra import median_ds
20+
from odc.algo import expr_eval
2021

2122
from ._registry import StatsPluginInterface, register
2223

odc/stats/plugins/lc_level34.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from ._registry import StatsPluginInterface, register
1515
from ._utils import rasterize_vector_mask, generate_numexpr_expressions
16-
from odc.stats._algebra import expr_eval
16+
from odc.algo import expr_eval
1717
from osgeo import gdal
1818

1919
NODATA = 255
@@ -28,6 +28,7 @@ class StatsLccsLevel4(StatsPluginInterface):
2828

2929
def __init__(
3030
self,
31+
*,
3132
class_def_path: str = None,
3233
class_condition: Dict[str, List] = None,
3334
urban_mask: str = None,

odc/stats/plugins/lc_ml_treelite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from odc.algo._memsink import yxbt_sink, yxt_sink
1919
from odc.stats.io import load_with_native_transform
2020

21-
from odc.stats._algebra import expr_eval
21+
from odc.algo import expr_eval
2222
from odc.stats.model import DateTimeRange
2323
from ._registry import StatsPluginInterface
2424
from ._worker import TreeliteModelPlugin

odc/stats/plugins/lc_tf_urban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from odc.algo._memsink import yxbt_sink
1717
from odc.stats.io import load_with_native_transform
1818

19-
from odc.stats._algebra import expr_eval
19+
from odc.algo import expr_eval
2020
from ._registry import StatsPluginInterface, register
2121
from ._worker import TensorFlowLiteModelPlugin
2222

odc/stats/plugins/lc_treelite_cultivated.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import dask.array as da
88
import numexpr as ne
99

10-
from odc.stats._algebra import expr_eval
10+
from odc.io import expr_eval
1111
from ._registry import register
1212
from .lc_ml_treelite import StatsMLTree, mask_and_predict
1313

@@ -53,6 +53,7 @@ def feature_BSI(input_block, nbart_swir_1, nbart_red, nbart_nir, nbart_blue):
5353
).astype("float32")
5454

5555

56+
# pylint: disable=too-many-positional-arguments
5657
def feature_TCW(
5758
input_block,
5859
nbart_blue,

odc/stats/plugins/lc_treelite_woody.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import xarray as xr
66
import dask.array as da
77

8-
from odc.stats._algebra import expr_eval
8+
from odc.io import expr_eval
99
from ._registry import register
1010
from .lc_ml_treelite import StatsMLTree, mask_and_predict
1111

odc/stats/plugins/lc_veg_class_a1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
import xarray as xr
9-
from odc.stats._algebra import expr_eval
9+
from odc.algo import expr_eval
1010

1111
from ._registry import StatsPluginInterface, register
1212
from ._utils import replace_nodata_with_mode
@@ -52,6 +52,7 @@ class StatsVegClassL1(StatsPluginInterface):
5252

5353
def __init__(
5454
self,
55+
*,
5556
output_classes: Dict,
5657
dem_threshold: Optional[int] = None,
5758
mudflat_threshold: Optional[int] = None,

0 commit comments

Comments
 (0)