-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_fdb_datacube.py
127 lines (116 loc) · 4.57 KB
/
test_fdb_datacube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
# import geopandas as gpd
# import matplotlib.pyplot as plt
class TestSlicingFDBDatacube:
def setup_method(self, method):
# Create a dataarray with 3 labelled axes using different index types
self.options = {
"axis_config": [
{"axis_name": "step", "transformations": [{"name": "type_change", "type": "int"}]},
{"axis_name": "number", "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]}]},
],
"compressed_axes_config": [
"longitude",
"latitude",
"levtype",
"step",
"date",
"domain",
"expver",
"param",
"class",
"stream",
"type",
],
"pre_path": {"class": "od", "expver": "0001", "levtype": "sfc", "stream": "oper"},
}
# Testing different shapes
@pytest.mark.fdb
def test_fdb_datacube(self):
import pygribjump as gj
request = Request(
Select("step", [0]),
Select("levtype", ["sfc"]),
Select("date", [pd.Timestamp("20230625T120000")]),
Select("domain", ["g"]),
Select("expver", ["0001"]),
Select("param", ["167"]),
Select("class", ["od"]),
Select("stream", ["oper"]),
Select("type", ["an"]),
Box(["latitude", "longitude"], [0, 0], [0.2, 0.2]),
)
self.fdbdatacube = gj.GribJump()
self.slicer = HullSlicer()
self.API = Polytope(
datacube=self.fdbdatacube,
engine=self.slicer,
options=self.options,
)
result = self.API.retrieve(request)
result.pprint()
assert len(result.leaves) == 3
assert len(result.leaves[0].result) == 3
assert result.leaves[0].flatten()["longitude"][1] == 0.070093457944
assert result.leaves[1].flatten()["longitude"][1] == 0.070148090413
assert result.leaves[2].flatten()["longitude"][1] == 0.070202808112
assert result.leaves[0].result[0] == 297.9250183105469
# lats = []
# lons = []
# tol = 1e-8
# for i in range(len(result.leaves)):
# cubepath = result.leaves[i].flatten()
# lat = cubepath["latitude"]
# lon = cubepath["longitude"]
# lats.append(lat)
# lons.append(lon)
# worldmap = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
# fig, ax = plt.subplots(figsize=(12, 6))
# worldmap.plot(color="darkgrey", ax=ax)
# plt.scatter(lons, lats, s=16, c="red", cmap="YlOrRd")
# plt.colorbar(label="Temperature")
# plt.show()
@pytest.mark.fdb
def test_fdb_datacube_select_grid(self):
import pygribjump as gj
request = Request(
Select("step", [0]),
Select("levtype", ["sfc"]),
Select("date", [pd.Timestamp("20230625T120000")]),
Select("domain", ["g"]),
Select("expver", ["0001"]),
Select("param", ["167"]),
Select("class", ["od"]),
Select("stream", ["oper"]),
Select("type", ["an"]),
Select("latitude", [0.035149384216]),
Span("longitude", 0, 0.070093457944),
)
self.fdbdatacube = gj.GribJump()
self.slicer = HullSlicer()
self.API = Polytope(
datacube=self.fdbdatacube,
engine=self.slicer,
options=self.options,
)
result = self.API.retrieve(request)
result.pprint()
assert len(result.leaves) == 1
assert len(result.leaves[0].result) == 2
assert result.leaves[0].flatten()["longitude"] == (0.0, 0.070093457944)