Skip to main content

A Python package for groundwater flow simulation and hydraulic tomography using the Reformulated Geostatistical Approach (RGA)

Project description

pyRGA

A Python package for groundwater flow simulation and hydraulic tomography using the Reformulated Geostatistical Approach (RGA).

Features

  • 2D steady-state and transient groundwater flow simulation
  • Hydraulic tomography analysis
  • Reformulated Geostatistical Approach (RGA) for parameter estimation
  • Parallel computation support
  • Visualization tools for hydraulic head and conductivity fields

Installation

pip install pyrga

Quick Start

Basic Usage

import numpy as np
from pyrga import hydraulic_tomography
from pyrga.RGA import prepare_physical_domain

# Define domain parameters
nx, ny = 64, 64
K = np.exp(np.random.randn(nx * ny) * 0.1 - 2)

# Prepare well configuration
well_nodes, Q, _, _ = prepare_physical_domain(nx, ny)

# Solve hydraulic tomography
heads = hydraulic_tomography(K, well_nodes, Q)

Complete Optimization Example

import numpy as np
import time
from pyrga import hydraulic_tomography
from pyrga.RGA import (
    generate_synthetic_field,
    prepare_physical_domain,
    observation_operator,
    forward_model,
    gauss_newton_dynamic_lambda,
    add_noise
)

# Define numerical domain parameters
nx = ny = 64     # Grid resolution

# Generate synthetic conductivity field
K, alpha, V, beta = generate_synthetic_field(
    nx, ny,
    k=50,                    # Number of retained components
    mu=-4,                   # Mean of the random field
    NR=400,                  # Number of random fields
    cov_type='gaussian',
    variance=1.0,            # Standard deviation squared
    lx=0.15,                # Correlation length in x
    ly=0.2                  # Correlation length in y
)

# Prepare physical domain and well configuration
well_nodes, Q, dx, dy = prepare_physical_domain(
    nx, ny,
    Lox=320,                # Domain length in x direction (m)
    Loy=320,                # Domain length in y direction (m)
    q_original=-0.02,       # Original pumping rate in m³/s
    well_relative_locs=None # Use default 5x5 grid of wells
)

# Solve hydraulic tomography
t0 = time.time()
hydraulic_heads = hydraulic_tomography(K, well_nodes, Q)
print(f"Elapsed time for solving HT: {time.time() - t0:.2f} seconds")

# Prepare observations
y0 = observation_operator(hydraulic_heads, well_nodes)

# Add measurement noise
y, obv_error = add_noise(y0, noise_level=0.05)

# Initialize optimization history
initial_history = {
    'true_alpha': alpha,
    'true_mu': -4,
    'true_y': y0,
    'alpha': [],
    'mu': [],
    'loss': [],
    'lambda': [],
    'step_norm': [],
    'time': [],
    'yp': []
}

# Run optimization
b, opt_history = gauss_newton_dynamic_lambda(
    lambda b: forward_model(b, V.T, Q, well_nodes),
    b0=np.concatenate((np.zeros(50), np.array([beta]))),
    y_obs=y,
    lam_init=1e-3,
    max_iter=10,
    tol=1e-5,
    history=initial_history,
    adaptive_lambda=False,
    anneal_lambda=True,
    min_lambda=1e-5
)

Documentation

For detailed documentation, please visit Read the Docs.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this software in your research, please cite:

@article{zhao2020reformulation,
  author = {Zhao, Yue and Luo, Jian},
  title = {Reformulation of Bayesian Geostatistical Approach on Principal Components},
  journal = {Water Resources Research},
  volume = {56},
  number = {4},
  pages = {e2019WR026732},
  year = {2020},
  doi = {https://doi.org/10.1029/2019WR026732},
  url = {https://doi.org/10.1029/2019WR026732},
  keywords = {geostatistical approach, inverse modeling, principal component}
}

Or in APA format:

Zhao, Y., & Luo, J. (2020). Reformulation of Bayesian Geostatistical Approach on Principal Components. Water Resources Research, 56(4), e2019WR026732. https://doi.org/10.1029/2019WR026732

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrga_ht-0.1.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrga_ht-0.1.2-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file pyrga_ht-0.1.2.tar.gz.

File metadata

  • Download URL: pyrga_ht-0.1.2.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for pyrga_ht-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0fd67a63c4c61dbfb11b6c27c0f205c617cf8f8cf8680fb0c3492e8342be263f
MD5 d3ecca1218084e2bd6743c6059d22459
BLAKE2b-256 0ca668af2efc77af135238f5c50e22a5d529d3327a6c22cca6de8ce6f8b9eb69

See more details on using hashes here.

File details

Details for the file pyrga_ht-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyrga_ht-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for pyrga_ht-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b9fa29663b2b1e93e4041ef842e39b13146db0c988ddd34c0bf06710ed74096
MD5 bad90d8efc372b80e87bc87a9b8340f2
BLAKE2b-256 b25ea3606e815e6158d7aff63d12b708cc03bdf5e804e251f05b7f102a22ce56

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page