TNO Intern

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

making changes so that the code fits the 88 line length and ruff formatting rules

parent feb83fe5
Loading
Loading
Loading
Loading
Loading

.pre-commit-config.yaml

deleted100644 → 0
+0 −5
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
+14 −32
Original line number Diff line number Diff line
@@ -203,7 +203,6 @@ environments:
      - conda: https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_1.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-2.0.0-pyhd8ed1ab_1.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/rich-14.0.0-pyh29332c3_0.conda
      - conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.13.0-h718f522_0.conda
      - conda: https://conda.anaconda.org/conda-forge/linux-64/s2n-1.5.21-h7ab7c64_0.conda
      - conda: https://conda.anaconda.org/conda-forge/linux-64/secretstorage-3.3.3-py313h78bf25f_3.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.8.2-pyhff2d567_0.conda
@@ -259,6 +258,7 @@ environments:
      - pypi: https://files.pythonhosted.org/packages/bd/24/12818598c362d7f300f18e74db45963dbcb85150324092410c8b49405e42/pyproject_hooks-1.2.0-py3-none-any.whl
      - pypi: https://files.pythonhosted.org/packages/05/19/94d6c66184c7d0f9374330c714f62c147dbb53eda9efdcc8fc6e2ac454c5/rasterio-1.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
      - pypi: https://files.pythonhosted.org/packages/2a/2f/63d2cacc0e525f8e3398bcf32bd3620385f22cd1600834ec49d7f3597a7b/rioxarray-0.19.0-py3-none-any.whl
      - pypi: https://files.pythonhosted.org/packages/a8/a6/7985ad1778e60922d4bef546688cd8a25822c58873e9ff30189cfe5dc4ab/ruff-0.13.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
      - pypi: https://files.pythonhosted.org/packages/b5/09/c5b6734a50ad4882432b6bb7c02baf757f5b2f256041da5df242e2d7e6b6/scipy-1.15.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
      - pypi: https://files.pythonhosted.org/packages/d1/a7/5c9cb413e4e2ce52c16be717e94abd40ce91b1f8974624d5d56154c5d40b/shapely-2.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
      - pypi: ./
@@ -431,7 +431,6 @@ environments:
      - conda: https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_1.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/rfc3986-2.0.0-pyhd8ed1ab_1.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/rich-14.0.0-pyh29332c3_0.conda
      - conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.13.0-h429b229_0.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.8.2-pyhff2d567_0.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_1.conda
      - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.17.0-pyhd8ed1ab_0.conda
@@ -491,6 +490,7 @@ environments:
      - pypi: https://files.pythonhosted.org/packages/bd/24/12818598c362d7f300f18e74db45963dbcb85150324092410c8b49405e42/pyproject_hooks-1.2.0-py3-none-any.whl
      - pypi: https://files.pythonhosted.org/packages/df/88/9db5f49ebfdd9c12365e4cac76c34ccb1a642b1c8cbab4124b3c681495de/rasterio-1.4.3-cp313-cp313-win_amd64.whl
      - pypi: https://files.pythonhosted.org/packages/2a/2f/63d2cacc0e525f8e3398bcf32bd3620385f22cd1600834ec49d7f3597a7b/rioxarray-0.19.0-py3-none-any.whl
      - pypi: https://files.pythonhosted.org/packages/61/21/0647eb71ed99b888ad50e44d8ec65d7148babc0e242d531a499a0bbcda5f/ruff-0.13.0-py3-none-win_amd64.whl
      - pypi: https://files.pythonhosted.org/packages/87/2e/892ad2862ba54f084ffe8cc4a22667eaf9c2bcec6d2bff1d15713c6c0703/scipy-1.15.3-cp313-cp313-win_amd64.whl
      - pypi: https://files.pythonhosted.org/packages/e3/f0/9f8cdf2258d7aed742459cea51c70d184de92f5d2d6f5f7f1ded90a18c31/shapely-2.1.0-cp313-cp313-win_amd64.whl
      - pypi: ./
@@ -4830,7 +4830,7 @@ packages:
- pypi: ./
  name: pythermogis
  version: 1.1.0
  sha256: 72377490b5fe0a81bb0feca89a06d8026ff0292c4df1d9275408f062f7704058
  sha256: 6b65f4805e94338a6160a1fa39a124410ee9af997fdbca4ab3cbefb643beb922
  requires_dist:
  - jpype1>=1.5.2,<2
  - xarray==2024.9.0.*
@@ -4838,6 +4838,7 @@ packages:
  - pytz>=2024.1,<2025
  - build>=1.2.2.post1,<2
  - pygridsio>=0.3.27,<0.4
  - ruff>=0.13.0,<0.14
  requires_python: '>=3.11'
  editable: true
- conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.13.3-hf636f53_101_cp313.conda
@@ -5203,35 +5204,16 @@ packages:
  - scipy ; extra == 'interp'
  - scipy ; extra == 'all'
  requires_python: '>=3.10'
- conda: https://conda.anaconda.org/conda-forge/linux-64/ruff-0.13.0-h718f522_0.conda
  noarch: python
  sha256: e9fbf08b633f8e85023873235b959958cf6518d0199628fbc022b7ed00310649
  md5: faa7bf93bbee4c29c1d1db270a8700d2
  depends:
  - python
  - __glibc >=2.17,<3.0.a0
  - libgcc >=14
  constrains:
  - __glibc >=2.17
  license: MIT
  purls:
  - pkg:pypi/ruff?source=hash-mapping
  size: 10887993
  timestamp: 1757556582032
- conda: https://conda.anaconda.org/conda-forge/win-64/ruff-0.13.0-h429b229_0.conda
  noarch: python
  sha256: 1851c53a56c1627930169a4da292df7dded6edbae94aa37b28a84c9a811e7fdf
  md5: 6ba664f3ec805fd5aff15b96370446cc
  depends:
  - python
  - vc >=14.3,<15
  - vc14_runtime >=14.44.35208
  - ucrt >=10.0.20348.0
  license: MIT
  purls:
  - pkg:pypi/ruff?source=hash-mapping
  size: 11132323
  timestamp: 1757556599278
- pypi: https://files.pythonhosted.org/packages/61/21/0647eb71ed99b888ad50e44d8ec65d7148babc0e242d531a499a0bbcda5f/ruff-0.13.0-py3-none-win_amd64.whl
  name: ruff
  version: 0.13.0
  sha256: 48e5c25c7a3713eea9ce755995767f4dcd1b0b9599b638b12946e892123d1efb
  requires_python: '>=3.7'
- pypi: https://files.pythonhosted.org/packages/a8/a6/7985ad1778e60922d4bef546688cd8a25822c58873e9ff30189cfe5dc4ab/ruff-0.13.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  name: ruff
  version: 0.13.0
  sha256: 03447f3d18479df3d24917a92d768a89f873a7181a064858ea90a804a7538991
  requires_python: '>=3.7'
- conda: https://conda.anaconda.org/conda-forge/linux-64/s2n-1.5.21-h7ab7c64_0.conda
  sha256: c8b252398b502a5cc6ea506fd2fafe7e102e7c9e2ef48b7813566e8a72ce2205
  md5: 28b5a7895024a754249b2ad7de372faa
+1 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ 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", "ruff>=0.13.0,<0.14"]


[tool.pytest.ini_options]
@@ -63,7 +63,6 @@ mkdocs = ">=1.6.1,<2"
mkdocstrings-python = ">=1.16.12,<2"
dask = ">=2025.5.1,<2026"
narwhals = ">=1.43.1,<2"
ruff = ">=0.13.0,<0.14"
pre-commit = ">=4.3.0,<5"

[tool.ruff]
+10 −8
Original line number Diff line number Diff line
@@ -9,12 +9,14 @@ from pythermogis.physics.temperature_grid_calculation import calculate_temperatu
from pythermogis.transmissivity.calculate_thick_perm_trans import generate_thickness_permeability_transmissivity_for_pvalues
from pythermogis.thermogis_classes.utc_properties import instantiate_utc_properties_builder

def calculate_doublet_performance_stochastic(reservoir_properties: xr.Dataset,
def calculate_doublet_performance_stochastic(
        reservoir_properties: xr.Dataset,
        utc_properties = None,
        rng_seed = None,
        p_values: List[float] = [50.0],
        chunk_size: int = None,
                                             print_execution_duration = False
        print_execution_duration = False,
        mask_value: float = np.nan
) -> xr.Dataset:
    """
    Perform a ThermoGIS Stochastic Doublet performance simulation.
@@ -134,7 +136,7 @@ def calculate_doublet_performance_stochastic(reservoir_properties: xr.Dataset,
                                                                                                          dask="parallelized",
                                                                                                          )

    output_data = simulate_doublet(output_data, reservoir_properties, rng_seed, utc_properties)
    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
+10 −3
Original line number Diff line number Diff line
@@ -2,9 +2,16 @@ 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, mask_value: float = np.nan) -> xr.Dataset:
def simulate_doublet(
    output_data: xr.Dataset,
    reservoir_properties: xr.Dataset,
    rng_seed: int,
    utc_properties: JClass,
    mask_value: float = np.nan
) -> 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
    output_data[f"transmissivity_with_ntg"] = (output_data[f"transmissivity"] *
                                               reservoir_properties.ntg) / 1e3

    # Calculate the doublet performance across all dimensions
    output_data_arrays = xr.apply_ufunc(calculate_performance_of_single_location,