forked from NatLabRockies/H2Integrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_openmeteo_wind_api.py
More file actions
189 lines (165 loc) · 6.21 KB
/
test_openmeteo_wind_api.py
File metadata and controls
189 lines (165 loc) · 6.21 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from decimal import ROUND_HALF_UP, Decimal
from pathlib import Path
import pytest
import openmdao.api as om
from h2integrate.core.supported_models import supported_models
@pytest.mark.unit
@pytest.mark.parametrize(
"model,which,lat,lon,resource_year,model_name,timezone,elevation",
[("OpenMeteoHistoricalWindResource", "wind", 44.04218, -95.19757, 2023, "open-meteo", 0, 438)],
ids=["Primary Example"],
)
def test_wind_resource_web_download(
plant_simulation,
site_config,
subtests,
model,
lat,
lon,
resource_year,
model_name,
timezone,
elevation,
):
fn = (
f"{model_name}-"
f"{Decimal(abs(lat)).quantize(Decimal('0.01'), ROUND_HALF_UP)}{'N' if lat > 0 else 'S'}"
f"{Decimal(abs(lon)).quantize(Decimal('0.01'), ROUND_HALF_UP)}{'E' if lon > 0 else 'W'}"
f"{elevation}m.csv"
)
site_config["resources"]["wind_resource"]["resource_parameters"]["resource_filename"] = fn
plant_config = {
"site": site_config,
"plant": plant_simulation,
}
prob = om.Problem()
comp = supported_models[model](
plant_config=plant_config,
resource_config=plant_config["site"]["resources"]["wind_resource"]["resource_parameters"],
driver_config={},
)
prob.model.add_subsystem("resource", comp)
prob.setup()
prob.run_model()
wind_data = prob.get_val("resource.wind_resource_data")
with subtests.test("filepath for data was found where expected"):
assert Path(wind_data["filepath"]).exists()
assert Path(wind_data["filepath"]).name == fn
with subtests.test("Data timezone"):
assert pytest.approx(wind_data["data_tz"], rel=1e-6) == timezone
with subtests.test("Site Elevation"):
assert pytest.approx(wind_data["elevation"], rel=1e-6) == elevation
data_keys = [k for k, v in wind_data.items() if not isinstance(v, float | int | str)]
for k in data_keys:
with subtests.test(f"{k} resource data is 8760"):
assert len(wind_data[k]) == 8760
with subtests.test("theres 12 timeseries data keys"):
assert len(data_keys) == 12
with subtests.test("Start time"):
assert wind_data["start_time"] == f"{resource_year}/01/01 00:00:00 (+0000)"
with subtests.test("Time step"):
assert wind_data["dt"] == plant_simulation["simulation"]["dt"]
# fmt: off
@pytest.mark.unit
@pytest.mark.parametrize(
"model,which,lat,lon,resource_year,model_name,timezone,elevation",
[("OpenMeteoHistoricalWindResource", "wind", 44.04218, -95.19757, 2023, "openmeteo_archive", -6, 449)], # noqa: E501
ids=["Non-UTC"],
)
# fmt: on
def test_wind_resource_h2i_download(
plant_simulation,
site_config,
subtests,
model,
lat,
lon,
resource_year,
model_name,
timezone,
elevation,
):
plant_config = {
"site": site_config,
"plant": plant_simulation,
}
prob = om.Problem()
comp = supported_models[model](
plant_config=plant_config,
resource_config=plant_config["site"]["resources"]["wind_resource"]["resource_parameters"],
driver_config={},
)
prob.model.add_subsystem("resource", comp)
prob.setup()
prob.run_model()
wind_data = prob.get_val("resource.wind_resource_data")
expected_fn = f"{lat}_{lon}_{resource_year}_{model_name}_60min_local_tz.csv"
with subtests.test("filepath for data was found where expected"):
assert Path(wind_data["filepath"]).exists()
assert Path(wind_data["filepath"]).name == expected_fn
with subtests.test("Data timezone"):
assert pytest.approx(wind_data["data_tz"], rel=1e-6) == timezone
with subtests.test("Site Elevation"):
assert pytest.approx(wind_data["elevation"], rel=1e-6) == elevation
data_keys = [k for k, v in wind_data.items() if not isinstance(v, float | int | str)]
for k in data_keys:
with subtests.test(f"{k} resource data is 8760"):
assert len(wind_data[k]) == 8760
with subtests.test("theres 13 timeseries data keys"):
assert len(data_keys) == 13
with subtests.test("Start time"):
assert wind_data["start_time"] == f"{resource_year}/01/01 00:00:00 (-0600)"
with subtests.test("Time step"):
assert wind_data["dt"] == plant_simulation["simulation"]["dt"]
# fmt: off
@pytest.mark.unit
@pytest.mark.parametrize(
"model,which,lat,lon,resource_year,model_name,timezone,elevation",
[("OpenMeteoHistoricalWindResource", "wind", -28.454864, 114.551749, 2024, "openmeteo_archive", 8, 71.0)], # noqa: E501
ids=["Non-UTC Leap Year"],
)
# fmt: on
def test_wind_resource_h2i_download_leap_year(
plant_simulation,
site_config,
subtests,
model,
lat,
lon,
resource_year,
model_name,
timezone,
elevation,
):
plant_config = {
"site": site_config,
"plant": plant_simulation,
}
prob = om.Problem()
comp = supported_models[model](
plant_config=plant_config,
resource_config=plant_config["site"]["resources"]["wind_resource"]["resource_parameters"],
driver_config={},
)
prob.model.add_subsystem("resource", comp)
prob.setup()
prob.run_model()
wind_data = prob.get_val("resource.wind_resource_data")
expected_fn = f"{lat}_{lon}_{resource_year}_{model_name}_60min_local_tz.csv"
with subtests.test("filepath for data was found where expected"):
assert Path(wind_data["filepath"]).exists()
assert Path(wind_data["filepath"]).name == expected_fn
with subtests.test("Data timezone"):
assert pytest.approx(wind_data["data_tz"], rel=1e-6) == timezone
with subtests.test("Site Elevation"):
assert pytest.approx(wind_data["elevation"], rel=1e-6) == elevation
data_keys = [k for k, v in wind_data.items() if not isinstance(v, float | int | str)]
for k in data_keys:
with subtests.test(f"{k} resource data is 8760"):
assert len(wind_data[k]) == 8760
with subtests.test("theres 14 timeseries data keys"):
assert len(data_keys) == 14
with subtests.test("Start time"):
assert wind_data["start_time"] == f"{resource_year}/01/01 00:00:00 (+0800)"
with subtests.test("Time step"):
assert wind_data["dt"] == plant_simulation["simulation"]["dt"]