Skip to content

Commit

Permalink
fix merging of multiple params
Browse files Browse the repository at this point in the history
  • Loading branch information
mathleur authored and jameshawkes committed Jan 22, 2024
1 parent e5dfb8e commit de9cae8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
14 changes: 9 additions & 5 deletions polytope/datacube/index_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ def __eq__(self, other):
else:
if other.value == self.value:
return True
if other.value - 2 * other.axis.tol <= self.value <= other.value + 2 * other.axis.tol:
return True
elif self.value - 2 * self.axis.tol <= other.value <= self.value + 2 * self.axis.tol:
return True
else:
return False
if isinstance(self.value, str):
return False
else:
if other.value - 2 * other.axis.tol <= self.value <= other.value + 2 * other.axis.tol:
return True
elif self.value - 2 * self.axis.tol <= other.value <= self.value + 2 * self.axis.tol:
return True
else:
return False
# return (self.axis.name, self.value) == (other.axis.name, other.value)

def __lt__(self, other):
Expand Down
41 changes: 41 additions & 0 deletions tests/test_multiple_param_fdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pandas as pd
import pytest

from polytope.engine.hullslicer import HullSlicer
from polytope.polytope import Polytope, Request
from polytope.shapes import Box, Select


class TestSlicingFDBDatacube:
def setup_method(self, method):
from polytope.datacube.backends.fdb import FDBDatacube

# Create a dataarray with 3 labelled axes using different index types
self.options = {
"values": {"mapper": {"type": "octahedral", "resolution": 1280, "axes": ["latitude", "longitude"]}},
"date": {"merge": {"with": "time", "linkers": ["T", "00"]}},
"step": {"type_change": "int"},
}
self.config = {"class": "od", "expver": "0001", "levtype": "sfc", "stream": "oper", "type": "fc"}
self.fdbdatacube = FDBDatacube(self.config, axis_options=self.options)
self.slicer = HullSlicer()
self.API = Polytope(datacube=self.fdbdatacube, engine=self.slicer, axis_options=self.options)

# Testing different shapes
@pytest.mark.fdb
def test_fdb_datacube(self):
request = Request(
Select("step", [0]),
Select("levtype", ["sfc"]),
Select("date", [pd.Timestamp("20240118T000000")]),
Select("domain", ["g"]),
Select("expver", ["0001"]),
Select("param", ["49", "167"]),
Select("class", ["od"]),
Select("stream", ["oper"]),
Select("type", ["fc"]),
Box(["latitude", "longitude"], [0, 0], [0.2, 0.2]),
)
result = self.API.retrieve(request)
result.pprint()
assert len(result.leaves) == 18

0 comments on commit de9cae8

Please sign in to comment.