A comprehensive Python package for integrating hydrological model outputs with geophysical forward modeling and inversion
Project description
PyHydroGeophysX
A comprehensive Python package for integrating hydrological model outputs with geophysical forward modeling and inversion, specializing in electrical resistivity tomography (ERT) and seismic refraction tomography (SRT) for watershed monitoring applications.
๐ Key Features
- ๐ Hydrological Model Integration: Seamless loading and processing of MODFLOW and ParFlow outputs
- ๐ชจ Petrophysical Relationships: Advanced models for converting between water content, saturation, resistivity, and seismic velocity
- โก Forward Modeling: Complete ERT and SRT forward modeling capabilities with synthetic data generation
- ๐ Time-Lapse Inversion: Sophisticated algorithms for time-lapse ERT inversion with temporal regularization
- ๐๏ธ Structure-Constrained Inversion: Integration of seismic velocity interfaces for constrained ERT inversion
- ๐ Uncertainty Quantification: Monte Carlo methods for parameter uncertainty assessment
- ๐ High Performance: GPU acceleration support (CUDA/CuPy) and parallel processing capabilities
- ๐ Advanced Solvers: Multiple linear solvers (CGLS, LSQR, RRLS) with optional GPU acceleration
๐ Requirements
- Python 3.8 or higher
- NumPy, SciPy, Matplotlib
- PyGIMLi (for geophysical modeling)
- Optional: CuPy (for GPU acceleration), joblib (for parallel processing)
๐ ๏ธ Installation
From Source
git clone https://github.com/yourusername/PyHydroGeophysX.git
cd PyHydroGeophysX
pip install -e .
Dependencies
pip install numpy scipy matplotlib pygimli joblib tqdm
For GPU support (optional):
pip install cupy-cuda11x # Replace with your CUDA version
๐ Documentation
Comprehensive documentation is available at Read the Docs.
To build documentation locally:
cd docs
make html
๐๏ธ Package Structure
PyHydroGeophysX/
โโโ core/ # Core utilities
โ โโโ interpolation.py # Profile interpolation tools
โ โโโ mesh_utils.py # Mesh creation and manipulation
โโโ model_output/ # Hydrological model interfaces
โ โโโ modflow_output.py # MODFLOW data loading
โ โโโ parflow_output.py # ParFlow data loading
โโโ petrophysics/ # Rock physics models
โ โโโ resistivity_models.py # Waxman-Smits, Archie models
โ โโโ velocity_models.py # DEM, Hertz-Mindlin models
โโโ forward/ # Forward modeling
โ โโโ ert_forward.py # ERT forward modeling
โ โโโ srt_forward.py # Seismic forward modeling
โโโ inversion/ # Inverse modeling
โ โโโ ert_inversion.py # Single-time ERT inversion
โ โโโ time_lapse.py # Time-lapse inversion
โ โโโ windowed.py # Windowed time-lapse for large datasets
โโโ solvers/ # Linear algebra solvers
โ โโโ linear_solvers.py # CGLS, LSQR, RRLS with GPU support
โโโ Hydro_modular/ # Direct hydro-to-geophysics conversion
โโโ Geophy_modular/ # Geophysical data processing tools
๐ Examples
The examples/ directory contains comprehensive tutorials:
Ex1_model_output.py: Loading hydrological model outputsEx2_workflow.py: Complete workflow from hydro models to geophysical inversionEx3_Time_lapse_measurement.py: Creating synthetic time-lapse ERT dataEx4_TL_inversion.py: Time-lapse ERT inversion techniquesEx5_SRT.py: Seismic refraction tomography workflowEx6_Structure_resinv.py: Structure-constrained resistivity inversionEx7_structure_TLresinv.py: Structure-constrained time-lapse inversionEx8_MC_WC.py: Monte Carlo uncertainty quantification
๐ Quick Start
1. Hydrological Model Integration
Load and process outputs from various hydrological models:
# MODFLOW
from PyHydroGeophysX import MODFLOWWaterContent, MODFLOWPorosity
processor = MODFLOWWaterContent("sim_workspace", idomain)
water_content = processor.load_time_range(start_idx=0, end_idx=10)
# ParFlow
from PyHydroGeophysX import ParflowSaturation, ParflowPorosity
saturation_proc = ParflowSaturation("model_dir", "run_name")
saturation = saturation_proc.load_timestep(100)
2. Petrophysical Modeling
Convert between hydrological and geophysical properties:
from PyHydroGeophysX.petrophysics import (
water_content_to_resistivity,
HertzMindlinModel,
DEMModel
)
# Water content to resistivity (Waxman-Smits model)
resistivity = water_content_to_resistivity(
water_content=wc, rhos=100, n=2.2, porosity=0.3, sigma_sur=0.002
)
# Water content to seismic velocity (rock physics models)
hm_model = HertzMindlinModel()
vp_high, vp_low = hm_model.calculate_velocity(
porosity=porosity, saturation=saturation,
bulk_modulus=30.0, shear_modulus=20.0, mineral_density=2650
)
3. Forward Modeling
Generate synthetic geophysical data:
from PyHydroGeophysX.forward import ERTForwardModeling, SeismicForwardModeling
# ERT forward modeling
ert_fwd = ERTForwardModeling(mesh, data)
synthetic_data = ert_fwd.create_synthetic_data(
xpos=electrode_positions, res_models=resistivity_model
)
# Seismic forward modeling
srt_fwd = SeismicForwardModeling(mesh, scheme)
travel_times = srt_fwd.create_synthetic_data(
sensor_x=geophone_positions, velocity_model=velocity_model
)
4. Time-Lapse Inversion
Perform sophisticated time-lapse ERT inversions:
from PyHydroGeophysX.inversion import TimeLapseERTInversion, WindowedTimeLapseERTInversion
# Full time-lapse inversion
inversion = TimeLapseERTInversion(
data_files=ert_files,
measurement_times=times,
lambda_val=50.0, # Spatial regularization
alpha=10.0, # Temporal regularization
inversion_type="L2" # L1, L2, or L1L2
)
result = inversion.run()
# Windowed inversion for large datasets
windowed_inv = WindowedTimeLapseERTInversion(
data_dir="data/", ert_files=files, window_size=3
)
result = windowed_inv.run(window_parallel=True)
5. Uncertainty Quantification
Quantify uncertainty in water content estimates:
from PyHydroGeophysX.Geophy_modular import ERTtoWC
# Set up Monte Carlo analysis
converter = ERTtoWC(mesh, resistivity_values, cell_markers, coverage)
# Define parameter distributions for different geological layers
layer_distributions = {
3: { # Top layer
'rhos': {'mean': 100.0, 'std': 20.0},
'n': {'mean': 2.2, 'std': 0.2},
'porosity': {'mean': 0.40, 'std': 0.05}
},
2: { # Bottom layer
'rhos': {'mean': 500.0, 'std': 100.0},
'n': {'mean': 1.8, 'std': 0.2},
'porosity': {'mean': 0.35, 'std': 0.1}
}
}
converter.setup_layer_distributions(layer_distributions)
wc_all, sat_all, params = converter.run_monte_carlo(n_realizations=100)
stats = converter.get_statistics() # mean, std, percentiles
๐ Example Workflows
Complete Workflow: Hydrology to Geophysics
from PyHydroGeophysX import *
# 1. Load hydrological data
processor = MODFLOWWaterContent("modflow_dir", idomain)
water_content = processor.load_timestep(timestep=50)
# 2. Set up 2D profile interpolation
interpolator = ProfileInterpolator(
point1=[115, 70], point2=[95, 180],
surface_data=surface_elevation
)
# 3. Create mesh with geological structure
mesh_creator = MeshCreator(quality=32)
mesh, _ = mesh_creator.create_from_layers(
surface=surface_line, layers=[layer1, layer2]
)
# 4. Convert to resistivity
resistivity = water_content_to_resistivity(
water_content, rhos=100, n=2.2, porosity=0.3
)
# 5. Forward model synthetic ERT data
synthetic_data, _ = ERTForwardModeling.create_synthetic_data(
xpos=electrode_positions, mesh=mesh, res_models=resistivity
)
# 6. Invert synthetic data
inversion = ERTInversion(data_file="synthetic_data.dat")
result = inversion.run()
Structure-Constrained Inversion
# 1. Process seismic data to extract velocity structure
from PyHydroGeophysX.Geophy_modular import process_seismic_tomography, extract_velocity_structure
TT_manager = process_seismic_tomography(travel_time_data, lam=50)
interface_x, interface_z, _ = extract_velocity_structure(
TT_manager.paraDomain, TT_manager.model.array(), threshold=1200
)
# 2. Create ERT mesh with velocity interface constraints
from PyHydroGeophysX.Geophy_modular import create_ert_mesh_with_structure
constrained_mesh, markers, regions = create_ert_mesh_with_structure(
ert_data, (interface_x, interface_z)
)
# 3. Run constrained inversion
inversion = TimeLapseERTInversion(
data_files=ert_files, mesh=constrained_mesh
)
result = inversion.run()
๐ Advanced Features
GPU Acceleration
Enable GPU acceleration for large-scale inversions:
inversion = TimeLapseERTInversion(
data_files=files,
use_gpu=True, # Requires CuPy
parallel=True, # CPU parallelization
n_jobs=-1 # Use all available cores
)
๐ค Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ Citation
If you use PyHydroGeophysX in your research, please cite:
@software{chen2025pyhydrogeophysx,
author = {Chen, Hang},
title = {PyHydroGeophysX: Integrating Hydrological and Geophysical Modeling},
year = {2025},
publisher = {GitHub},
url = {https://github.com/yourusername/PyHydroGeophysX}
}
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- PyGIMLi team for the excellent geophysical modeling framework
- MODFLOW and ParFlow communities for hydrologic modeling tools
๐ง Contact
Author: Hang Chen
Email: hchen8@lbl.gov
Issues: GitHub Issues
PyHydroGeophysX - Bridging the gap between hydrological models and geophysical monitoring
Note: This package is under active development. Please report issues and feature requests through the GitHub issue tracker.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhydrogeophysx-0.1.0.tar.gz.
File metadata
- Download URL: pyhydrogeophysx-0.1.0.tar.gz
- Upload date:
- Size: 92.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1320b7e41665abe77204e3041127ea91c092aba00c4344b8558245897a03eeb
|
|
| MD5 |
c874746c01818a1e534bbe712f048656
|
|
| BLAKE2b-256 |
eade4a6cc285c26066ebdb0b2b23123d132532898032690f84ac05bb1151db38
|
File details
Details for the file pyhydrogeophysx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyhydrogeophysx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 105.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7308a2502f3bae76885b05927d942dd87806c8dce38d52c9705c4afb7ce89d2
|
|
| MD5 |
85e9c74087a2175a29ac438db8f4e61c
|
|
| BLAKE2b-256 |
f4f65c9644a5744b015e232d90b033deb4368d025dac59fbc0230768e40aaa9c
|