This repository contains the R code and data for the Probabilistic Duration Model (PDM) described in:
Daniels, W. S., Jia, M., and Hammerling, D. M. (2024). Estimating methane emission durations using continuous monitoring systems. Environmental Science & Technology Letters, 11(11), 1187–1192. https://doi.org/10.1021/acs.estlett.4c00687
The PDM estimates how long methane emissions on oil and gas sites last, using concentration data from point-in-space continuous monitoring systems (CMS). It probabilistically accounts for nondetect times, the times when wind blows emitted methane away from the sensors so that the CMS records no elevated concentrations even though an emission may be ongoing. Ignoring nondetect times causes emission durations to be underestimated. The duration distributions can also be used to bound the duration of emissions detected by survey-based technologies (aircraft, satellites) that observe a given site infrequently.
The PDM has four steps, described in the paper. (1) Emission events are identified as spikes in the maximum background-removed concentration across sensors, and a source and emission rate are estimated for each of these "naive" events. (2) A Gaussian puff model simulates the concentrations that each event would cause at the sensors, giving an information mask of the periods when the CMS could have observed the emission. (3) For naive events with the same estimated source that are separated by a period of no information, the probability that they belong to the same emission is computed from the similarity of their estimated rates. (4) Monte Carlo sampling draws possible start and end times from the periods of no information, producing a distribution of possible durations for each event.
The code here applies the PDM to three controlled release campaigns (ADED 2022 and ADED 2023 at the Methane Emissions Technology Evaluation Center, METEC, in Fort Collins, Colorado, and a 2022 Stanford high emission rate campaign in Arizona) and to a production site in the Appalachian Basin, where CMS data were collected from August 21 to October 31, 2023 as part of the Appalachian Methane Initiative (AMI). On the blinded ADED 2023 releases the PDM has a bias of −4.9% (R² = 0.80), with 86.8% of estimates within a factor of 2 of the true duration. On the case study site, ignoring nondetect times underestimates durations by up to a factor of 65. The PDM assumes that each event has a single source, so it is not intended for sites with simultaneous emissions from several sources.
Note: this README was generated with Claude Sonnet 5.5.
CMS-durations/
├── code/
│ ├── MAIN_1_estimate_durations.R # applies the PDM to forward model output
│ ├── MAIN_2_analyze_controlled_release_results.R # evaluates the controlled releases, makes figures
│ ├── MAIN_3_analyze_case_study_results.R # makes the case study figures
│ └── helper_functions.R # functions used by all three scripts
├── input_data/
│ ├── <experiment>_forward_model_output_SAMPLE.RData # one week of CMS data and simulations (4 files)
│ ├── ADED2022_leak_data.csv # controlled release records (ground truth)
│ ├── ADED2023_leak_data.csv
│ └── Stanford_leak_data.RData
├── output_data/
│ ├── <experiment>_duration_estimates_SAMPLE.RData # MAIN_1 output for the sample week (4 files)
│ ├── case_study_duration_estimates.RData # MAIN_1 output for the full case study
│ └── <experiment>_duration_estimates_<arrangement>_arrangement_<n>_sensors.RData
├── figures/ # populated by MAIN_2 and MAIN_3
│ └── ADED2022/ ADED2023/ Stanford/ case_study/
├── LICENSE
└── README.md
The workflow is:
forward model output --MAIN_1--> duration estimates --MAIN_2 / MAIN_3--> figures
helper_functions.R is also loaded directly from this repository by the MDLQ code, so please do not move or rename it.
MAIN_1 takes two kinds of input: CMS concentration observations and simulated concentrations at the sensors for each potential source. They are stored together in the *_forward_model_output_SAMPLE.RData files, whose format must match the output of MAIN_1_simulate.R in the DLQ repository: a named list with the elements times (minute time stamps), obs (observed concentrations in ppm, one row per minute and one column per sensor), WD and WS (wind direction and speed), followed by one data frame per potential source with the simulated concentrations at each sensor. MAIN_1 assumes the simulations start at the fifth element of the list.
run.type |
Data set | CMS sensors | Potential sources | Sample period (UTC) | Ground truth (input_data/) |
|---|---|---|---|---|---|
| 1 | ADED 2022 (METEC) | 8 | Tank, Separator.East, Separator.West, Wellhead.East, Wellhead.West |
May 9–15, 2022 | ADED2022_leak_data.csv |
| 2 | ADED 2023 (METEC) | 10 | same as ADED 2022 | Mar 1–8, 2023 | ADED2023_leak_data.csv |
| 3 | Stanford (Arizona) | 6 | tall, short |
Nov 1–8, 2022 | Stanford_leak_data.RData |
| 4 | AMI case study | 7 | Production.Unit, Wellheads1, Wellheads2, Separator, Tanks |
Sep 1–8, 2023 | none |
The ground truth files hold the controlled release records (start and end times, release rates, and, for METEC, the equipment group and the number of emission points). They are used only by MAIN_2, which excludes multisource releases and the estimated events that overlap them.
Due to the proprietary nature of the CMS sensor technology used in this study, only a one-week sample of the concentration data from each experiment can be shared publicly. The full data can be made available for research purposes upon request (see Contact). The results obtained from the full data are pre-generated in output_data/ and are what MAIN_2 and MAIN_3 read, so the figures in the paper can be reproduced without the full data.
All .RData files in this repository were written with saveRDS() and must be read with readRDS(), not load().
| File | Contents |
|---|---|
<experiment>_duration_estimates_SAMPLE.RData |
MAIN_1 output for the sample week of each experiment |
case_study_duration_estimates.RData |
MAIN_1 output for the full case study (307 naive events) |
<experiment>_duration_estimates_<arrangement>_arrangement_<n>_sensors.RData |
Controlled release results using only n of the CMS sensors. Provided for n = 2, 4, 6, 8 (ADED 2022), n = 2, 4, 6, 8, 10 (ADED 2023), and n = 2, 4, 6 (Stanford). The best arrangement maximizes detections by the network given the wind data from the site; mean and worst are the suboptimal arrangements in Section S10 of the paper's Supporting Information. The sensors in each arrangement are listed in get.sensor.arrangement() in helper_functions.R. MAIN_2 reads only the best files. |
Each output file is a named list with one element per quantity below. all.durations, rate.est.all.events, and the other event-level elements have one entry per naive event.
| Element | Description |
|---|---|
all.durations |
Monte Carlo sample of possible durations (hours) for each naive event, named by the estimated source. The PDM point estimate is the mean of this sample (or the maximum, for an upper bound). |
original.durations |
Naive duration (hours) of each event, which does not account for nondetect times |
start.bounds, end.bounds |
Earliest possible start time and latest possible end time of each event |
loc.est.all.events |
Estimated source of each event |
rate.est.all.events, error.lower.all.events, error.upper.all.events |
Estimated emission rate (kg/h) of each event, with the 5th and 95th percentiles |
spikes, max.obs |
Event mask (time and events, with events equal to NA outside of naive events) and the minute-by-minute maximum background-removed concentration (ppm) across sensors |
info.list |
Information mask for each source, with events not NA during periods of information |
est.durations, source.names |
Mean duration estimate of each event grouped by source, and the source names |
start.similarity.scores, end.similarity.scores |
Rate similarity scores used to combine adjacent events (Equation 1 in the paper). Not present in the n-sensor controlled release files. |
The code is written in R and uses the packages lubridate, zoo, and scales, plus fields for MAIN_2:
install.packages(c("lubridate", "zoo", "scales", "fields"))rstudioapi is used only to set the working directory when the scripts are run inside RStudio, where it is already available. MAIN_1 also loads the spike detection algorithm (HELPER_spike_detection_algorithm.R) directly from the DLQ repository on GitHub, so it needs an internet connection. To run it offline, download that file and change the source() call near the top of MAIN_1 to point to the local copy.
All paths are relative to the code directory. In RStudio the scripts set the working directory automatically; otherwise run them from a terminal inside code:
cd code
Rscript MAIN_1_estimate_durations.R
Rscript MAIN_2_analyze_controlled_release_results.R
Rscript MAIN_3_analyze_case_study_results.RThe pre-generated files in output_data/ let you start at MAIN_2 or MAIN_3. The figure scripts do not create folders, so keep the subfolders of figures/.
Set run.type at the top of the script (1 to 4, see the table above; the default is 4). The script reads the matching sample file from input_data/ and then:
- Removes the background from the CMS observations.
- Identifies the naive events.
- Estimates the source and emission rate of each naive event.
- Creates the information mask from the simulated concentrations, scaled by the estimated rates.
- Estimates the distribution of possible durations for each event.
- Estimates emission frequencies, which are printed to the console as events per year (mean and 90% interval) for each source but not saved.
The results are saved to output_data/<experiment>_duration_estimates_SAMPLE.RData, overwriting the pre-generated file, so change save.dir first if you want to keep it. The Monte Carlo steps do not set a random seed, so re-running gives durations and rate intervals that differ slightly from the provided files. The sample week covers only a small part of each experiment, so it does not reproduce the results in the paper.
Set run.type to 1, 2, or 3 (the default is 2). The script reads the best arrangement results for 1 to N sensors (N = 8, 10, or 6) and the ground truth file, then compares the PDM and naive duration estimates to the true durations of the single-source releases using a linear fit through the origin. It saves one figure, figures/<experiment>/METEC_and_summary_best_solution_<experiment>_<N>_sensors.png, showing a parity plot of estimated and true durations and the factor of over- or underestimation of the best fit line as a function of the number of sensors. For ADED 2023 this is Figure 1 of the paper; the ADED 2022 and Stanford figures are in the Supporting Information.
This script reads case_study_duration_estimates.RData and saves the following figures to figures/case_study/:
| File | Contents |
|---|---|
case_study_summary.png |
Duration estimates by source (Figure 2b) |
case_study_example1.png |
Hypothetical snapshot measurement on September 28, 2023, with the overlapping CMS data, naive events, periods of information, and the resulting distribution of possible durations (Figure 3) |
case_study_example2.png, case_study_example3.png |
The same figure for snapshot measurements on October 8 and September 14, 2023 |
under_est_hists.png |
Factor by which the naive duration underestimates the PDM duration, for a snapshot measurement at every naive event |
method_illustration.png |
Illustration of the method on an example event |
case_study_time_series_<p>.png |
Time series of the naive events, colored by estimated source |
cannot open the connectionwhen saving a figure: the output folder does not exist. Run from thecodedirectory with thefigures/subfolders next to it.bad restore file magic numberorunknown input formatwhen reading a data file: usereadRDS()instead ofload().
If you use this code in your research, please cite the accompanying paper:
Daniels, W. S., Jia, M., and Hammerling, D. M. (2024). Estimating methane emission durations using continuous monitoring systems. Environmental Science & Technology Letters, 11(11), 1187–1192. https://doi.org/10.1021/acs.estlett.4c00687
@article{daniels_estimating_2024,
title = {Estimating {Methane} {Emission} {Durations} {Using} {Continuous} {Monitoring} {Systems}},
volume = {11},
doi = {10.1021/acs.estlett.4c00687},
number = {11},
urldate = {2024-11-27},
journal = {Environmental Science \& Technology Letters},
publisher = {American Chemical Society},
author = {Daniels, William S. and Jia, Meng and Hammerling, Dorit M.},
month = nov,
year = {2024},
pages = {1187--1192},
}The source and emission rate estimates build on the DLQ method: Daniels, W. S., Jia, M., and Hammerling, D. M. (2024). Detection, localization, and quantification of single-source methane emissions on oil and gas production sites using point-in-space continuous monitoring systems. Elementa: Science of the Anthropocene, 12(1), 00110. https://doi.org/10.1525/elementa.2023.00110. The Gaussian puff atmospheric dispersion model used for the forward simulations is described in Jia, M., Fish, R., Daniels, W. S., Sprinkle, B., and Hammerling, D. (2025). A fast and lightweight implementation of the Gaussian puff model for near-field atmospheric transport of trace gasses. Scientific Reports, 15, 18710. https://doi.org/10.1038/s41598-025-99491-x
This project is released under the MIT License; see LICENSE.
William Daniels (wdanie16@jh.edu). Please also contact the author to request access to the full CMS concentration data for research purposes.