TNO Intern

Commit 36a4c5a9 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

allowing the user to set the mask value

parent 57c5d147
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
- repo: https://github.com/astral-sh/ruff-pre-commit
  rev: v0.4.4  # Use latest
  hooks:
    - id: ruff
    - id: ruff-format
 No newline at end of file
+20 −0
Original line number Diff line number Diff line
@@ -63,3 +63,23 @@ mkdocs = ">=1.6.1,<2"
mkdocstrings-python = ">=1.16.12,<2"
dask = ">=2025.5.1,<2026"
narwhals = ">=1.43.1,<2"

[tool.ruff]
line-length = 88
target-version = "py313"

[tool.ruff.lint]
select = [
    # pycodestyle (style guide violations)
    "E",
    # Pyflakes (bug detection)
    "F",
    # pyupgrade (modern Python syntax)
    "UP",
    # flake8-bugbear (common bugs and design issues)
    "B",
    # flake8-simplify (simplifiable constructs)
    "SIM",
    # isort (import sorting)
    "I",
]
 No newline at end of file
+7 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ from pythermogis.physics.temperature_grid_calculation import calculate_temperatu
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) -> xr.Dataset:
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:
    """
    Perform a deterministic Doublet performance simulation.

@@ -50,6 +50,12 @@ def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properti
    print_execution_duration : bool
        False by default, If set to True print the time in seconds it took to simulate across all reservoir properties

    mask_value : float
        Any cell that results in:
        1. a failed simulation
        2. failed input validation checks
        will be assigned the mask_value, by default it is 0

    Returns
    -------
    output_data : xr.Dataset
+32 −15
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ import numpy as np
import xarray as xr
from jpype import JClass

def simulate_doublet(output_data: xr.Dataset, reservoir_properties: xr.Dataset, rng_seed: int, utc_properties: JClass) -> xr.Dataset:
def simulate_doublet(output_data: xr.Dataset, reservoir_properties: xr.Dataset, rng_seed: int, utc_properties: JClass, mask_value: float) -> xr.Dataset:
    # Calculate transmissivity scaled by ntg and converted to Dm
    output_data[f"transmissivity_with_ntg"] = (output_data[f"transmissivity"] * reservoir_properties.ntg) / 1e3

@@ -42,7 +42,7 @@ def simulate_doublet(output_data: xr.Dataset, reservoir_properties: xr.Dataset,
    return output_data


def calculate_performance_of_single_location(mask: float, depth: float, thickness: float, porosity: float, ntg: float, temperature: float, transmissivity: float, transmissivity_with_ntg: float, rng_seed: int, utc_properties: JClass = None) -> float:
def calculate_performance_of_single_location(mask: float, depth: float, thickness: float, porosity: float, ntg: float, temperature: float, transmissivity: float, transmissivity_with_ntg: float, rng_seed: int, utc_properties: JClass = None, mask_value: float = 0.0) -> float:
    """
    Calculate the performance of a doublet at a single location.

@@ -86,16 +86,9 @@ def calculate_performance_of_single_location(mask: float, depth: float, thicknes
    inj_temp: float [C]
    prd_temp: float [C]
    """

    if np.isnan(thickness) or np.isnan(depth) or np.isnan(porosity) or np.isnan(ntg) or np.isnan(temperature) or np.isnan(transmissivity) or np.isnan(transmissivity_with_ntg):
        return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan

    if np.isnan(mask):
        return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
        #return 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0

    if (temperature<utc_properties.minProdTemp()):
        return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
    if not validate_input(depth, mask, ntg, porosity, temperature, thickness, transmissivity,
                   transmissivity_with_ntg, utc_properties):
        return (mask_value,) * 14

    # Instantiate ThermoGIS doublet
    doublet = instantiate_thermogis_doublet(utc_properties, rng_seed)
@@ -104,9 +97,9 @@ 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
    doublet.calculateDoubletPerformance(-9999.0, thickness, transmissivity, False)

    if doublet.getUtcPeurctkWh() == -9999.0:  # If calculation was not successful, return all nan
        return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
        #return 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
    # If calculation was not successful, return mask value
    if doublet.getUtcPeurctkWh() == -9999.0:
        return (mask_value,) * 14

    # calculate net-present-value using the utc-cutoffs
    if depth > utc_properties.utcDeepDepth():
@@ -140,6 +133,30 @@ def calculate_performance_of_single_location(mask: float, depth: float, thicknes
        "cophp"], output_values["pres"], output_values["flow_rate"], output_values["welld"], output_values["inj_temp"], output_values["prd_temp"]


def validate_input(depth: float,
    mask: float,
    ntg: float,
    porosity: float,
    temperature: float,
    thickness: float,
    transmissivity: float,
    transmissivity_with_ntg: float,
    utc_properties: float,
) -> bool:
    if np.any(np.isnan([depth,
                        mask,
                        ntg,
                        porosity,
                        temperature,
                        thickness,
                        transmissivity,
                        transmissivity_with_ntg])):
        return False

    if temperature < utc_properties.minProdTemp():
        return False
    return True

def instantiate_thermogis_doublet(utc_properties, rng_seed: int = None) -> JClass:
    """
    Instantiate a ThermoGIS Doublet class, setting necessary parameters from utc_properties and optionally using a specified random seed.
−81.5 KiB
Loading image diff...
Loading