TNO Intern

Commit 3f7f7335 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Merge branch 'issue-67-tempnan' into 'main'

Issue 67 tempnan

See merge request AGS/pythermogis!82
parents b1041507 437cf52c
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6,3 +6,5 @@ __pycache__
*.egg-info
build
dist

tests/resources/test_output
 No newline at end of file
+170 −20

File changed.

Preview size limit exceeded, changes collapsed.

+25 −2
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pythermogis"
version = "1.1.0"
version = "1.1.1"
description = "This repository is used as a python API for the ThermoGIS Doublet simulations"
authors = [
    { name = "Hen Brett", email = "hen.brett@tno.nl" },
@@ -18,7 +18,9 @@ dependencies = [
    "jpype1>=1.5.2,<2",
    "xarray==2024.9.0.*",
    "pandas>=2.2.3,<3",
    "pytz>=2024.1,<2025", "build>=1.2.2.post1,<2", "pygridsio>=0.3.27,<0.4"]
    "pytz>=2024.1,<2025",
    "build>=1.2.2.post1,<2",
    "pygridsio>=0.3.27,<0.4"]


[tool.pytest.ini_options]
@@ -63,3 +65,24 @@ mkdocs = ">=1.6.1,<2"
mkdocstrings-python = ">=1.16.12,<2"
dask = ">=2025.5.1,<2026"
narwhals = ">=1.43.1,<2"
pre-commit = ">=4.3.0,<5"

[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",
]
+17 −6
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.

@@ -33,7 +33,7 @@ def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properti
        Optional variables:
        - transmissivity, units: Dm, if provided then permeability is ignored.
        - temperature : If not provided, temperature is estimated using the depth and a temperature gradient from `utc_properties`.
        - mask : If provided, all non-NaN values will result in setting corresponding output values to zero.
        - mask : If provided, all non-NaN values will result in setting corresponding output values to mask_value.

    utc_properties : JClass
        A Java class specifying the properties of the doublet being simulated
@@ -50,6 +50,10 @@ 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
        0.0 by default, Any cell that results in a failed simulation or corresponds to a
        non-nan value in the mask parameter will be assigned the mask value

    Returns
    -------
    output_data : xr.Dataset
@@ -76,7 +80,8 @@ def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properti
        - "transmissivity"
        - "transmissivity_with_ntg"
    """
    if print_execution_duration: start = timeit.default_timer()
    if print_execution_duration:
        start = timeit.default_timer()

    validate_input(reservoir_properties)

@@ -100,9 +105,13 @@ def calculate_doublet_performance(reservoir_properties: xr.Dataset, utc_properti
        reservoir_properties = auto_chunk_dataset(reservoir_properties, chunk_size)

    output_data = reservoir_properties.copy()
    output_data = simulate_doublet(output_data, reservoir_properties, rng_seed, utc_properties)
    if chunk_size is not None: output_data.load() # If chunking has occurred then the data must be de-chunked
    if print_execution_duration: print(f"Doublet simulation took {timeit.default_timer() - start:.1f} seconds")
    output_data = simulate_doublet(output_data, reservoir_properties, rng_seed, utc_properties, mask_value=mask_value)

    if chunk_size is not None:
        output_data.load() # If chunking has occurred then the data must be de-chunked

    if print_execution_duration:
        print(f"Doublet simulation took {timeit.default_timer() - start:.1f} seconds")

    return output_data

@@ -125,11 +134,13 @@ def validate_input(reservoir_properties: xr.Dataset):
    for variable in ["thickness", "porosity", "ntg", "depth"]:
        if variable not in reservoir_properties:
            missing_variables.append(variable)

    if len(missing_variables) > 0:
        raise ValueError(f"provided reservoir properties Dataset does not contain the following required variables: {missing_variables}")

    if "permeability" not in reservoir_properties and "transmissivity" not in reservoir_properties:
        raise ValueError(f"provided reservoir properties Dataset must provide either permeability or transmissivity variables, currently neither are provided")

    if "permeability" in reservoir_properties and "transmissivity" in reservoir_properties:
        warnings.warn("Both reservoir permeability and transmissivity provided; however the doublet simulation will use only the provided transmissivity and ignore permeability (transmissivity = permeability * thickness)")

+15 −9

File changed.

Preview size limit exceeded, changes collapsed.

Loading