From 3b4d116ba410517a4be15e64ecf973be633a2f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Tr=C3=B6ndle?= Date: Thu, 27 Jun 2024 16:34:25 +0200 Subject: [PATCH 1/3] Update folder structure of tests --- .../{ => timeseries/supply}/test_capacityfactors.py | 0 tests/scripts/{ => demand}/test_national_load.py | 11 ++++++----- .../test_template_transmission_entsoe_tyndp.py} | 0 3 files changed, 6 insertions(+), 5 deletions(-) rename tests/model/{ => timeseries/supply}/test_capacityfactors.py (100%) rename tests/scripts/{ => demand}/test_national_load.py (96%) rename tests/scripts/{test_link_entsoe_tyndp.py => transmission/test_template_transmission_entsoe_tyndp.py} (100%) diff --git a/tests/model/test_capacityfactors.py b/tests/model/timeseries/supply/test_capacityfactors.py similarity index 100% rename from tests/model/test_capacityfactors.py rename to tests/model/timeseries/supply/test_capacityfactors.py diff --git a/tests/scripts/test_national_load.py b/tests/scripts/demand/test_national_load.py similarity index 96% rename from tests/scripts/test_national_load.py rename to tests/scripts/demand/test_national_load.py index 20e8fa67..41b34375 100644 --- a/tests/scripts/test_national_load.py +++ b/tests/scripts/demand/test_national_load.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import numpy as np import pandas as pd @@ -14,7 +15,8 @@ filter_outliers, ) -THIS_DIR = os.path.dirname(__file__) +THIS_DIR = Path(os.path.dirname(__file__)) +PATH_TO_RESOURCES = THIS_DIR / ".." / ".." / "resources" class TestLoadHelperFunctions: @@ -197,14 +199,13 @@ def _load( "fill-29th-feb-from-28th": fill_29th_feb_from_28th, "data-source-priority-order": list(data_source_priority_order), } - path_to_raw_load = os.path.join( - THIS_DIR, "..", "resources", "national", "dummy_load.csv" - ) + path_to_raw_load = PATH_TO_RESOURCES / "national" / "dummy_load.csv" + countries = ["ALB", "DEU"] year = 2016 return clean_load_data( - path_to_raw_load, year, year, data_quality_config, countries + path_to_raw_load.as_posix(), year, year, data_quality_config, countries ) return _load diff --git a/tests/scripts/test_link_entsoe_tyndp.py b/tests/scripts/transmission/test_template_transmission_entsoe_tyndp.py similarity index 100% rename from tests/scripts/test_link_entsoe_tyndp.py rename to tests/scripts/transmission/test_template_transmission_entsoe_tyndp.py From 9936cf6b4cbd97f12da8e939727351282d6934e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Tr=C3=B6ndle?= Date: Wed, 3 Jul 2024 17:26:11 +0200 Subject: [PATCH 2/3] Update path handling in test file --- tests/scripts/demand/test_national_load.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/scripts/demand/test_national_load.py b/tests/scripts/demand/test_national_load.py index 41b34375..e0c61cb9 100644 --- a/tests/scripts/demand/test_national_load.py +++ b/tests/scripts/demand/test_national_load.py @@ -1,4 +1,3 @@ -import os from pathlib import Path import numpy as np @@ -15,8 +14,8 @@ filter_outliers, ) -THIS_DIR = Path(os.path.dirname(__file__)) -PATH_TO_RESOURCES = THIS_DIR / ".." / ".." / "resources" +THIS_DIR = Path(__file__).parent +PATH_TO_RESOURCES = THIS_DIR.parent.parent / "resources" class TestLoadHelperFunctions: From 482c9d163537914efff67f52813938620f67d8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Tr=C3=B6ndle?= Date: Wed, 3 Jul 2024 17:42:41 +0200 Subject: [PATCH 3/3] Update file structure for heat test files --- tests/model/timeseries/demand/test_heat.py | 8 ++++++++ .../{test_heat.py => timeseries/supply/test_cop.py} | 10 ---------- 2 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 tests/model/timeseries/demand/test_heat.py rename tests/model/{test_heat.py => timeseries/supply/test_cop.py} (52%) diff --git a/tests/model/timeseries/demand/test_heat.py b/tests/model/timeseries/demand/test_heat.py new file mode 100644 index 00000000..fb68015c --- /dev/null +++ b/tests/model/timeseries/demand/test_heat.py @@ -0,0 +1,8 @@ +def test_unscaled_heat(unscaled_space_heat_timeseries): + """Expecting more space heating demand in winter than summer.""" + # xarray to pandas as we need a newer xarray version (with flox) for `groupby` performance. + df = unscaled_space_heat_timeseries.space_heat.to_series() + hourly_space_monthly = df.groupby(df.index.get_level_values("time").month).sum() + hourly_space_winter = hourly_space_monthly.loc[[12, 1, 2]].sum() + hourly_space_summer = hourly_space_monthly.loc[[6, 7, 8]].sum() + assert (hourly_space_winter > hourly_space_summer).all() diff --git a/tests/model/test_heat.py b/tests/model/timeseries/supply/test_cop.py similarity index 52% rename from tests/model/test_heat.py rename to tests/model/timeseries/supply/test_cop.py index 955eee85..4a4b1708 100644 --- a/tests/model/test_heat.py +++ b/tests/model/timeseries/supply/test_cop.py @@ -13,13 +13,3 @@ def test_cop_all_at_least_1(cop_timeseries): assert ( cop_timeseries.stack() >= 1 ).all(), "Found improbably low heat pump COP values (< 1)." - - -def test_unscaled_heat(unscaled_space_heat_timeseries): - """Expecting more space heating demand in winter than summer.""" - # xarray to pandas as we need a newer xarray version (with flox) for `groupby` performance. - df = unscaled_space_heat_timeseries.space_heat.to_series() - hourly_space_monthly = df.groupby(df.index.get_level_values("time").month).sum() - hourly_space_winter = hourly_space_monthly.loc[[12, 1, 2]].sum() - hourly_space_summer = hourly_space_monthly.loc[[6, 7, 8]].sum() - assert (hourly_space_winter > hourly_space_summer).all()