PorousMediaLab
The toolbox for batch and 1D reactive transport modelling in porous media aimed at the easiness of use for the user without computational background.
What's New in v4.0.0
- Column transport conserves mass with depth-varying porosity and accounts for advection at flux boundaries. Existing
fluxandneumannruns can produce different results. Use the newdanckwertsboundary type to prescribe total inward flux. - Column boundary flux estimates now use gradients at the boundary nodes. Columns apply Henry partitioning and acid-base speciation after reactions, which can change stored concentrations.
- Calibration scores matched observations at every registered depth. Metric formulas, input validation, and seeded random sequences have changed. Species registration rejects invalid or duplicate names, and HDF5 loading returns UTF-8 strings as
str. - Richards flow conserves water on non-uniform grids, and column models can opt into Strang splitting. SciPy solvers accept configurable tolerances, and reaction solvers support signed rates.
See the changelog for all changes and migration details.
What's New in v3.0.0
Numerical-correctness fixes and a leaner, faster solver
- Restored true 4th/5th-order accuracy for the
rk4andbutcher5ODE solvers — a stage-arithmetic bug had silently reduced both to first-order (Euler) accuracy - Unified negative-value clipping across all ODE paths via a per-species
allow_negativeflag (Temperatureauto-enrolled), so legitimately negative variables survive on the default solver - ~4x faster column transport via cached LU factorization; vectorized van Genuchten functions and rate reconstruction
- Dropped the
scikit-learndependency; accessing an unknown species/attribute now raisesAttributeError - Expanded regression coverage for the numerical solvers
What's New in v2.2.0
Robustness and maintainability improvements with expanded test coverage:
- Input validation across the solver: division-by-zero guards and a CFL stability warning catch unstable grids early
- Behavior-preserving refactor of the core ODE/PDE solver and class contracts (boundary conditions, flux estimators, acid-base updates)
- Removed unused code (
sensitivity.pystubs, deadelement.py, legacy Python 2 compatibility) - Test suite expanded to 389 tests, including mathematical-correctness integration tests
What's New in v2.1.1
Correctness and packaging hardening for solver setup and release artifacts:
- Validates time and spatial grids to prevent silently shifted
dtanddx - Fixes ODE derivative ordering,
Batchsolver dispatch, flux estimators, and calibration depth comparisons - Removes obsolete binary build artifacts and legacy upload scripts from the source distribution
What's New in v2.1.0
2.4x overall performance improvement with optimized rate reconstruction:
- Vectorized
reconstruct_rates()method - 45x faster - Enabled numexpr multi-threading for parallel rate expression evaluation
- Pre-allocated arrays in hot loops to reduce memory overhead
What's New in v2.0.0
6-60x faster reaction integration with the new vectorized ODE solver:
- Reactions are now solved using a vectorized approach that processes all spatial points simultaneously
- Uses
scipy.integrate.solve_ivpwith LSODA method (auto-detects stiffness) - Backward compatible: use
ode_method='scipy_sequential'for the old behavior
| Spatial Points | Species | Speedup |
|---|---|---|
| 50 | 2 | 13x |
| 100 | 3 | 23x |
| 500 | 5 | 62x |
How to use
Have a look at "examples" folder.
Installation using pip
- Install Python version 3.10 or higher (click);
- To install the toolbox run
pip install porousmedialab - In terminal run
jupyter notebook; - You will see the folders in your home folder. You can navigate in any folder and create a new notebook with your model.
Development installation using Poetry
- Install Python version 3.10 or higher (click);
- Install Poetry 2.x (click);
- Clone this repository:
git clone https://github.com/biogeochemistry/PorousMediaLab - Navigate to the project folder:
cd PorousMediaLab - Install dependencies:
poetry install(add--with notebooksto run example Jupyter notebooks) - Run tests:
poetry run pytest - Activate the virtual environment:
eval $(poetry env activate)(or runpoetry env activateto print the activation command for your shell)
Development Commands (Makefile)
The project includes a Makefile for common tasks:
make install # Install dependencies
make test # Run test suite
make benchmark # Run performance optimization benchmark
make benchmark-ode # Run ODE solver benchmark
make build # Build package
make release # Show GitHub Release publishing instructions
make clean # Clean build artifacts
Publishing a Release
Set up a PyPI Trusted Publisher for the existing porousmedialab project once with these GitHub Actions settings.
| PyPI field | Value |
|---|---|
| Owner | biogeochemistry |
| Repository name | PorousMediaLab |
| Workflow name | publish.yml |
| Environment name | pypi |
In GitHub, create the pypi environment and select Selected branches and tags under Deployment branches and tags. Add a Tag rule with the pattern v*.
After CI passes on the release commit on master, publish a GitHub Release with a matching version tag such as v4.0.0. Set the GitHub pre-release flag for pre-release versions such as v4.1.0rc1. The workflow builds the distributions, smoke-tests the installed wheel, and uploads the distributions to PyPI using OIDC.
Manual installation
- Install Python version 3.10 or higher (click);
- Download and unzip or clone (using git) this repository (PorousMediaLab);
- Open terminal and go to the PorousMediaLab folder using
cdcommand. If you have problems with the terminal, check this guide; - Install dependencies:
pip install numpy numexpr scipy matplotlib seaborn h5py - In terminal run command
jupyter notebook; - You will see the folders of the PorousMediaLab project; you can go in "examples" folder and play with them.
Testing
To run the test suite:
pip install pytest pytest-cov pyyaml
pytest tests/ -v
For coverage report:
pytest tests/ --cov=porousmedialab --cov-report=term-missing
Citation
Igor Markelov (2020). Modelling Biogeochemical Cycles Across Scales: From Whole-Lake Phosphorus Dynamics to Microbial Reaction Systems. UWSpace. http://hdl.handle.net/10012/15513
Contribution
I am looking for contributors specifically for incorporation of:
- sensitivity tests
- unsaturated flow
- thermodynamic calculations
- your crazy ideas and needs
If you wish to contribute in this open source project, please, create pull request or contact me via email: is.markelov@gmail.com.
Acknowledgements
This project was funded by
-
Lakes in Transition (Research Council of Norway project no. 244558/E50 (https://prosjektbanken.forskningsradet.no/#/project/NFR/244558)
-
the Canada Excellence Research Chair in Ecohydrology (https://www.cerc.gc.ca/chairholders-titulaires/former-ancien-eng.aspx).
MIT License
Copyright (c) 2019 Igor Markelov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata
Release files for porousmedialab 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| porousmedialab-4.1.0.tar.gz | 61.9 kB | With provenance | Details for porousmedialab-4.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| porousmedialab-4.1.0-py3-none-any.whl | Python 3 | none | any | Details for porousmedialab-4.1.0-py3-none-any.whl |
Total release size: 127.9 kB
Release files / porousmedialab-4.1.0.tar.gz
| Download URL | porousmedialab-4.1.0.tar.gz |
|---|---|
| Size | 61.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d890d5f30104d9c686ca04ff3b3e881ff61559529213daf63afbc0ec75644bdc
|
|
BLAKE2b-256 checksum How to use checksums |
20dff4d9252740d3076f854d317bb7506b1132ca86196f45b6066bc13ee6e3a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / porousmedialab-4.1.0-py3-none-any.whl
| Download URL | porousmedialab-4.1.0-py3-none-any.whl |
|---|---|
| Size | 66.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ebbc13f055898071e36dacb6db50079bcf9fe25538737d464dccb913a3734568
|
|
BLAKE2b-256 checksum How to use checksums |
549e49c7cb9a2b786293436508f8187deef274b3f3602b0559dbf40251673e72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for porousmedialab 4.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for porousmedialab-4.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.