Skip to content

Commit 9d1af4d

Browse files
committed
added tests for leap year resource data
1 parent 8e067d6 commit 9d1af4d

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

h2integrate/resource/solar/test/test_resource_models.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,61 @@ def test_solar_resource_h2i_download(
197197
assert solar_data["start_time"] == f"{resource_year}/01/01 00:00:00 (+0000)"
198198
with subtests.test("Time step"):
199199
assert solar_data["dt"] == plant_simulation["simulation"]["dt"]
200+
201+
202+
203+
# fmt: off
204+
@pytest.mark.unit
205+
@pytest.mark.parametrize(
206+
"model,which,lat,lon,resource_year,model_name,timezone",
207+
[("OpenMeteoHistoricalSolarResource", "solar", -28.454864, 114.551749, 2024, "openmeteo_archive_solar", 8)], # noqa: E501
208+
ids=["OpenMeteoHistoricalSolarResource-Leap Year"]
209+
)
210+
# fmt: on
211+
def test_solar_resource_h2i_download_leap_year(
212+
plant_simulation,
213+
site_config,
214+
subtests,
215+
model,
216+
which,
217+
lat,
218+
lon,
219+
resource_year,
220+
model_name,
221+
):
222+
plant_config = {
223+
"site": site_config,
224+
"plant": plant_simulation,
225+
}
226+
227+
prob = om.Problem()
228+
comp = supported_models[model](
229+
plant_config=plant_config,
230+
resource_config=plant_config["site"]["resources"]["solar_resource"]["resource_parameters"],
231+
driver_config={},
232+
)
233+
prob.model.add_subsystem("resource", comp)
234+
prob.setup()
235+
prob.run_model()
236+
solar_data = prob.get_val("resource.solar_resource_data")
237+
name_expected = f"{lat}_{lon}_{resource_year}_{model_name}_60min_local_tz.csv"
238+
with subtests.test("filepath for data was found where expected"):
239+
assert Path(solar_data["filepath"]).exists()
240+
assert Path(solar_data["filepath"]).name == name_expected
241+
242+
with subtests.test("Data timezone"):
243+
assert pytest.approx(solar_data["data_tz"], rel=1e-6) == 8
244+
with subtests.test("Site Elevation"):
245+
assert pytest.approx(solar_data["elevation"], rel=1e-6) == 71
246+
247+
data_keys = [k for k, v in solar_data.items() if not isinstance(v, float | int | str)]
248+
for k in data_keys:
249+
with subtests.test(f"{k} resource data is 8760"):
250+
assert len(solar_data[k]) == 8760
251+
252+
with subtests.test("There are 16 timeseries data keys"):
253+
assert len(data_keys) == 16
254+
with subtests.test("Start time"):
255+
assert solar_data["start_time"] == f"{resource_year}/01/01 00:00:00 (+0800)"
256+
with subtests.test("Time step"):
257+
assert solar_data["dt"] == plant_simulation["simulation"]["dt"]

h2integrate/resource/wind/openmeteo_wind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def format_timeseries_data(self, data):
362362

363363
if "is_day" in c:
364364
data_rename_mapper.update({c: "is_day"})
365-
data_units.update({"is_day": "percent"})
365+
data_units.update({"is_day": "unitless"})
366366

367367
if "surface" in c:
368368
new_c += "_0m"

h2integrate/resource/wind/test/test_openmeteo_wind_api.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,63 @@ def test_wind_resource_h2i_download(
127127
assert wind_data["start_time"] == f"{resource_year}/01/01 00:00:00 (-0600)"
128128
with subtests.test("Time step"):
129129
assert wind_data["dt"] == plant_simulation["simulation"]["dt"]
130+
131+
132+
133+
# fmt: off
134+
@pytest.mark.unit
135+
@pytest.mark.parametrize(
136+
"model,which,lat,lon,resource_year,model_name,timezone,elevation",
137+
[("OpenMeteoHistoricalWindResource", "wind", -28.454864, 114.551749, 2024, "openmeteo_archive", 8, 71.0)], # noqa: E501
138+
ids=["Non-UTC Leap Year"],
139+
)
140+
# fmt: on
141+
def test_wind_resource_h2i_download_leap_year(
142+
plant_simulation,
143+
site_config,
144+
subtests,
145+
model,
146+
lat,
147+
lon,
148+
resource_year,
149+
model_name,
150+
timezone,
151+
elevation,
152+
):
153+
plant_config = {
154+
"site": site_config,
155+
"plant": plant_simulation,
156+
}
157+
158+
prob = om.Problem()
159+
comp = supported_models[model](
160+
plant_config=plant_config,
161+
resource_config=plant_config["site"]["resources"]["wind_resource"]["resource_parameters"],
162+
driver_config={},
163+
)
164+
prob.model.add_subsystem("resource", comp)
165+
prob.setup()
166+
prob.run_model()
167+
wind_data = prob.get_val("resource.wind_resource_data")
168+
169+
expected_fn = f"{lat}_{lon}_{resource_year}_{model_name}_60min_local_tz.csv"
170+
with subtests.test("filepath for data was found where expected"):
171+
assert Path(wind_data["filepath"]).exists()
172+
assert Path(wind_data["filepath"]).name == expected_fn
173+
174+
with subtests.test("Data timezone"):
175+
assert pytest.approx(wind_data["data_tz"], rel=1e-6) == timezone
176+
with subtests.test("Site Elevation"):
177+
assert pytest.approx(wind_data["elevation"], rel=1e-6) == elevation
178+
179+
data_keys = [k for k, v in wind_data.items() if not isinstance(v, float | int | str)]
180+
for k in data_keys:
181+
with subtests.test(f"{k} resource data is 8760"):
182+
assert len(wind_data[k]) == 8760
183+
184+
with subtests.test("theres 14 timeseries data keys"):
185+
assert len(data_keys) == 14
186+
with subtests.test("Start time"):
187+
assert wind_data["start_time"] == f"{resource_year}/01/01 00:00:00 (+0800)"
188+
with subtests.test("Time step"):
189+
assert wind_data["dt"] == plant_simulation["simulation"]["dt"]

0 commit comments

Comments
 (0)