|
| 1 | +import pandas as pd |
| 2 | +import pytest |
| 3 | + |
| 4 | +from polytope_feature.polytope import Polytope, Request |
| 5 | +from polytope_feature.shapes import Box, Select |
| 6 | + |
| 7 | + |
| 8 | +class TestSlicingFDBDatacube: |
| 9 | + def setup_method(self, method): |
| 10 | + # Create a dataarray with 3 labelled axes using different index types |
| 11 | + self.options = { |
| 12 | + "axis_config": [ |
| 13 | + {"axis_name": "step", "transformations": [{"name": "type_change", "type": "int"}]}, |
| 14 | + {"axis_name": "date", "transformations": [{"name": "type_change", "type": "date"}]}, |
| 15 | + {"axis_name": "time", "transformations": [{"name": "type_change", "type": "time"}]}, |
| 16 | + { |
| 17 | + "axis_name": "values", |
| 18 | + "transformations": [ |
| 19 | + {"name": "mapper", "type": "octahedral", "resolution": 1280, "axes": ["latitude", "longitude"]} |
| 20 | + ], |
| 21 | + }, |
| 22 | + {"axis_name": "latitude", "transformations": [{"name": "reverse", "is_reverse": True}]}, |
| 23 | + {"axis_name": "longitude", "transformations": [{"name": "cyclic", "range": [0, 360]}]}, |
| 24 | + ], |
| 25 | + "pre_path": {"class": "od", "expver": "0001", "levtype": "sfc", "stream": "oper", "type": "fc"}, |
| 26 | + "compressed_axes_config": [ |
| 27 | + "longitude", |
| 28 | + "latitude", |
| 29 | + "levtype", |
| 30 | + "step", |
| 31 | + "date", |
| 32 | + "domain", |
| 33 | + "expver", |
| 34 | + "param", |
| 35 | + "class", |
| 36 | + "stream", |
| 37 | + "type", |
| 38 | + ], |
| 39 | + } |
| 40 | + |
| 41 | + # Testing different shapes |
| 42 | + @pytest.mark.fdb |
| 43 | + def test_fdb_datacube(self): |
| 44 | + import pygribjump as gj |
| 45 | + |
| 46 | + request = Request( |
| 47 | + Select("step", [0]), |
| 48 | + Select("levtype", ["sfc"]), |
| 49 | + Select("date", [pd.Timestamp("20240118")]), |
| 50 | + Select("time", [pd.Timedelta("00:00:00")]), |
| 51 | + Select("domain", ["g"]), |
| 52 | + Select("expver", ["0001"]), |
| 53 | + Select("param", ["167"]), |
| 54 | + Select("class", ["od"]), |
| 55 | + Select("stream", ["oper"]), |
| 56 | + Select("type", ["fc"]), |
| 57 | + Box(["latitude", "longitude"], [0, 0], [0.2, 0.2]), |
| 58 | + ) |
| 59 | + self.fdbdatacube = gj.GribJump() |
| 60 | + self.API = Polytope( |
| 61 | + datacube=self.fdbdatacube, |
| 62 | + options=self.options, |
| 63 | + ) |
| 64 | + result = self.API.retrieve(request) |
| 65 | + result.pprint() |
| 66 | + assert len(result.leaves) == 3 |
| 67 | + assert len(result.leaves[0].result) == 3 |
0 commit comments