TNO Intern

Commit c888bd8c authored by Hen Brett's avatar Hen Brett 🐔
Browse files

fixing the tests so they also check the values of the GA4A scenarios and not only a happy flow

parent b884b2f5
Loading
Loading
Loading
Loading
Loading
+28 −15
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ from pythermogis import *

class UTCBuilder(TestCase):
    scenarios_file_path =  Path(__file__).parent.parent / "resources" / "test_input" / "scenarios"
    benchmark_path =  Path(__file__).parent.parent / "resources" / "test_benchmark_output" / "ga4a"

    def test_tg_scenario_xmls_parse_and_run(self):
        # These are the current 2.4 scenario settings, for BaseCase, HP, Stim and HP&Stim
@@ -16,13 +17,17 @@ class UTCBuilder(TestCase):
    def test_ga4a_scenario_xmls_parse_and_run(self):
        # The ga4a scenarios no longer work as they are missing necessary input parameters; they were generated by an older version of TG, I corrected them using the gui, producing a new set of configs.
        scenarios = ["ga4a_ORC_new_config.xml", "ga4a_directheat_new_config.xml", "ga4a_directheatHP_new_config.xml", "ga4a_chiller_new_config.xml"]
        utc_properties = [instantiate_utc_properties_from_xml(self.scenarios_file_path / scenario) for scenario in scenarios]

        # If test reaches here, then parsing of xml's worked, check that the scenarios actually run on a set of test data:
        [self.run_scenario(utc_property) for utc_property in utc_properties]

    def run_scenario(self, utc_properties):
        input_data = xr.Dataset({
        # If test reaches here, then parsing of xml's worked, check that the scenarios actually run on a set of test data:
        for scenario in scenarios:
            utc_properties = instantiate_utc_properties_from_xml(self.scenarios_file_path / scenario)
            benchmark_results = xr.load_dataset((self.benchmark_path / scenario).with_suffix(".nc"))
            self.run_scenario(utc_properties, benchmark_results)

    def run_scenario(self, utc_properties, benchmark_results: xr.Dataset = None):
        input_data = xr.Dataset(
            {
                "thickness_mean": ((), 300),
                "thickness_sd": ((), 50),
                "ntg": ((), 0.5),
@@ -30,6 +35,14 @@ class UTCBuilder(TestCase):
                "depth": ((), 5000),
                "ln_permeability_mean": ((), 5),
                "ln_permeability_sd": ((), 0.5),
        })
            }
        )

        results = calculate_doublet_performance_stochastic(
            input_data,
            utc_properties=utc_properties,
            rng_seed=0
        )

        calculate_doublet_performance_stochastic(input_data, utc_properties=utc_properties)
        if benchmark_results is not None:
            xr.testing.assert_equal(results, benchmark_results)
+17.8 KiB

File added.

No diff preview for this file type.

+17.8 KiB

File added.

No diff preview for this file type.

+17.8 KiB

File added.

No diff preview for this file type.

+17.8 KiB

File added.

No diff preview for this file type.