cumBg {biogas} | R Documentation |
Calculate Cumulative Biogas Production
Description
cumBg
(for cumulative biogas) calculates cumulative biogas, methane production and production rates from individual volume (or mass) and composition measurements for any number of reactors.
Usage
cumBg(
# Main arguments
dat, dat.type = 'vol', comp = NULL, temp = NULL,
pres = NULL, interval = TRUE,
data.struct = 'long',
# Column names for volumetric method
id.name = 'id', time.name = 'time', dat.name = dat.type,
comp.name = 'xCH4',
# Additional arguments for manometric and gravimetric methods
pres.resid = NULL, temp.init = NULL, pres.init = NULL,
rh.resid = NULL,
rh.resid.init = 1, headspace = NULL,
vol.hs.name = 'vol.hs', headcomp = 'N2',
absolute = TRUE, pres.amb = NULL,
# Additional arguments for GCA method
mol.f.name = NULL, vol.syr = NULL,
# Calculation method and other settings
cmethod = 'removed', imethod = 'linear', extrap = FALSE,
addt0 = TRUE, showt0 = TRUE,
dry = FALSE,
empty.name = NULL,
# Warnings and messages
std.message = !quiet,
check = TRUE,
# Units and standard conditions
temp.std = getOption('temp.std', as.numeric(NA)),
pres.std = getOption('pres.std', as.numeric(NA)),
unit.temp = getOption('unit.temp', 'C'),
unit.pres = getOption('unit.pres', 'atm'),
quiet = FALSE
)
Arguments
dat |
a data frame with reactor identification code; time of measurement (as |
dat.type |
the type of data contained in |
comp |
(optional) a data frame with the columns reactor identification code; time of measurement, (as |
temp |
the temperature at which biogas volume was measured (when |
pres |
the absolute pressure at which biogas volume was measured (when |
interval |
do biogas measurements (volume or pressure) represent production only from the time interval between observations (default)?
|
data.struct |
the structure of input data. The default of 'long' means separate objects for volume (or pressure or mass for manometric and gravimetric methods) and composition (if available).
Each data frame must have reactor identification code and time columns with names specified with |
id.name |
name of the reactor identification code column in |
time.name |
name of column containing time data in |
dat.name |
name of column containing the primary response variable (volume or mass) in |
comp.name |
name of column containing biogas mole fraction of methane in |
pres.resid |
headspace pressure after venting.
Either a single numeric value, assumed to be the same for all observations, or the name of a column in |
temp.init |
initial headspace temperature in |
pres.init |
headspace pressure at the begining of the experiment.
Used in manometric method only ( |
rh.resid |
relative humidity of the gas in the headspace after venting.
If NULL (default), it is calculated for each interval as the ratio of post- to pre-venting pressure (equivalent to assuming relative water vapor concentration (mixing ratio) is the same before and after venting.
If entered, typically should be 1.0.
Length one numeric vector.
Used in manometric method only ( |
rh.resid.init |
relative humidity of the gas in the headspace at the begining of the experiment.
Typically should be 1.0 (the default).
Length one numeric vector.
Used in manometric method only ( |
headspace |
(optional) a data frame or length-one numeric vector with reactor headspace volume(s).
If a data frame is used, it should at least contain a |
vol.hs.name |
name of column containing headspace volume data in optional |
headcomp |
(optional) Composition of headspace for correction of initial headspace mass for gravimetric method only.
If provided, correction will be applied to first mass loss observation for each individual reactor.
See argument of the same name in |
absolute |
is the headspace pressure measured in the manometric method ( |
pres.amb |
absolute ambient pressure needed to calculate absolute pressure from gauge pressure measurements.
In atmospheres by default (see |
mol.f.name |
name of the column in |
vol.syr |
volume of the syringe used in the absolute GC method (Hansen et al., 2004) ( |
cmethod |
method for calculating cumulative methane production.
Applies to |
imethod |
method used for interpolation of |
extrap |
should |
addt0 |
is the earliest time in |
showt0 |
should “time zero” rows be returned in the output?
Can be convenient for plotting cumulative volumes.
Only applies if |
dry |
set to |
empty.name |
column containing a binary (logical, or integer or numeric (1 or 0)) variable indicating when accumulated biogas was emptied.
Use for mix of cumulative/interval data.
Only applies to volumetric data (dat.type = 'vol').
If used, |
std.message |
should a message with the standard conditions be displayed?
Default is |
check |
should input data be checked for unreasonable values (with warnings)?
Currently only composition values are checked.
Default is |
temp.std |
standard temperature for presentation of biogas and methane results.
Length one numeric vector.
Default value is 0 degrees C (set in |
pres.std |
standard pressure for presentation of biogas and methane results.
Length one numeric vector.
Default value is 1.0 atm (101325 Pa) (set in |
unit.temp |
temperature units for |
unit.pres |
pressure units for |
quiet |
use to suppress messages. Default is |
Details
Using volume, mass, pressure, or molar quantity data from dat
and gas composition from comp
, this function will calculate standardised biogas and methane production (if comp
is provided) for each observation, interpolating comp.name
(from comp
argument) to each time.name
in dat
if needed, and summing these for cumulative values.
Use of volumetric measurements is the default case.
However, this function is essentially deprecated for both volumetric and manometric methods, and the new calcBgMan
and calcBgVol
functions are recommended instead.
Alternatively, if reactor mass is given in dat
, a gravimetric approach (Hafner et al. 2015) can be applied by setting dat.type
to "mass"
.
In this case, to determine total cumulative biogas production for batch reactors, an initial mass should be included for each reactor.
If pressure is measured in dat
, a manometric method can be applied by setting dat.type
to "pres"
.
Lastly, molar quantity of methane can be used in the absolute GC method by setting dat.type
to "gca"
.
For the volumetric and absolute GC methods, all volumes (input and output) have the same units, e.g., mL, L, SCF.
For the gravimetric method, output volumes will be in mL if input masses are in g (or in L if input masses are in kg, etc.).
For the manometric method, inputs units are specified with unit.pres
, and output volumes are the same as headspace volume, e.g., mL or L.
Biogas composition (comp.name
column in comp
) is specified as the mole fraction of methane in dry biogas, normalised so mole fractions of methane and carbon dioxide sum to unity (Richards et al. 1991). Alternatively, if cmethod
is set to "total"
, biogas composition is the mole fraction of methane in dry biogas (include all the other gases except water).
Standard values and units for temperature and pressure can be globally set using the function options
.
See stdVol
.
To surpress volume correction to a “standard” temperature and pressure, leave temp
as NULL
(the default).
If check = TRUE
, the input values of mole fraction of methane in biogas are checked, and a warning is returned if the are outside 0, 1.
Value
a data frame with all the columns originally present in dat
, plus these others:
vBg |
Standardised volume of biogas production for individual event. |
xCH4 |
Interpolated mole fraction of methane in biogas. |
vCH4 |
Standardised volume of methane production for individual event. Only if |
vhsCH4 |
Standardised volume of methane present in reactor headspace. Only if |
cvBg |
Standardised cumulative volume of biogas production. |
cvCH4 |
Standardised cumulative volume of methane production. Only if |
rvBg |
Production rate of biogas. |
rvCH4 |
Production rate of methane. Only if |
Author(s)
Sasha D. Hafner and Charlotte Rennuit
References
Hafner, S.D., Rennuit, C., Triolo, J.M., Richards, B.K. 2015. Validation of a simple gravimetric method for measuring biogas production in laboratory experiments. Biomass and Bioenergy 83, 297-301.
Hansen, T.L., Schmidt, J.E., Angelidaki, I., Marca, E., Jansen, J. la C., Mosbak, H. and Christensen, T.H. 2004. Method for determination of methane potentials of solid organic waste. Waste Management 24, 393-400
Richards, B.K., Cummings, R.J., White, T.E., Jewell, W.J. 1991. Methods for kinetic analysis of methane fermentation in high solids biomass digesters. Biomass and Bioenergy 1: 65-73.
See Also
calcBgMan
,
calcBgVol
,
calcBgGD
,
summBg
,
interp
,
stdVol
,
options
Examples
data("vol")
data("comp")
head(vol)
head(comp)
# Calculate cumulative production and rates from vol and comp
cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, id.name = "id", time.name = "days",
comp.name = "xCH4", dat.name = "vol")
head(cum.prod)
# Note warnings and related NAs in results
# Set extrap = TRUE to extrapolate xCH4 to earliest times
# Calculate cumulative production and rates from vol and comp
cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, id.name = "id", time.name = "days",
comp.name = "xCH4", dat.name = "vol", extrap = TRUE)
head(cum.prod)
# In this case, we can use default values for some column names, so this call is identical
cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, time.name = "days", extrap = TRUE)
# Plot results
## Not run:
# Not run just because it is a bit slow
library(ggplot2)
qplot(x = days, y = cvCH4, data = cum.prod, xlab = "Time (d)",
ylab = "Cumulative methane production (mL)",color = id, geom = "line")
## End(Not run)
# Omit added time zero rows
cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, time.name = "days", extrap = TRUE,
showt0 = FALSE)
head(cum.prod)
## Not run:
# Not run just because it is a bit slow
qplot(x = days, y = cvCH4, data = cum.prod, xlab = "Time (d)",
ylab = "Cumulative methane production (mL)", color = id, geom = "line")
## End(Not run)
# Previous is different from never adding them in the first place (rates not calculated for first
# observations here)
cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, time.name = "days", extrap = TRUE,
addt0 = FALSE)
head(cum.prod)
## Not run:
# Not run just because it is a bit slow
qplot(x = days, y = cvCH4, data = cum.prod, xlab = "Time (d)",
ylab = "Cumulative methane production (mL)", color = id, geom = "line")
## End(Not run)
# Can use POSIX objects for time (but cumBg cannot add t0 rows here)
class(vol$date.time)
class(comp$date.time)
cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, time.name = "date.time", extrap = TRUE)
head(cum.prod)
## Not run:
# Not run just because it is a bit slow
qplot(x = date.time, y = cvCH4, data = cum.prod, xlab = "Time (d)",
ylab = "Cumulative methane production (mL)", color = id, geom = "line")
## End(Not run)
# Can leave out composition data, and then CH4 is not included in results
cum.prod <- cumBg(vol, temp = 20, pres = 1, time.name = "days")
head(cum.prod)
# Leave out pres or temp, and results are not standardised
cum.prod <- cumBg(vol, time.name = "days")
head(cum.prod)
# Example with input data frames with different column names
data("vol2")
data("comp2")
head(vol2)
head(comp2)
cum.prod <- cumBg(vol2, comp = comp2, temp = 20, pres = 1,
id.name = "bottle", time.name = "days",
dat.name = "meas.vol", comp.name = "CH4.conc")
head(cum.prod)
tail(cum.prod)
# Note warnings and related NAs in results
warnings()
# Set extrap = TRUE to avoid
cum.prod <- cumBg(vol2, comp = comp2, temp = 20, pres = 1,
id.name = "bottle", time.name = "days",
dat.name = "meas.vol", comp.name = "CH4.conc",
extrap = TRUE)
head(cum.prod)
## Not run:
# Not run just because it is a bit slow
qplot(x = days, y = cvCH4, data = cum.prod, xlab = "Time (d)",
ylab = "Cumulative methane production (mL)",
color = bottle, geom = "line")
## End(Not run)
# Mass example
data("mass")
mass
# Need to specify data type with dat.type argument (using default
# values for id.name, dat.name, and comp.name)
cum.prod <- cumBg(mass, dat.type = "mass", comp = comp, temp = 35,
pres = 1, time.name = "days")
cum.prod
# Drop time 0 rows
cum.prod <- cumBg(mass, dat.type = "mass", comp = comp, temp = 35,
pres = 1, time.name = "days", showt0 = FALSE)
cum.prod
# Add initial headspace correction (alternatively, headspace could
# be a data frame with a different volume for each reactor)
cum.prod <- cumBg(mass, dat.type = "mass", comp = comp, temp = 35,
pres = 1, time.name = "days", headspace = 300,
headcomp = "N2", temp.init = 20, showt0 = FALSE)
cum.prod
# Pressure example
data("strawPressure")
data("strawComp")
data("strawSetup")
cum.prod <- cumBg(strawPressure, dat.type = 'pres',
comp = strawComp, temp = 35,
id.name = 'bottle', time.name ='time',
dat.name = 'pres', comp.name = 'xCH4',
pres.resid = 'pres.resid', temp.init = 20,
pres.init = 101.325,
headspace = strawSetup,
vol.hs.name = 'headspace',
extrap = TRUE,
unit.pres = 'kPa', pres.std = 101.325)
head(cum.prod)
# Absolute GC method (long format is the only option)
# Generate some data--two bottles with identical results
# Units for n1 and n2 are micromoles of CH4
biogas <- data.frame(id = rep(c('A', 'B'), each = 5),
time.d = rep(1:5, 2),
n1 = rep(c(1.1, 2.4, 3.8, 5.9, 2.3), 2),
n2 = rep(c(NA, NA, NA, 1.2, NA), 2))
# Bottles were vented after the measurements on day 4
biogas
# Syringe volume is 0.25 mL
# Headspace volume is 50 mL
cp <- cumBg(biogas, id.name = 'id', time.name = 'time.d',
dat.name = 'n1', mol.f.name = 'n2', vol.syr= 0.25,
headspace = 50, dat.type = 'gca')
cp
# Suppose the bottles had two difference headspace volumes
setup <- data.frame(id = c('A', 'B'), vol.hs = c(50, 60))
cp2 <- cumBg(biogas, id.name = 'id', time.name = 'time.d',
dat.name = 'n1', mol.f.name = 'n2', vol.syr= 0.25,
headspace = setup, vol.hs.name = 'vol.hs', dat.type = 'gca')
cp2
# Different data structures
# Load example data
data("s3voll")
data("s3volw")
data("s3compl")
data("s3compw")
data("s3lcombo")
# wide
# Check data structure first
s3volw
s3compw
cum.prod <- cumBg(s3volw, comp = s3compw, temp = 25, pres = 1,
time.name = 'time.d',
data.struct = 'wide',
dat.name = 'D', comp.name = 'D',
extrap = TRUE)
cum.prod
# longcombo
s3lcombo
cum.prod <- cumBg(s3lcombo, temp = 25, pres = 1,
id.name = 'id', time.name = 'time.d',
data.struct = 'longcombo',
dat.name = 'vol.ml', comp.name = 'xCH4',
extrap = TRUE)
# Compare wide and longcombo to long (default)
s3voll
s3compl
cum.prod <- cumBg(s3lcombo, comp = s3compl, temp = 25, pres = 1,
id.name = 'id', time.name = 'time.d',
dat.name = 'vol.ml', comp.name = 'xCH4',
extrap = TRUE)
cum.prod