|
| 1 | +import pandas as pd |
| 2 | +import pytest |
| 3 | + |
| 4 | +from polytope_feature.engine.hullslicer import HullSlicer |
| 5 | +from polytope_feature.polytope import Polytope, Request |
| 6 | +from polytope_feature.shapes import Point, Select, Span, Union |
| 7 | + |
| 8 | + |
| 9 | +class TestSlicingFDBDatacube: |
| 10 | + def setup_method(self, method): |
| 11 | + # Create a dataarray with 3 labelled axes using different index types |
| 12 | + self.options = { |
| 13 | + "axis_config": [ |
| 14 | + {"axis_name": "number", "transformations": [{"name": "type_change", "type": "int"}]}, |
| 15 | + {"axis_name": "step", "transformations": [{"name": "type_change", "type": "int"}]}, |
| 16 | + { |
| 17 | + "axis_name": "date", |
| 18 | + "transformations": [{"name": "merge", "other_axis": "time", "linkers": ["T", "00"]}], |
| 19 | + }, |
| 20 | + { |
| 21 | + "axis_name": "values", |
| 22 | + "transformations": [ |
| 23 | + {"name": "mapper", "type": "octahedral", "resolution": 1280, "axes": ["latitude", "longitude"]} |
| 24 | + ], |
| 25 | + }, |
| 26 | + {"axis_name": "latitude", "transformations": [{"name": "reverse", "is_reverse": True}]}, |
| 27 | + {"axis_name": "longitude", "transformations": [{"name": "cyclic", "range": [0, 360]}]}, |
| 28 | + ], |
| 29 | + "pre_path": {"class": "od", "expver": "0001", "levtype": "sfc", "stream": "oper"}, |
| 30 | + "compressed_axes_config": [ |
| 31 | + "longitude", |
| 32 | + "latitude", |
| 33 | + "levtype", |
| 34 | + "step", |
| 35 | + "date", |
| 36 | + "domain", |
| 37 | + "expver", |
| 38 | + "param", |
| 39 | + "class", |
| 40 | + "stream", |
| 41 | + "type", |
| 42 | + ], |
| 43 | + } |
| 44 | + |
| 45 | + # Testing different shapes |
| 46 | + @pytest.mark.fdb |
| 47 | + def test_fdb_datacube(self): |
| 48 | + import pygribjump as gj |
| 49 | + |
| 50 | + request = Request( |
| 51 | + Select("step", [0]), |
| 52 | + Select("levtype", ["sfc"]), |
| 53 | + Span("date", pd.Timestamp("20230625T120000"), pd.Timestamp("20230626T120000")), |
| 54 | + Select("domain", ["g"]), |
| 55 | + Select("expver", ["0001"]), |
| 56 | + Select("param", ["167"]), |
| 57 | + Select("class", ["od"]), |
| 58 | + Select("stream", ["oper"]), |
| 59 | + Select("type", ["an"]), |
| 60 | + Union( |
| 61 | + ["latitude", "longitude"], |
| 62 | + Point(["latitude", "longitude"], [[20, 20]], method="nearest"), |
| 63 | + Point(["latitude", "longitude"], [[0, 0]], method="nearest"), |
| 64 | + Point(["latitude", "longitude"], [[0, 20]], method="nearest"), |
| 65 | + Point(["latitude", "longitude"], [[25, 30]], method="nearest"), |
| 66 | + Point(["latitude", "longitude"], [[-30, 90]], method="nearest"), |
| 67 | + Point(["latitude", "longitude"], [[-60, -30]], method="nearest"), |
| 68 | + Point(["latitude", "longitude"], [[-15, -45]], method="nearest"), |
| 69 | + Point(["latitude", "longitude"], [[20, 0]], method="nearest"), |
| 70 | + ), |
| 71 | + ) |
| 72 | + |
| 73 | + self.fdbdatacube = gj.GribJump() |
| 74 | + self.slicer = HullSlicer() |
| 75 | + self.API = Polytope( |
| 76 | + datacube=self.fdbdatacube, |
| 77 | + engine=self.slicer, |
| 78 | + options=self.options, |
| 79 | + ) |
| 80 | + result = self.API.retrieve(request) |
| 81 | + result.pprint() |
| 82 | + assert len(result.leaves) == 8 |
| 83 | + |
| 84 | + @pytest.mark.fdb |
| 85 | + def test_fdb_datacube_surrounding(self): |
| 86 | + import pygribjump as gj |
| 87 | + |
| 88 | + request = Request( |
| 89 | + Select("step", [0]), |
| 90 | + Select("levtype", ["sfc"]), |
| 91 | + Span("date", pd.Timestamp("20230625T120000"), pd.Timestamp("20230626T120000")), |
| 92 | + Select("domain", ["g"]), |
| 93 | + Select("expver", ["0001"]), |
| 94 | + Select("param", ["167"]), |
| 95 | + Select("class", ["od"]), |
| 96 | + Select("stream", ["oper"]), |
| 97 | + Select("type", ["an"]), |
| 98 | + Union( |
| 99 | + ["latitude", "longitude"], |
| 100 | + Point(["latitude", "longitude"], [[25, 30]], method="surrounding"), |
| 101 | + Point(["latitude", "longitude"], [[-15, -45]], method="surrounding"), |
| 102 | + ), |
| 103 | + ) |
| 104 | + |
| 105 | + self.fdbdatacube = gj.GribJump() |
| 106 | + self.slicer = HullSlicer() |
| 107 | + self.API = Polytope( |
| 108 | + datacube=self.fdbdatacube, |
| 109 | + engine=self.slicer, |
| 110 | + options=self.options, |
| 111 | + ) |
| 112 | + result = self.API.retrieve(request) |
| 113 | + result.pprint() |
| 114 | + assert len(result.leaves) == 4 |
| 115 | + tot_leaves = 0 |
| 116 | + for leaf in result.leaves: |
| 117 | + tot_leaves += len(leaf.result) |
| 118 | + assert tot_leaves == 9 |
| 119 | + |
| 120 | + # @pytest.mark.fdb |
| 121 | + # def test_fdb_datacube_mix_methods(self): |
| 122 | + # import pygribjump as gj |
| 123 | + |
| 124 | + # request = Request( |
| 125 | + # Select("step", [0]), |
| 126 | + # Select("levtype", ["sfc"]), |
| 127 | + # Span("date", pd.Timestamp("20230625T120000"), pd.Timestamp("20230626T120000")), |
| 128 | + # Select("domain", ["g"]), |
| 129 | + # Select("expver", ["0001"]), |
| 130 | + # Select("param", ["167"]), |
| 131 | + # Select("class", ["od"]), |
| 132 | + # Select("stream", ["oper"]), |
| 133 | + # Select("type", ["an"]), |
| 134 | + # Union(["latitude", "longitude"], |
| 135 | + # Point(["latitude", "longitude"], [[25, 30]], method="nearest"), |
| 136 | + # Point(["latitude", "longitude"], [[-15, -45]], method="surrounding")) |
| 137 | + # ) |
| 138 | + |
| 139 | + # self.fdbdatacube = gj.GribJump() |
| 140 | + # self.slicer = HullSlicer() |
| 141 | + # self.API = Polytope( |
| 142 | + # datacube=self.fdbdatacube, |
| 143 | + # engine=self.slicer, |
| 144 | + # options=self.options, |
| 145 | + # ) |
| 146 | + # result = self.API.retrieve(request) |
| 147 | + # result.pprint() |
| 148 | + # assert len(result.leaves) == 6 |
0 commit comments