TNO Intern

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

Allowing the complex logic of the heat pump calculation to occur

parent 3d4be995
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -6,9 +6,8 @@ import xarray as xr

def calculate_doublet_performance(input_data: xr.Dataset,
                                  input_params: dict = None,
                                  rng_seed: int = None,
                                  p_values: List[float] = None) -> xr.Dataset:
    """
    An access point to the calculate_doublet_performance_across_dimensions function in pythermogis.thermogis_classes.doublet, see that method for more detailed instruction
    """
    return calculate_doublet_performance_across_dimensions(input_data, input_params=input_params, rng_seed=rng_seed, p_values=p_values)
    return calculate_doublet_performance_across_dimensions(input_data, input_params=input_params, p_values=p_values)
+34 −22
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ def calculate_performance_of_single_location(mask: float, depth: float, thicknes

def calculate_doublet_performance_across_dimensions(input_data: xr.Dataset,
                                                    input_params: dict = None,
                                  rng_seed: int =None,
                                                    p_values: List[float] = None) -> xr.Dataset:
    """
    Perform a ThermoGIS Doublet performance assessment. This will occur across all dimensions of the input_data (ie. input data can have a single value for each required variable, or it can be 1Dimensional or a 2Dimensional grid)
@@ -131,9 +130,13 @@ def calculate_doublet_performance_across_dimensions(input_data: xr.Dataset,
                             "stimKhMax": 20,
                             "use_stimulation": False,
                             "use_heat_pump": False,
                             "calculate_cop": True,
                             "hp_application_mode": False,
                             "hp_direct_heat_input_temp": 70.0,
                             "utc_cutoff_shallow": 5.1,
                             "utc_cutoff_deep": 6.5,
                    "utc_cutoff_depth": 4000.0}
                             "utc_cutoff_depth": 4000.0,
                             "rng_seed": np.random.randint(low=0, high=10000)}

    if input_params is None:  # If no input_params provided, use the basecase
        input_params = input_params_basecase
@@ -148,8 +151,14 @@ def calculate_doublet_performance_across_dimensions(input_data: xr.Dataset,
    if "mask" not in input_data:
        input_data["mask"] = np.nan

    # if (props.useHeatPump() & & props.calculateCop() & & !props.hpApplicationMode() ) {
    #     doublet.doubletCalc1DData.setInjectionTemp(doublet.calculateInjectionTempWithHeatPump(temperature, props.hpDirectHeatInputTemp()));
    # }

    # Instantiate ThermoGIS doublet
    doublet = instantiate_thermogis_doublet(rng_seed=rng_seed)
    doublet = instantiate_thermogis_doublet(input_params)

    # set injectionTemp differently for heat_pump

    # Setup output_data dataset
    output_data = input_data.thickness_mean.copy().to_dataset(name="thickness")
@@ -239,7 +248,7 @@ def calculate_doublet_performance_across_dimensions(input_data: xr.Dataset,
    return output_data


def instantiate_thermogis_doublet(rng_seed=None):
def instantiate_thermogis_doublet(input_params):
    """
    Instantiate a ThermoGIS Doublet class, with a set random seed if provided
    :param rng_seed:
@@ -257,13 +266,16 @@ def instantiate_thermogis_doublet(rng_seed=None):

    # Instantiate the UTC properties class
    propsBuilder = UTCPropertiesBuilder()
    utc_properties = propsBuilder.build()
    utc_properties = (propsBuilder
                      .setUseStimulation(input_params["use_stimulation"])
                      .setUseHeatPump(input_params["use_heat_pump"])
                      .setCalculateCop(input_params["calculate_cop"])
                      .setHpApplicationMode(input_params["hp_application_mode"])
                      .setHpDirectHeatInputTemp(input_params["hp_direct_heat_input_temp"])
                      .build())

    # Instantiate random number generator:
    if rng_seed is None:
        rng = RNG()
    else:
        rng = RNG(rng_seed)
    rng = RNG(input_params["rng_seed"])

    # Create an instance of a ThermoGISDoublet
    doublet = ThermoGISDoublet(Mockito.mock(Logger), rng, utc_properties)
+16 −4
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import xarray as xr
from jpype.types import *
from pygridsio.pygridsio import read_grid

from pythermogis.thermogis_classes.doublet import calculate_doublet_performance
from pythermogis.pythermogis import calculate_doublet_performance
from pythermogis.thermogis_classes.java_start import start_jvm


@@ -80,7 +80,7 @@ class PyThermoGIS(TestCase):
        input_grids = self.read_input_grids()

        # Run calculation across all dimensions of input_grids, and all provided P_values
        output_grids = calculate_doublet_performance(input_grids, rng_seed=123, p_values=[10, 20, 30, 40, 50, 60, 70, 80, 90])
        output_grids = calculate_doublet_performance(input_grids, input_params={"rng_seed": 123}, p_values=[10, 20, 30, 40, 50, 60, 70, 80, 90])

        # Assert values are the same as the benchmark grids generated by the Java code
        for p_value in [10, 50, 90]:
@@ -88,6 +88,19 @@ class PyThermoGIS(TestCase):
            output_grids_p_value = output_grids_p_value.drop_vars("p_value")
            self.assert_output_and_benchmark_is_close(self.test_benchmark_output_basecase, output_grids_p_value, p_value, "")

    def test_doublet_grid_HP(self):
        # Act
        # Read Input grids
        input_grids = self.read_input_grids()

        # Run calculation across all dimensions of input_grids, and all provided P_values
        output_grids = calculate_doublet_performance(input_grids, input_params={"rng_seed": 123, "use_heat_pump": True}, p_values=[10, 20, 30, 40, 50, 60, 70, 80, 90])

        # Assert values are the same as the benchmark grids generated by the Java code
        for p_value in [50]:
            output_grids_p_value = output_grids.sel(p_value=p_value)
            output_grids_p_value = output_grids_p_value.drop_vars("p_value")
            self.assert_output_and_benchmark_is_close(self.test_benchmark_output_HP, output_grids_p_value, p_value, "_HP")

    def test_doublet_grid_STIM(self):
        # Act
@@ -95,7 +108,7 @@ class PyThermoGIS(TestCase):
        input_grids = self.read_input_grids()

        # Run calculation across all dimensions of input_grids, and all provided P_values
        output_grids = calculate_doublet_performance(input_grids, rng_seed=123, p_values=[10, 20, 30, 40, 50, 60, 70, 80, 90], input_params={"use_stimulation": True})
        output_grids = calculate_doublet_performance(input_grids, input_params={"rng_seed": 123, "use_stimulation": True}, p_values=[10, 20, 30, 40, 50, 60, 70, 80, 90])

        # Assert values are the same as the benchmark grids generated by the Java code
        for p_value in [50]:
@@ -156,4 +169,3 @@ class PyThermoGIS(TestCase):
        # Act & Assert
        with self.assertRaises(ValueError):
            calculate_doublet_performance(input_data)