Oil Production Greenhouse gas Emissions Estimator (OPGEE) — a Python package for life-cycle assessment (LCA) of oil and gas fields. OPGEEv4 translates a physical description of fields, processes, and material/energy streams (in XML) into a runnable model that computes energy use, greenhouse gas emissions, and carbon intensity (CI).
- Source code repository: https://github.com/msmasnadi/OPGEEv4
- Documentation: https://opgee.readthedocs.io/
- License: see License below and
LICENSE.txt
| Item | Location |
|---|---|
| Source code | opgee/ Python package |
| Command-line tool | opg (installed via pip install -e .) |
| Default LCA model and lookup tables | opgee/etc/, opgee/tables/ |
| Demo dataset (single oil field) | demo/demo_model.xml |
| Demo run scripts | demo/run_demo.sh, demo/run_demo.ps1 |
| Full documentation source | docs/ |
OPGEEv4 has been developed and tested on:
| OS | Versions tested |
|---|---|
| Microsoft Windows | Windows 10, Windows 11 |
| macOS | 12 (Monterey) and later |
| Linux | Ubuntu 20.04+, other x86_64 distributions |
| Component | Version |
|---|---|
| Python | 3.11 (recommended; see py3-opgee.yml) |
| Python (CI-tested) | 3.9–3.11 |
Python 3.12+ is not currently supported by all pinned dependencies.
All dependencies are listed in requirements.txt (generated from requirements.in).
Key packages and pinned versions:
| Package | Version |
|---|---|
| chemicals | 1.2.0 |
| dash | 2.18.1 |
| dask | 2024.11.2 |
| fluids | 1.0.27 |
| lxml | 5.3.0 |
| networkx | 3.4.2 |
| numpy | 1.26.4 |
| pandas | 2.2.3 |
| pint | 0.24.4 |
| scipy | 1.14.1 |
| thermo | 0.3.0 |
| thermosteam | 0.46.0 |
The complete list is in requirements.txt. Anaconda/Miniconda (or Miniforge) is the
recommended way to install dependencies; see py3-opgee.yml.
No special hardware is required. A standard desktop or laptop with at least 4 GB RAM and 2 CPU cores is sufficient for single-field runs. Large Monte Carlo studies or multi-field batches benefit from additional cores and memory; optional SLURM cluster support is available for HPC environments.
| Platform | Python | OPGEE version |
|---|---|---|
| Windows 10/11 | 3.11 | 4.0+ |
| macOS | 3.11 | 4.0+ |
| Ubuntu (GitHub Actions) | 3.9, 3.11 | 4.0+ |
Install Miniconda or Anaconda for your platform.
-
Clone the repository
git clone https://github.com/msmasnadi/OPGEEv4.git cd OPGEEv4 -
Create the conda environment (recommended)
conda env create -f py3-opgee.yml conda activate opgee
-
Install OPGEE in editable mode
pip install -e . -
Verify installation
opg --help
You should see the
opgsubcommand list (run,gui,graph,gensim, etc.).
On a normal desktop computer with a broadband connection:
| Step | Approximate time |
|---|---|
| Clone repository | < 1 minute |
conda env create |
5–15 minutes |
pip install -e . |
< 1 minute |
| Total | ~6–16 minutes |
Times depend on network speed and whether conda packages are cached locally.
If you already have Python 3.11 with scientific packages installed:
pip install -r requirements.txt
pip install -e .Using the conda environment file is preferred because it resolves binary dependencies
(e.g. lxml, numba) reliably across platforms.
The demo/ directory contains a small, real OPGEE model describing one onshore oil field
(AES-E1, Egypt) with water reinjection and crude-oil stabilization. The model merges with
the built-in default model (opgee/etc/opgee.xml) at run time.
Option A — bundled demo model (recommended for reviewers)
conda activate opgee
cd OPGEEv4
# Linux / macOS
bash demo/run_demo.sh
# Windows PowerShell
powershell -File demo/run_demo.ps1
# Or run directly:
opg run -m demo/demo_model.xml -a demo -o demo/output --cluster-type serialOption B — built-in example (no extra input files)
opg run -a example -o demo/output_builtin --cluster-type serialThis runs the pre-defined gas_lifting_field analysis from the default model.
After a successful run, the output directory contains CSV files. The primary result is
carbon_intensity.csv, with columns including:
| Column | Description |
|---|---|
analysis |
Analysis name (demo or example) |
field |
Field name |
node |
System boundary or process node |
CI |
Carbon intensity (g CO₂-eq / MJ) |
unit |
Unit string for CI |
Example structure (values are illustrative; exact numbers depend on model version):
analysis,field,trial,name,value,unit,node
demo,demo-field,,CI,12.34,grams/MJ,TOTAL
demo,demo-field,,CI,10.11,grams/MJ,Production
...Additional files may be written when detailed results are requested (-r detailed):
energy_use.csv— energy consumption by processemissions.csv— emissions by process and gas speciesgases.csv,streams.csv— detailed flows
On a normal desktop computer (Intel Core i5 / Apple M1 class, single field, serial mode):
| Demo | Approximate time |
|---|---|
demo/demo_model.xml (1 field) |
10–60 seconds |
Built-in example analysis (1 field) |
10–60 seconds |
-
Prepare a model XML file describing your field(s). Start from
opgee/etc/opgee.xmlordemo/demo_model.xml. Fields typically usemodifies="template"and override attributes with<A name="...">value</A>elements. See the XML format documentation. -
Define an analysis that references your field(s) via
<FieldRef>:<Analysis name="my-study"> <A name="functional_unit">oil</A> <FieldRef name="my-field"/> </Analysis>
-
Run the model:
opg run -m path/to/my_model.xml -a my-study -o results/ --cluster-type serial
By default, your XML is merged with the built-in model. Use
--no-default-modelonly if your file is fully self-contained. -
Inspect results in
results/carbon_intensity.csvand related CSV files. -
Optional — graphical interface:
opg gui -m path/to/my_model.xml
Opens a browser-based GUI at http://127.0.0.1:8050 for viewing the process network, editing parameters, and running the model interactively.
| Task | Command |
|---|---|
| Run multiple fields in parallel | opg run -a my-study -o results/ -c dask |
| Monte Carlo simulation | opg gensim then opg run with MCS options (see docs) |
| Merge XML model files | opg merge file1.xml file2.xml -o merged.xml |
| Convert CSV field data to XML | opg csv2xml fields.csv -o fields.xml |
| View process network graph | opg graph --field my-field |
Full subcommand reference: https://opgee.readthedocs.io/en/latest/opg.html
To reproduce quantitative results reported in the accompanying manuscript:
-
Install OPGEE as described in Section 2.
-
Obtain the manuscript model XML file(s) and any supplementary CSV inputs from the manuscript supplementary data (or from the authors upon request).
-
Run the analysis named in the manuscript, for example:
opg run -m manuscript_model.xml -a MANUSCRIPT_ANALYSIS -o reproduction/ --cluster-type serial
-
Compare
reproduction/carbon_intensity.csvagainst published tables/figures.
For Monte Carlo results, use the gensim subcommand to generate trial XML files from
parameter distributions, then run with the appropriate --num-trials and cluster options.
See https://opgee.readthedocs.io/en/latest/monte-carlo.html.
Note: Update the analysis name, model file path, and supplementary data location to match your manuscript before submission.
OPGEE is distributed under the terms in LICENSE.txt (Stanford University open
redistribution license). Software may be downloaded, modified, and redistributed free
of charge subject to the conditions in that file, including retention of copyright notices
and notification to the OPGEE maintainers.
Portions of the code derived from pygcam are additionally available under the MIT License.
For Nature submission: this license permits free academic use and redistribution with attribution. Contact Adam Brandt (abrandt@stanford.edu) regarding commercial use or endorsement questions.
A complete description of OPGEE's algorithms and process logic is provided in the accompanying manuscript:
| Item | Location in manuscript |
|---|---|
| Model overview and carbon-intensity calculation | Methods section |
| Process equations and pseudocode | Methods section |
| Software architecture | Methods section and/or Supplementary Information |
Action for authors: Replace the rows above with the exact section numbers/titles from your submitted manuscript before completing the Nature editor form.
Additional technical documentation:
- Architecture: https://opgee.readthedocs.io/en/latest/architecture.html
- Calculation of CI: https://opgee.readthedocs.io/en/latest/calculation.html
- Process implementations:
opgee/processes/(Python source)
If you use OPGEE in published research, please cite the accompanying Nature manuscript and this software repository:
[Authors]. OPGEEv4: Oil Production Greenhouse gas Emissions Estimator, version 4.
https://github.com/msmasnadi/OPGEEv4
- Repository issues: https://github.com/msmasnadi/OPGEEv4/issues
- OPGEE project: https://eao.stanford.edu/research-areas/opgee
- Improved performance
- Merged
run,runsim, andrunmanyinto a unifiedruncommand - Updated model XML format (
<FieldRef>inside<Analysis>)
- First public alpha release