Skip to content

Commit

Permalink
Merge pull request #264 from ecmwf/develop
Browse files Browse the repository at this point in the history
new_version
  • Loading branch information
mathleur authored Nov 18, 2024
2 parents 0c02e41 + 32c765c commit a63a7ab
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 502 deletions.
503 changes: 23 additions & 480 deletions docs/Service/Examples/vertical_profile_example.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
from copy import deepcopy

from ....utility.combinatorics import unique
from ....utility.list_tools import unique
from ..datacube_transformations import DatacubeAxisTransformation


Expand Down
3 changes: 2 additions & 1 deletion polytope_feature/engine/hullslicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from ..datacube.datacube_axis import UnsliceableDatacubeAxis
from ..datacube.tensor_index_tree import TensorIndexTree
from ..shapes import ConvexPolytope
from ..utility.combinatorics import argmax, argmin, group, tensor_product, unique
from ..utility.combinatorics import group, tensor_product
from ..utility.exceptions import UnsliceableShapeError
from ..utility.geometry import lerp
from ..utility.list_tools import argmax, argmin, unique
from .engine import Engine


Expand Down
9 changes: 7 additions & 2 deletions polytope_feature/shapes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import copy
import math
import warnings
from abc import ABC, abstractmethod
from typing import List

import tripy

from .utility.list_tools import unique

"""
Shapes used for the constructive geometry API of Polytope
"""
Expand Down Expand Up @@ -60,11 +63,13 @@ def polytope(self):

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

def __init__(self, axis, values, method=None):
self.axis = axis
self.values = values
self.values = unique(values)
if len(self.values) != len(values):
warnings.warn("Duplicate request values were removed")
self.method = method

def axes(self):
Expand Down
16 changes: 0 additions & 16 deletions polytope_feature/utility/combinatorics.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,3 @@ def validate_axes(actual_axes, test_axes):
raise AxisNotFoundError(ax)

return True


def unique(points):
points.sort()
points = [k for k, _ in itertools.groupby(points)]
return points


def argmin(points):
amin = min(range(len(points)), key=points.__getitem__)
return amin


def argmax(points):
amax = max(range(len(points)), key=points.__getitem__)
return amax
2 changes: 1 addition & 1 deletion polytope_feature/utility/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, axis):
self.axis = axis
self.message = (
f"Axis {axis} is overdefined. You have used it in two or more input polytopes which"
f"cannot form a union (because they span different axes)."
f" cannot form a union (because they span different axes)."
)


Expand Down
19 changes: 19 additions & 0 deletions polytope_feature/utility/list_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import itertools


def bisect_left_cmp(arr, val, cmp):
left = -1
r = len(arr)
Expand All @@ -20,3 +23,19 @@ def bisect_right_cmp(arr, val, cmp):
else:
r = e
return r


def unique(points):
points.sort()
points = [k for k, _ in itertools.groupby(points)]
return points


def argmin(points):
amin = min(range(len(points)), key=points.__getitem__)
return amin


def argmax(points):
amax = max(range(len(points)), key=points.__getitem__)
return amax
2 changes: 1 addition & 1 deletion polytope_feature/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.14"
__version__ = "1.0.15"
8 changes: 8 additions & 0 deletions tests/test_slicing_xarray_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,11 @@ def test_intersection_point_disk_polygon(self):
result = self.API.retrieve(request)
paths = [r.flatten().values() for r in result.leaves]
assert ((pd.Timestamp("2000-01-01 00:00:00"),), (3,), (1,)) in paths

def test_duplicate_values_select(self):
request = Request(Select("step", [3, 3]), Select("level", [1]), Select("date", ["2000-01-01"]))
result = self.API.retrieve(request)
result.pprint()
assert len(result.leaves) == 1
path = result.leaves[0].flatten()["step"]
assert len(path) == 1

0 comments on commit a63a7ab

Please sign in to comment.