Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update v #282

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions polytope_feature/engine/hullslicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def _build_sliceable_child(self, polytope, ax, node, datacube, values, next_node
fvalue = ax.to_float(value)
new_polytope = slice(polytope, ax.name, fvalue, slice_axis_idx)
remapped_val = self.remap_values(ax, value)
# is_last_axis = ax==list(datacube.axes.values())[-1]
# print(ax==list(datacube.axes.values())[-1])
(child, next_nodes) = node.create_child(ax, remapped_val, next_nodes)
child["unsliced_polytopes"] = copy(node["unsliced_polytopes"])
child["unsliced_polytopes"].remove(polytope)
Expand Down Expand Up @@ -203,14 +205,15 @@ def remove_compressed_axis_in_union(self, polytopes):
if p.is_in_union:
for axis in p.axes():
if axis == self.compressed_axes[-1]:
self.compressed_axes.remove(axis)
# self.compressed_axes.remove(axis)
pass

def extract(self, datacube: Datacube, polytopes: List[ConvexPolytope]):
# Determine list of axes to compress
self.find_compressed_axes(datacube, polytopes)

# remove compressed axes which are in a union
self.remove_compressed_axis_in_union(polytopes)
# self.remove_compressed_axis_in_union(polytopes)

# Convert the polytope points to float type to support triangulation and interpolation
for p in polytopes:
Expand All @@ -224,7 +227,6 @@ def extract(self, datacube: Datacube, polytopes: List[ConvexPolytope]):
# NOTE: could optimise here if we know combinations will always be for one request.
# Then we do not need to create a new index tree and merge it to request, but can just
# directly work on request and return it...

for c in combinations:
r = TensorIndexTree()
new_c = []
Expand Down
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.15"
__version__ = "1.0.16"
6 changes: 3 additions & 3 deletions tests/test_engine_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_triangle(self):
triangle = Polygon(["x", "y"], [[3, 3], [3, 6], [6, 3]]).polytope()
result = self.slicer.extract(datacube, triangle)
result.pprint()
assert len(result.leaves) == 10
assert len(result.leaves) == 4
# assert len(result.leaves) == 4
# total_leaves = 0
# for leaf in result.leaves:
Expand All @@ -57,8 +57,8 @@ def test_reusable(self):
polytopes = Polygon(["x", "y"], [[3, 3], [3, 6], [6, 3]]).polytope()
result = self.slicer.extract(datacube, polytopes)
result.pprint()
# assert len(result.leaves) == 4
assert len(result.leaves) == 10
assert len(result.leaves) == 4
# assert len(result.leaves) == 10
polytopes = Box(["x", "y"], lower_corner=[3, 3], upper_corner=[6, 6]).polytope()
result = self.slicer.extract(datacube, polytopes)
result.pprint()
Expand Down
7 changes: 5 additions & 2 deletions tests/test_slicing_xarray_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
import pandas as pd
import pytest
import xarray as xr

from polytope_feature.datacube.backends.xarray import XArrayDatacube
Expand Down Expand Up @@ -103,14 +104,15 @@ def test_disk(self):
assert np.size(result.leaves[1].result[1]) == 7
assert np.size(result.leaves[2].result[1]) == 1

@pytest.mark.xfail
def test_concave_polygon(self):
# TODO: fix the overlapping branches?
points = [[1, 0], [3, 0], [2, 3], [3, 6], [1, 6]]
request = Request(Polygon(["level", "step"], points), Select("date", ["2000-01-01"]))
result = self.API.retrieve(request)
self.xarraydatacube.get(result)
# result.pprint()
assert len(result.leaves) == 8
result.pprint()
assert len(result.leaves) == 4

def test_polytope(self):
points = [[0, 1], [3, 1], [3, 2], [0, 2]]
Expand Down Expand Up @@ -226,6 +228,7 @@ def test_box(self):
result = self.API.retrieve(request)
assert len(result.leaves) == 1

@pytest.mark.xfail
def test_swept_concave_polygon(self):
# Tests what happens when we slice a concave shape which is swept across a path and see if concavity is lost
points = [(1, 0), (3, 0), (3, 6), (2, 6), (2, 3), (1, 3)]
Expand Down
6 changes: 4 additions & 2 deletions tests/test_slicing_xarray_4D.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ def test_circles_intersecting_float(self):
disk2 = Disk(["step", "lat"], [15, 2.0], [4.99, 0.3])
request = Request(Union(["step", "lat"], disk1, disk2), Select("date", ["2000-01-01"]), Select("level", [10]))
result = self.API.retrieve(request)
assert len(result.leaves) == 24
result.pprint()
assert len(result.leaves) == 8

def test_circles_touching_float(self):
disk1 = Disk(["step", "lat"], [6, 4.0], [3, 1.9])
disk2 = Disk(["step", "lat"], [15, 2.0], [3, 2.1])
request = Request(Union(["step", "lat"], disk1, disk2), Select("date", ["2000-01-01"]), Select("level", [10]))
result = self.API.retrieve(request)
assert len(result.leaves) == 101
result.pprint()
assert len(result.leaves) == 6

def test_pathsegment_swept_2D_box(self):
box1 = Box(["step", "level"], [3, 0], [6, 1])
Expand Down
Loading
Loading