Skip to content

Commit a63a7ab

Browse files
authored
Merge pull request #264 from ecmwf/develop
new_version
2 parents 0c02e41 + 32c765c commit a63a7ab

File tree

9 files changed

+62
-502
lines changed

9 files changed

+62
-502
lines changed

docs/Service/Examples/vertical_profile_example.ipynb

Lines changed: 23 additions & 480 deletions
Large diffs are not rendered by default.

polytope_feature/datacube/transformations/datacube_cyclic/datacube_cyclic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
from copy import deepcopy
33

4-
from ....utility.combinatorics import unique
4+
from ....utility.list_tools import unique
55
from ..datacube_transformations import DatacubeAxisTransformation
66

77

polytope_feature/engine/hullslicer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from ..datacube.datacube_axis import UnsliceableDatacubeAxis
1010
from ..datacube.tensor_index_tree import TensorIndexTree
1111
from ..shapes import ConvexPolytope
12-
from ..utility.combinatorics import argmax, argmin, group, tensor_product, unique
12+
from ..utility.combinatorics import group, tensor_product
1313
from ..utility.exceptions import UnsliceableShapeError
1414
from ..utility.geometry import lerp
15+
from ..utility.list_tools import argmax, argmin, unique
1516
from .engine import Engine
1617

1718

polytope_feature/shapes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import copy
22
import math
3+
import warnings
34
from abc import ABC, abstractmethod
45
from typing import List
56

67
import tripy
78

9+
from .utility.list_tools import unique
10+
811
"""
912
Shapes used for the constructive geometry API of Polytope
1013
"""
@@ -60,11 +63,13 @@ def polytope(self):
6063

6164
# This is the only shape which can slice on axes without a discretizer or interpolator
6265
class Select(Shape):
63-
"""Matches several discrete value"""
66+
"""Matches several discrete values"""
6467

6568
def __init__(self, axis, values, method=None):
6669
self.axis = axis
67-
self.values = values
70+
self.values = unique(values)
71+
if len(self.values) != len(values):
72+
warnings.warn("Duplicate request values were removed")
6873
self.method = method
6974

7075
def axes(self):

polytope_feature/utility/combinatorics.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,3 @@ def validate_axes(actual_axes, test_axes):
4646
raise AxisNotFoundError(ax)
4747

4848
return True
49-
50-
51-
def unique(points):
52-
points.sort()
53-
points = [k for k, _ in itertools.groupby(points)]
54-
return points
55-
56-
57-
def argmin(points):
58-
amin = min(range(len(points)), key=points.__getitem__)
59-
return amin
60-
61-
62-
def argmax(points):
63-
amax = max(range(len(points)), key=points.__getitem__)
64-
return amax

polytope_feature/utility/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, axis):
1313
self.axis = axis
1414
self.message = (
1515
f"Axis {axis} is overdefined. You have used it in two or more input polytopes which"
16-
f"cannot form a union (because they span different axes)."
16+
f" cannot form a union (because they span different axes)."
1717
)
1818

1919

polytope_feature/utility/list_tools.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import itertools
2+
3+
14
def bisect_left_cmp(arr, val, cmp):
25
left = -1
36
r = len(arr)
@@ -20,3 +23,19 @@ def bisect_right_cmp(arr, val, cmp):
2023
else:
2124
r = e
2225
return r
26+
27+
28+
def unique(points):
29+
points.sort()
30+
points = [k for k, _ in itertools.groupby(points)]
31+
return points
32+
33+
34+
def argmin(points):
35+
amin = min(range(len(points)), key=points.__getitem__)
36+
return amin
37+
38+
39+
def argmax(points):
40+
amax = max(range(len(points)), key=points.__getitem__)
41+
return amax

polytope_feature/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.14"
1+
__version__ = "1.0.15"

tests/test_slicing_xarray_3D.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,11 @@ def test_intersection_point_disk_polygon(self):
249249
result = self.API.retrieve(request)
250250
paths = [r.flatten().values() for r in result.leaves]
251251
assert ((pd.Timestamp("2000-01-01 00:00:00"),), (3,), (1,)) in paths
252+
253+
def test_duplicate_values_select(self):
254+
request = Request(Select("step", [3, 3]), Select("level", [1]), Select("date", ["2000-01-01"]))
255+
result = self.API.retrieve(request)
256+
result.pprint()
257+
assert len(result.leaves) == 1
258+
path = result.leaves[0].flatten()["step"]
259+
assert len(path) == 1

0 commit comments

Comments
 (0)