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

add gj union test #153

Merged
merged 3 commits into from
Jul 8, 2024
Merged
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
79 changes: 79 additions & 0 deletions tests/test_union_gj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import pandas as pd
import pytest

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


class TestSlicingFDBDatacube:
def setup_method(self, method):
# Create a dataarray with 3 labelled axes using different index types
self.options = {
"axis_config": [
{"axis_name": "number", "transformations": [{"name": "type_change", "type": "int"}]},
{"axis_name": "step", "transformations": [{"name": "type_change", "type": "int"}]},
{
"axis_name": "date",
"transformations": [{"name": "merge", "other_axis": "time", "linkers": ["T", "00"]}],
},
{
"axis_name": "values",
"transformations": [
{"name": "mapper", "type": "octahedral", "resolution": 1280, "axes": ["latitude", "longitude"]}
],
},
{"axis_name": "latitude", "transformations": [{"name": "reverse", "is_reverse": True}]},
{"axis_name": "longitude", "transformations": [{"name": "cyclic", "range": [0, 360]}]},
],
"pre_path": {"class": "od", "expver": "0001", "levtype": "sfc", "stream": "oper"},
"compressed_axes_config": [
"longitude",
"latitude",
"levtype",
"step",
"date",
"domain",
"expver",
"param",
"class",
"stream",
"type",
],
}

# Testing different shapes
@pytest.mark.fdb
def test_fdb_datacube(self):
import pygribjump as gj

box1 = Box(["latitude", "longitude"], [0, 0], [0.2, 0.2])

box2 = Box(["latitude", "longitude"], [0.1, 0.1], [0.3, 0.3])

union = Union(["latitude", "longitude"], box1, box2)

request = Request(
Select("step", [0]),
Select("levtype", ["sfc"]),
Span("date", pd.Timestamp("20230625T120000"), pd.Timestamp("20230626T120000")),
Select("domain", ["g"]),
Select("expver", ["0001"]),
Select("param", ["167"]),
Select("class", ["od"]),
Select("stream", ["oper"]),
Select("type", ["an"]),
union,
)

self.fdbdatacube = gj.GribJump()
self.slicer = HullSlicer()
self.API = Polytope(
request=request,
datacube=self.fdbdatacube,
engine=self.slicer,
options=self.options,
)
result = self.API.retrieve(request)
result.pprint()
assert len(result.leaves) == 16
Loading