TNO Intern

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

Figuring out the input limtis of the simulation

parent 1f9e131c
Loading
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -6,8 +6,12 @@ import xarray as xr

from pythermogis import simulate_doublet
from pythermogis.dask_utils.auto_chunk import auto_chunk_dataset
from pythermogis.physics.temperature_grid_calculation import calculate_temperature_from_gradient
from pythermogis.thermogis_classes.utc_properties import instantiate_utc_properties_builder
from pythermogis.physics.temperature_grid_calculation import (
    calculate_temperature_from_gradient,
)
from pythermogis.thermogis_classes.utc_properties import (
    instantiate_utc_properties_builder,
)


def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properties = None, rng_seed: int = None, chunk_size: int = None, print_execution_duration: bool = False, mask_value: float = np.nan) -> xr.Dataset:
+9 −14
Original line number Diff line number Diff line
@@ -119,13 +119,13 @@ def calculate_performance_of_single_location(mask: float, depth: float, thicknes
        )

    # The Java routine which calculates DoubletPerformance, for more detail on the simulation inspect the Java source code
    try:
        results = doublet.calculateDoubletPerformance(input)

    # If calculation was not successful, return mask value
    if results is None:
    except:
        return (mask_value,) * 14

    if results.utc() == -9999.0:
    # If calculation was not successful, return mask value
    if results is None or results.utc() == -9999.0:
        return (mask_value,) * 14

    # calculate net-present-value using the utc-cutoffs
@@ -167,15 +167,10 @@ def validate_input(depth: float,
    transmissivity: float,
    transmissivity_with_ntg: float,
) -> bool:
    if np.any(np.isnan([depth,
                        ntg,
                        porosity,
                        temperature,
                        thickness,
                        transmissivity,
                        transmissivity_with_ntg])):
        return False
    return True
    """
    Check that none of the input is nan
    """
    return not np.any(np.isnan([depth, ntg, porosity, temperature, thickness, transmissivity, transmissivity_with_ntg]))

def instantiate_thermogis_doublet(utc_properties, rng_seed: int = None) -> JClass:
    """
+48 −0
Original line number Diff line number Diff line
from pathlib import Path

import numpy as np
import xarray as xr

from pythermogis import calculate_doublet_performance

test_files_path = Path(__file__).parent / "resources"

def print_min_max(variable: xr.DataArray):
    print(f"{variable.name}, {np.min(variable):.2f}, {np.max(variable):.2f}")

def test_define_calculation_limits():
    recalculate_results = True
    if recalculate_results:
        # generate simulation samples across desired reservoir properties
        Nsamples = 1000
        thickness_samples = np.random.uniform(low=1, high=10e3, size=Nsamples)
        porosity_samples = np.random.uniform(low=0.01, high=0.99, size=Nsamples)
        ntg_samples = np.random.uniform(low=0.01, high=0.99, size=Nsamples)
        depth_samples = np.random.uniform(low=1, high=10e3, size=Nsamples)
        permeability_samples = np.random.uniform(low=1, high=10e3, size=Nsamples)
        reservoir_properties = xr.Dataset(
            {
                "thickness": (["sample"], thickness_samples),
                "porosity": (["sample"], porosity_samples),
                "ntg": (["sample"], ntg_samples),
                "depth": (["sample"], depth_samples),
                "permeability": (["sample"], permeability_samples),
            },
            coords={"sample": np.arange(Nsamples)},
        )

        results = calculate_doublet_performance(
            reservoir_properties,
            chunk_size=100,
            print_execution_duration=True
        )
        results.to_netcdf(test_files_path / "calculation_limits_result.nc")
    else:
        results = xr.load_dataset(test_files_path / "calculation_limits_result.nc")

    # drop the values which returned nan:
    results = results.dropna(dim="sample", subset=["power"])

    # print the min and max values of all the inputs
    for var in results:
        print_min_max(results[var])
 No newline at end of file