Skip to main content

pyEMU is a set of python modules for interfacing with PEST and PEST++

Project description

pyEMU

python modules for model-independent FOSM (first-order, second-moment) (a.k.a linear-based, a.k.a. Bayes linear) uncertainty analyses and data-worth analyses, non-linear uncertainty analyses and interfacing with PEST and PEST++.
pyEMU also has a pure python (pandas and numpy) implementation of ordinary kriging for geostatistical interpolation and support for generating high-dimensional PEST(++) model interfaces, including support for (very) high-dimensional ensemble generation and handling

Master branch: GHA CI Coverage Status

Develop branch: GHA CI Coverage Status

Documentation

Complete user's guide:

https://pyemu.readthedocs.io/en/latest/

The pyEMU documentation is being treated as a first-class citizen! Also see the example notebooks in the repo.

What is pyEMU?

pyEMU is a set of python modules for model-independent, user-friendly, computer model uncertainty analysis. pyEMU is tightly coupled to the open-source suite PEST (Doherty 2010a and 2010b, and Doherty and other, 2010) and PEST++ (Welter and others, 2015, Welter and other, 2012), which are tools for model-independent parameter estimation. However, pyEMU can be used with generic array objects, such as numpy ndarrays.

Several equations are implemented, including Schur's complement for conditional uncertainty propagation (a.k.a. Bayes Linear estimation) (the foundation of the PREDUNC suite from PEST) and error variance analysis (the foundation of the PREDVAR suite of PEST). pyEMU has easy-to-use routines for parameter and data worth analyses, which estimate how increased parameter knowledge and/or additional data effect forecast uncertainty in linear, Bayesian framework. Support is also provided for high-dimensional Monte Carlo analyses via ObservationEnsemble and ParameterEnsemble class, including the null-space monte carlo approach of Tonkin and Doherty (2009); these ensemble classes also play nicely with PESTPP-IES.

pyEMU also includes lots of functionality for dealing with PEST(++) datasets, such as:

  • manipulation of PEST control files, including the use of pandas for sophisticated editing of the parameter data and observation data sections
  • creation of PEST control files from instruction and template files
  • going between site sample files and pandas dataframes - really cool for observation processing
  • easy-to-use observation (re)weighting via residuals or user-defined functions
  • handling Jacobian and covariance matrices, including functionality to go between binary and ASCII matrices, reading and writing PEST uncertainty files. Covariance matrices can be instantiated from relevant control file sections, such as parameter bounds or observation weights. The base Matrix class overloads most common linear algebra operators so that operations are automatically aligned by row and column name. Builtin SVD is also included in all Matrix instances.
  • geostatistics including geostatistical structure support, reading and writing PEST structure files and creating covariance matrices implied by nested geostatistical structures, and ordinary kriging (in the utils.geostats.OrdinaryKrige object), which replicates the functionality of pest utility ppk2fac.
  • composite scaled sensitivity calculations
  • calculation of correlation coefficient matrix from a given covariance matrix
  • Karhunen-Loeve-based parameterization as an alternative to pilot points for spatially-distributed parameter fields
  • a helper functions to start a group of tcp/ip workers on a local machine for parallel PEST++/BeoPEST runs
  • full support for prior information equations in control files
  • preferred differencing prior information equations where the weights are based on the Pearson correlation coefficient
  • verification-based tests based on results from several PEST utilities

Version => 1.1 includes the PstFrom setup class to support generating PEST(++) interfaces in the 100,000 to 1,000,000 parameter range with all the bells and whistles. A publication documenting the PstFrom class can be found here:

https://doi.org/10.1016/j.envsoft.2021.105022

A publication documenting pyEMU and an example application can be found here:

http://dx.doi.org/10.1016/j.envsoft.2016.08.017

Funding

pyEMU was originally developed with support from the U.S. Geological Survey. The New Zealand Strategic Science Investment Fund as part of GNS Science’s (https://www.gns.cri.nz/) Groundwater Research Programme has also funded contributions 2018-present. Intera, Inc. has also provided funding for pyEMU development and support

Examples

Several example ipython notebooks are provided to demonstrate typical workflows for FOSM parameter and forecast uncertainty analysis as well as techniques to investigate parameter contributions to forecast uncertainty and observation data worth. Example models include the Henry saltwater intrusion problem (Henry 1964) and the model of Freyberg (1988)

Related Links

https://github.com/usgs/pestpp

PEST - http://www.pesthomepage.org/

How to get started with pyEMU

pyEMU is available through pyPI:

>>>pip install pyemu

pyEMU needs numpy and pandas. For plotting, matplotloib, pyshp, and flopy to take advantage of the auto interface construction

Found a bug? Got a smart idea? Contributions welcome.

Feel free to raise and issue or submit a pull request.

pyEMU CI testing, using GitHub actions, has recently been switched over to run with pytest. We make use of pytest-xdist for parallel execution. Some notes that might be helpful for building your PR and testing:

  • Test files are in ./autotest
  • Pytest settings are in ./autotest/conftest.py and ./autotest/pytest.ini
  • Currently, files ending _tests.py or _tests_2.py are collected
  • Functions starting test_ or ending _test are collected
  • ipython notebooks in .examples are also run
  • As tests are run in parallel, where tests require read/write access to files it is safest to sandbox runs. Pytest has a built-in fixture tmp_path that can help with this. Setting optional argument --basetemp can be helpful for accessing the locally run files.

Running test locally

To be able to make clean use of pytests fixture decorators etc., it is recommended to run local tests through pytest (rather than use from script execution and commenting in main block). For e.g.:

Run all tests:

pytest --basetemp=runner autotest

with pytest-xdist, local runs can be parallelized:

pytest --basetemp=runner -n auto autotest

Run all tests in a file:

pytest --basetemp=runner -n auto autotest/testfile_tests.py

Run a specific test [this_test()]:

pytest --basetemp=runner autotest/testfile_tests.py::this_test

Using an IDE:

Most modern, feature-rich editors and IDEs support launching pytest within debug or run consoles. Some might need "encouraging" to recognise the non-standard test tags used in this library. For example, in pycharm, to support click-and-run testing, the pytest-imp plugin is required to pickup test functions that end with _test (a nosetest hangover in pyEMU).

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

pyemu-1.3.0.tar.gz (333.8 kB view details)

Uploaded Source

Built Distribution

pyemu-1.3.0-py3-none-any.whl (326.4 kB view details)

Uploaded Python 3

File details

Details for the file pyemu-1.3.0.tar.gz.

File metadata

  • Download URL: pyemu-1.3.0.tar.gz
  • Upload date:
  • Size: 333.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for pyemu-1.3.0.tar.gz
Algorithm Hash digest
SHA256 7d3b72a5100b3f0f28d5f126280316004489322e2c850fb2c32e8f1eed4396bb
MD5 82559102a1cb19937fba25a9628b076b
BLAKE2b-256 31834d4b1dbe7d4de6e67f337f367ce98b4ec9c2b8c87bc6074973f5a779352b

See more details on using hashes here.

File details

Details for the file pyemu-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyemu-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 326.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for pyemu-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6f237b6a74f9b3fefa2114140081e4c62c9398aa29c53735b30c519a73582a
MD5 4803cde027dddccedaae469e460a61e8
BLAKE2b-256 f25641a4061f80a4c374b2c2d278dd6b5361d48b4d44c63685ff009e1df0432f

See more details on using hashes here.

Supported by

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