Title: | Process Biogas Data and Predict Biogas Production |
---|---|
Description: | High- and low-level functions for processing biogas data and predicting biogas production. Molar mass and calculated oxygen demand (COD') can be determined from a chemical formula. Measured gas volume can be corrected for water vapor and to (possibly user-defined) standard temperature and pressure. Gas quantity can be converted between volume, mass, and moles. Gas composition, cumulative production, or other variables can be interpolated to a specified time. Cumulative biogas and methane production (and rates) can be calculated from raw data obtained using volumetric, manometric, gravimetric, or gas density methods for any number of bottles. With cumulative methane production data and data on bottle contents, biochemical methane potential (BMP) or specific methane production (SMP) can be calculated and summarized, including subtraction of the inoculum contribution and normalization by substrate mass. Cumulative production and production rates can be summarized in several different ways (e.g., omitting normalization) using the same function. Biogas quantity and composition can be predicted from substrate composition and additional, optional data. Inoculum and substrate mass can be determined for planning BMP experiments. Finally, first-order models can be fit to measurements in order to extract estimates of ultimate yield and kinetic constants. |
Authors: | Sasha D. Hafner [aut, cre] , Charlotte Rennuit [aut], Camilla Justesen [aut], Nanna Lojborg [aut], Jacob Mortensen [aut], Jonas Ohlsson [aut], Sergi Astals [ctb], Konrad Koch [ctb], Soeren Weinrich [ctb], Jin Mi Triolo [ctb], Ali Heidarzadeh Vazifehkhoran [ctb] |
Maintainer: | Sasha D. Hafner <[email protected]> |
License: | GPL-2 |
Version: | 1.61 |
Built: | 2024-12-05 13:55:29 UTC |
Source: | CRAN |
calcBgGD
(for calculate biogas from GD (gas density) measurements) calculates cumulative biogas, methane production and production rates from mass loss and volume measurements for any number of bottles.
calcBgGD( # Main arguments dat, temp.vol, temp.grav, pres.vol, pres.grav, # Column names id.name, time.name, vol.name, m.pre.name = NULL, m.post.name, comp.name = 'xCH4', # Settings vented.mass = FALSE, averaging = 'final', temp.init = NULL, pres.init = NULL, headspace = NULL, vol.hs.name = NULL, headcomp = 'N2', # Calculation method and other settings vmethod = 'vol', comp.lim = c(0, 1), comp.sub = NA, imethod = 'linear', extrap = FALSE, addt0 = TRUE, showt0 = TRUE, dry = FALSE, # Warnings and messages std.message = TRUE, 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') )
calcBgGD( # Main arguments dat, temp.vol, temp.grav, pres.vol, pres.grav, # Column names id.name, time.name, vol.name, m.pre.name = NULL, m.post.name, comp.name = 'xCH4', # Settings vented.mass = FALSE, averaging = 'final', temp.init = NULL, pres.init = NULL, headspace = NULL, vol.hs.name = NULL, headcomp = 'N2', # Calculation method and other settings vmethod = 'vol', comp.lim = c(0, 1), comp.sub = NA, imethod = 'linear', extrap = FALSE, addt0 = TRUE, showt0 = TRUE, dry = FALSE, # Warnings and messages std.message = TRUE, 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') )
dat |
a data frame with bottle identification code, time of measurement (as |
temp.vol |
temperature at which biogas volume was measured. |
temp.grav |
temperature of bottle headspace at time of biogas venting, prior to gravimetric measurement. |
pres.vol |
pressure at which biogas volume was measured. |
pres.grav |
pressure of bottle headspace at time of biogas venting, prior to gravimetric measurement. |
id.name |
name of the bottle identification code column in |
time.name |
name of column containing time data (cumulative time) in |
vol.name |
name of the measured biogas volume column in |
m.pre.name |
name of column containing pre-venting bottle mass in |
m.post.name |
name of column containing post-venting bottle mass in |
comp.name |
name of column with biogas composition to be added to output data frame. |
vented.mass |
Set to |
averaging |
type of averaging used for calculating biogas composition.
Default is |
temp.init |
optional initial headspace temperature. Used to correct results for initial headspace. See details. |
pres.init |
optional initial headspace pressure. Used to correct results for initial headspace. See details. |
headspace |
optional 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 |
optional name of column containing headspace volume data in optional |
headcomp |
optional initial headspace composition used to correct results for initial headspace.
Default of |
vmethod |
method used for calculating biogas volume.
Default of |
comp.lim |
acceptable limits on calculated methane mole fraction.
Any values outside of this range are set to |
comp.sub |
Value substituted in for calculated methane mole fraction when calculated value is outside of |
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 |
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 |
Using volume and mass loss data from dat
, this function will calculate standardized biogas and methane production for each observation using the gas density (GD) method.
See reference below for details on the method.
Standard values and units for temperature and pressure can be globally set using the function options
.
See stdVol
.
a data frame with all the columns originally present in dat
, plus others including these:
vBg |
Standardized volume of biogas production for individual event. |
xCH4 |
Calculated mole fraction of methane in biogas. |
vCH4 |
Standardized volume of methane production for individual event. |
cvBg |
Standardized cumulative volume of biogas production. |
cvCH4 |
Standardized cumulative volume of methane production. |
rvBg |
Production rate of biogas. |
rvCH4 |
Production rate of methane. |
Units are based on units in input data.
Sasha D. Hafner, Camilla Justesen, Jacob Mortensen
Justesen, C.G., Astals, S., Mortensen, J.R., Thorsen, R., Koch, K., Weinrich, S., Triolo, J.M., Hafner, S.D. 2019. Development and validation of a low-cost gas density method for measuring biochemical potential (BMP) Water (MDPI) 11(12): 2431.
calcBgMan
,
calcBgVol
,
summBg
,
interp
,
stdVol
,
options
data("UQGDBiogas") data("UQGDSetup") head(UQGDBiogas) head(UQGDSetup) cbg <- calcBgGD(UQGDBiogas, temp.vol = 20, pres.vol = 1013.25, temp.grav = 30, pres.grav = 1500, id.name = 'id', vol.name = 'vol', m.pre.name = 'mass.init', m.post.name = 'mass.final', time.name = 'time.d', unit.pres = 'mbar') BMP <- summBg(cbg, UQGDSetup, id.name = "id", time.name = 'time.d', descrip.name = 'descrip', inoc.name = "Inoculum", inoc.m.name = "m.inoc", norm.name = "m.sub.vs", when = 'end') BMP
data("UQGDBiogas") data("UQGDSetup") head(UQGDBiogas) head(UQGDSetup) cbg <- calcBgGD(UQGDBiogas, temp.vol = 20, pres.vol = 1013.25, temp.grav = 30, pres.grav = 1500, id.name = 'id', vol.name = 'vol', m.pre.name = 'mass.init', m.post.name = 'mass.final', time.name = 'time.d', unit.pres = 'mbar') BMP <- summBg(cbg, UQGDSetup, id.name = "id", time.name = 'time.d', descrip.name = 'descrip', inoc.name = "Inoculum", inoc.m.name = "m.inoc", norm.name = "m.sub.vs", when = 'end') BMP
calcBgGrav
calculates cumulative biogas, methane production and production rates from mass loss (gravimetric measurements) and volume measurements for any number of bottles.
calcBgGrav( # Main arguments dat, comp = NULL, temp = NULL, pres = NULL, data.struct = 'longcombo', id.name = 'id', time.name = 'time', mass.name, xCH4.name = 'xCH4', xCO2.name = NULL, xN2.name = NULL, headspace = NULL, vol.hs.name = 'vol.hs', temp.init = NULL, pres.init = NULL, pres.resid = NULL, headcomp = 'N2', cmethod = 'removed', imethod = 'linear', extrap = FALSE, addt0 = TRUE, showt0 = TRUE, std.message = !quiet, check = TRUE, 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 )
calcBgGrav( # Main arguments dat, comp = NULL, temp = NULL, pres = NULL, data.struct = 'longcombo', id.name = 'id', time.name = 'time', mass.name, xCH4.name = 'xCH4', xCO2.name = NULL, xN2.name = NULL, headspace = NULL, vol.hs.name = 'vol.hs', temp.init = NULL, pres.init = NULL, pres.resid = NULL, headcomp = 'N2', cmethod = 'removed', imethod = 'linear', extrap = FALSE, addt0 = TRUE, showt0 = TRUE, std.message = !quiet, check = TRUE, 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 )
dat |
a data frame with at least bottle identification code, time of measurement (as |
comp |
(optional) a data frame with the columns bottle identification code; time of measurement, (as |
temp |
the temperature of biogas just prior to venting.
A length-one numeric vector.
Degrees Celcius by default (see |
pres |
the absolute pressure of biogas prior to venting.
A length-one numeric vector or a character vector giving the name of the column in |
data.struct |
the structure of input data. The default of 'longcombo' means bottle mass and biogas composition (if available) are both in |
id.name |
name of the bottle identification code column in |
time.name |
name of column containing time data in |
mass.name |
name of column containing the primary response variable (bottle mass) in |
xCH4.name |
name of column containing biogas mole fraction of methane in |
xCO2.name |
name of column containing biogas mole fraction of carbon dioxide in |
xN2.name |
name of column containing biogas mole fraction of dinitrogen in |
headspace |
(optional) a data frame or length-one numeric vector with bottle 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 |
temp.init |
the initial headspace temperature.
Optional.
A length-one numeric vector.
Degrees Celcius by default (see |
pres.init |
the initial headspace pressure.
Optional.
A length-one numeric vector.
Atmospheres by default (see |
pres.resid |
residual headspace pressure after venting.
Optional.
A length-one numeric vector.
Atmospheres by default (see |
headcomp |
initial headspace composition as a chemical formula.
Optional, for correcting for change in headspace density.
Mixtures accepted.
Default is |
cmethod |
method for calculating cumulative methane production.
Use |
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 |
std.message |
should a message with the standard conditions be displayed?
Default is |
check |
should input data be checked for unreasonable values (with warnings)?
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 |
Using mass loss data from dat
and composition data from dat
or comp
, this function will calculate standardized biogas and methane production for each observation using a grvimetric method.
See reference below for details on the method.
Standard values and units for temperature and pressure can be globally set using the function options
.
See stdVol
.
a data frame with all the columns originally present in dat
, plus others including these:
vBg |
Standardized volume of biogas production for individual event. |
xCH4 |
Calculated mole fraction of methane in biogas. |
vCH4 |
Standardized volume of methane production for individual event. |
cvBg |
Standardized cumulative volume of biogas production. |
cvCH4 |
Standardized cumulative volume of methane production. |
rvBg |
Production rate of biogas. |
rvCH4 |
Production rate of methane. |
Units are based on units in input data.
Sasha D. Hafner
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.
calcBgMan
,
calcBgVol
,
calcBgGD
,
summBg
,
interp
,
stdVol
,
options
# Combined data frame with mass and composition for \code{data.struct = 'longcombo'} (default). data('UQGravBiogas') data('UQGravSetup') cbg <- calcBgGrav(UQGravBiogas, temp = 35, pres = 1.5, id.name = 'id', time.name = 'day', mass.name = 'mass.final', xCH4.name = 'xCH4') head(cbg) # With separate mass and composition data frames data('strawMass') data('strawComp') data('strawSetup') cbg0 <- calcBgGrav(strawMass, comp = strawComp, temp = 35, pres = 1.5, data.struct = 'long', id.name = 'bottle', time.name = 'time', mass.name = 'mass', xCH4.name = 'xCH4') warnings() cbg <- calcBgGrav(strawMass, comp = strawComp, temp = 35, pres = 1.5, data.struct = 'long', id.name = 'bottle', time.name = 'time', mass.name = 'mass', xCH4.name = 'xCH4', extrap = TRUE) head(cbg)
# Combined data frame with mass and composition for \code{data.struct = 'longcombo'} (default). data('UQGravBiogas') data('UQGravSetup') cbg <- calcBgGrav(UQGravBiogas, temp = 35, pres = 1.5, id.name = 'id', time.name = 'day', mass.name = 'mass.final', xCH4.name = 'xCH4') head(cbg) # With separate mass and composition data frames data('strawMass') data('strawComp') data('strawSetup') cbg0 <- calcBgGrav(strawMass, comp = strawComp, temp = 35, pres = 1.5, data.struct = 'long', id.name = 'bottle', time.name = 'time', mass.name = 'mass', xCH4.name = 'xCH4') warnings() cbg <- calcBgGrav(strawMass, comp = strawComp, temp = 35, pres = 1.5, data.struct = 'long', id.name = 'bottle', time.name = 'time', mass.name = 'mass', xCH4.name = 'xCH4', extrap = TRUE) head(cbg)
calcBgMan
(for cumulative biogas manometric) calculates cumulative biogas, methane production and production rates from individual pressure and composition measurements for any number of reactors.
calcBgMan( # Main arguments dat, comp = NULL, temp, interval = TRUE, data.struct = 'longcombo', # Column names id.name = 'id', time.name = 'time', pres.name = 'pres', comp.name = NULL, # Additional arguments pres.resid = NULL, temp.init = NULL, pres.init = NULL, rh.resid = NULL, rh.resid.init = 1, headspace = NULL, vol.hs.name = 'vol.hs', absolute = TRUE, pres.amb = NULL, # Calculation method and other settings cmethod = 'removed', imethod = 'linear', extrap = FALSE, addt0 = TRUE, showt0 = TRUE, # 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 )
calcBgMan( # Main arguments dat, comp = NULL, temp, interval = TRUE, data.struct = 'longcombo', # Column names id.name = 'id', time.name = 'time', pres.name = 'pres', comp.name = NULL, # Additional arguments pres.resid = NULL, temp.init = NULL, pres.init = NULL, rh.resid = NULL, rh.resid.init = 1, headspace = NULL, vol.hs.name = 'vol.hs', absolute = TRUE, pres.amb = NULL, # Calculation method and other settings cmethod = 'removed', imethod = 'linear', extrap = FALSE, addt0 = TRUE, showt0 = TRUE, # 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 )
dat |
a data frame with reactor identification code; time of measurement (as |
comp |
(optional) a data frame with the columns reactor identification code; time of measurement, (as |
temp |
the temperature at which headspace pressure was measured.
A length-one numeric vector or length-one character vector referring to a column in |
interval |
do biogas pressure measurements represent production only from the time interval between observations (default)?
|
data.struct |
the structure of input data. The default of 'longcombo' means headspace pressure and composition in a single column.
The |
id.name |
name of the reactor identification code column in |
time.name |
name of column containing time data in |
pres.name |
name of column containing the primary response variable (pressure) 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.
Can be absolute (default) or gauge depending on the value of |
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. |
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. |
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 |
absolute |
is the headspace pressure measured ( |
pres.amb |
absolute ambient pressure needed to calculate absolute pressure from gauge pressure measurements.
In atmospheres by default (see |
cmethod |
method for calculating cumulative methane production.
Use |
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 |
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 |
Using pressure 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.
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.
See associated vignette (calcBgMan_function.Rnw
) for more information.
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 |
Sasha D. Hafner and Nanna Lojborg
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.
cumBg
,
calcBgVol
,
calcBgGD
,
summBg
,
interp
,
stdVol
,
options
# Example with longcombo structured input data frame data("sludgeTwoBiogas") data("sludgeTwoSetup") head(sludgeTwoBiogas) head(sludgeTwoSetup) # Calculate cumulative production and rates # Pressure is gauge (not absolute) so absolute argument needed # Data structure is default of longcombo cbg <- calcBgMan(sludgeTwoBiogas, temp = 30, id.name = "id", time.name = "time.d", pres.name = "pres", comp.name = "xCH4n", temp.init = 30, pres.resid = 0, pres.init = 0, headspace = sludgeTwoSetup, vol.hs.name = "vol.hs", pres.amb = 1013, absolute = FALSE, unit.pres = "mbar") head(cbg) # Plot results ## Not run: # Not run just because it is a bit slow library(ggplot2) ggplot(cbg, aes(time.d, cvCH4, colour = factor(id))) + geom_point() + geom_line(aes(group = id)) + labs(x = "Time (d)", y = "Cumulative methane production (mL)", colour = "Bottle id") + theme_bw() ## End(Not run) # This sludgeTwoBiogas dataset has original xCH4 as well as normalized values # So "method 2" can also be used by changing comp.name and cmethod arguments cbg2 <- calcBgMan(sludgeTwoBiogas, temp = 30, id.name = "id", time.name = "time.d", pres.name = "pres", comp.name = "xCH4", temp.init = 30, pres.resid = 0, pres.init = 0, headspace = sludgeTwoSetup, vol.hs.name = "vol.hs", pres.amb = 1013, cmethod = 'total', absolute = FALSE, unit.pres = "mbar") head(cbg2) # Compare quantile(cbg2$vCH4 - cbg$vCH4) # Median difference of 0.2 mL # Example with long structured input data frame data("strawPressure") data("strawComp") data("strawSetup") # Need to specify data structure with \code{data.struct} argument # Using default values for time.name, pres.name cbg <- calcBgMan(strawPressure, comp = strawComp, temp = 31, data.struct = "long", id.name = "bottle", comp.name = "xCH4", temp.init = 21.55, pres.resid = "pres.resid", pres.init = 0, headspace = strawSetup, vol.hs.name = "headspace", pres.amb = 101.3, absolute = FALSE, unit.pres = "kPa") # Because of missing composition measurements at last time for some bottles # CH4 volume will be missing # Can estimate xCH4 here by extrapolation using argument of same name cbg2 <- calcBgMan(strawPressure, comp = strawComp, temp = 31, data.struct = "long", id.name = "bottle", comp.name = "xCH4", temp.init = 21.55, pres.resid = "pres.resid", pres.init = 0, headspace = strawSetup, vol.hs.name = "headspace", pres.amb = 101.3, absolute = FALSE, extrap = TRUE, unit.pres = "kPa") # For example with wide structured input data frame calcBgVol() help file
# Example with longcombo structured input data frame data("sludgeTwoBiogas") data("sludgeTwoSetup") head(sludgeTwoBiogas) head(sludgeTwoSetup) # Calculate cumulative production and rates # Pressure is gauge (not absolute) so absolute argument needed # Data structure is default of longcombo cbg <- calcBgMan(sludgeTwoBiogas, temp = 30, id.name = "id", time.name = "time.d", pres.name = "pres", comp.name = "xCH4n", temp.init = 30, pres.resid = 0, pres.init = 0, headspace = sludgeTwoSetup, vol.hs.name = "vol.hs", pres.amb = 1013, absolute = FALSE, unit.pres = "mbar") head(cbg) # Plot results ## Not run: # Not run just because it is a bit slow library(ggplot2) ggplot(cbg, aes(time.d, cvCH4, colour = factor(id))) + geom_point() + geom_line(aes(group = id)) + labs(x = "Time (d)", y = "Cumulative methane production (mL)", colour = "Bottle id") + theme_bw() ## End(Not run) # This sludgeTwoBiogas dataset has original xCH4 as well as normalized values # So "method 2" can also be used by changing comp.name and cmethod arguments cbg2 <- calcBgMan(sludgeTwoBiogas, temp = 30, id.name = "id", time.name = "time.d", pres.name = "pres", comp.name = "xCH4", temp.init = 30, pres.resid = 0, pres.init = 0, headspace = sludgeTwoSetup, vol.hs.name = "vol.hs", pres.amb = 1013, cmethod = 'total', absolute = FALSE, unit.pres = "mbar") head(cbg2) # Compare quantile(cbg2$vCH4 - cbg$vCH4) # Median difference of 0.2 mL # Example with long structured input data frame data("strawPressure") data("strawComp") data("strawSetup") # Need to specify data structure with \code{data.struct} argument # Using default values for time.name, pres.name cbg <- calcBgMan(strawPressure, comp = strawComp, temp = 31, data.struct = "long", id.name = "bottle", comp.name = "xCH4", temp.init = 21.55, pres.resid = "pres.resid", pres.init = 0, headspace = strawSetup, vol.hs.name = "headspace", pres.amb = 101.3, absolute = FALSE, unit.pres = "kPa") # Because of missing composition measurements at last time for some bottles # CH4 volume will be missing # Can estimate xCH4 here by extrapolation using argument of same name cbg2 <- calcBgMan(strawPressure, comp = strawComp, temp = 31, data.struct = "long", id.name = "bottle", comp.name = "xCH4", temp.init = 21.55, pres.resid = "pres.resid", pres.init = 0, headspace = strawSetup, vol.hs.name = "headspace", pres.amb = 101.3, absolute = FALSE, extrap = TRUE, unit.pres = "kPa") # For example with wide structured input data frame calcBgVol() help file
calcBgVol
(for calculation of biogas production from volumetric) measurements) calculates cumulative biogas, methane production and production rates from individual volume and composition measurements for any number of bottles.
calcBgVol( # Main arguments dat, comp = NULL, temp = NULL, pres = NULL, interval = TRUE, data.struct = 'longcombo', # Column names id.name = 'id', time.name = 'time', vol.name = 'vol', comp.name = NULL, # Additional arguments headspace = NULL, vol.hs.name = 'vol.hs', # 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 )
calcBgVol( # Main arguments dat, comp = NULL, temp = NULL, pres = NULL, interval = TRUE, data.struct = 'longcombo', # Column names id.name = 'id', time.name = 'time', vol.name = 'vol', comp.name = NULL, # Additional arguments headspace = NULL, vol.hs.name = 'vol.hs', # 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 )
dat |
a data frame with bottle identification code; time of measurement (as |
comp |
(optional) a data frame with the columns bottle identification code; time of measurement, (as |
temp |
the temperature at which biogas volume was measured.
A length-one numeric vector.
Degrees Celcius by default (see |
pres |
the absolute pressure at which biogas volume was measured.
A length-one numeric vector or a character vector giving the name of the column in |
interval |
do biogas volume measurements represent production only from the time interval between observations (default)?
|
data.struct |
the structure of input data. The default of 'longcombo' means volume and composition (if available) are both in |
id.name |
name of the bottle identification code column in |
time.name |
name of column containing time data in |
vol.name |
name of column containing the primary response variable (as-measured volume) in |
comp.name |
name of column containing biogas mole fraction of methane in |
headspace |
(optional) a data frame or length-one numeric vector with bottle 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 |
cmethod |
method for calculating cumulative methane production.
Use |
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.
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 |
Using volume 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.
All volumes (input and output) have the same units, e.g., mL, L, SCF.
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.
See associated vignette (calcBgVol_function.Rnw
) for more information.
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 bottle 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 |
Sasha D. Hafner and Nanna Lojborg
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.
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.
cumBg
,
calcBgMan
,
calcBgGD
,
summBg
,
interp
,
stdVol
,
options
# Example with long structured input data frame data("s3lcombo") s3lcombo # Calculate cumulative production and rates from s3lcombo # With default data structure comp argument is not needed # Necessary to extrapolate because first observations are missing xCH4 cbg <- calcBgVol(s3lcombo, temp = 25, pres = 1, id.name = 'id', time.name = 'time.d', vol.name = 'vol.ml', comp.name = 'xCH4', extrap = TRUE) head(cbg) # Plot results ## Not run: # Not run just because it is a bit slow ggplot(cbg, aes(time.d, cvCH4, colour = id)) + geom_point() + geom_line(aes(group = id)) + labs(x = "Time (d)", y = "Cumulative methane production (mL)", colour = "Bottle ID") + theme_bw() plot(ggplot) ## End(Not run) # Wide data structure, from AMPTS II in this case data("feedVol") head(feedVol) # By default biogas is assumed to be saturated with water vapor # Composition is set to a single value. # Data are cumulative args(calcBgVol) cbg <- calcBgVol(feedVol, comp = 1, temp = 0, pres = 1, interval = FALSE, data.struct = 'wide', id.name = "id", time.name = 'time.d', vol.name = '1', dry = TRUE) head(cbg) # Calculate cumulative production and rates from vol and comp # Biogas volume and composition can be in separate data frames data("vol") data("comp") head(vol) head(comp) # extrap = TRUE is needed to get CH4 results here because first xCH4 values are missing cbg <- calcBgVol(vol, comp = comp, temp = 20, pres = 1, data.struct = "long", id.name = "id", time.name = "days", comp.name = "xCH4", vol.name = "vol", extrap = TRUE) head(cbg)
# Example with long structured input data frame data("s3lcombo") s3lcombo # Calculate cumulative production and rates from s3lcombo # With default data structure comp argument is not needed # Necessary to extrapolate because first observations are missing xCH4 cbg <- calcBgVol(s3lcombo, temp = 25, pres = 1, id.name = 'id', time.name = 'time.d', vol.name = 'vol.ml', comp.name = 'xCH4', extrap = TRUE) head(cbg) # Plot results ## Not run: # Not run just because it is a bit slow ggplot(cbg, aes(time.d, cvCH4, colour = id)) + geom_point() + geom_line(aes(group = id)) + labs(x = "Time (d)", y = "Cumulative methane production (mL)", colour = "Bottle ID") + theme_bw() plot(ggplot) ## End(Not run) # Wide data structure, from AMPTS II in this case data("feedVol") head(feedVol) # By default biogas is assumed to be saturated with water vapor # Composition is set to a single value. # Data are cumulative args(calcBgVol) cbg <- calcBgVol(feedVol, comp = 1, temp = 0, pres = 1, interval = FALSE, data.struct = 'wide', id.name = "id", time.name = 'time.d', vol.name = '1', dry = TRUE) head(cbg) # Calculate cumulative production and rates from vol and comp # Biogas volume and composition can be in separate data frames data("vol") data("comp") head(vol) head(comp) # extrap = TRUE is needed to get CH4 results here because first xCH4 values are missing cbg <- calcBgVol(vol, comp = comp, temp = 20, pres = 1, data.struct = "long", id.name = "id", time.name = "days", comp.name = "xCH4", vol.name = "vol", extrap = TRUE) head(cbg)
calcCOD
is used to calculate the oxygen demand (“calculated oxygen demand”, or COD' as described by Rittmann and McCarty (2001)) of a compound.
calcCOD(form)
calcCOD(form)
form |
a chemical formula, as a character vector, e.g., |
Based on Eqs. (2.2) and (2.3) in Rittmann and McCarty (2001) (p 128), but using molar mass calculated with molMass
.
calcCOD
is not case-sensitive as long as all elements have single letter abbreviations.
The function is vectorized.
A numeric vector with length equal to length of form
with COD' in g of oxygen per g of compound.
Sasha D. Hafner and Charlotte Rennuit
Rittmann, B., McCarty, P. 2001 Environmental Biotechnology. McGraw-Hill.
calcCOD("C6H12O6") calcCOD("CH3COOH") calcCOD("CH3CH2OH") calcCOD("CH4") calcCOD("ch4") calcCOD(c("C6H12O6", "CH3COOH", "CH3CH2OH"))
calcCOD("C6H12O6") calcCOD("CH3COOH") calcCOD("CH3CH2OH") calcCOD("CH4") calcCOD("ch4") calcCOD(c("C6H12O6", "CH3COOH", "CH3CH2OH"))
Methane content (biogas composition) measurements from nine batch reactors.
data("comp")
data("comp")
A data frame with 132 observations on the following 4 variables.
id
identification code, a unique value for each reactor in the dataset. A factor with levels 2_1
, 2_2
, 2_3
, 2_4
, 2_5
, 2_6
, 2_7
, 2_8
, 2_9
, 2_10
, 2_11
, and 2_12
date.time
date and time of mass measurement, a POSIXct object.
days
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
xCH4
biogas methane content as a mole fraction, excluding water and all other gases other than carbon dioxide, a numeric vector
These data are meant to be example data for multiple functions, e.g., interp
, cumBg
, or summBg
.
Reactors were 500 mL glass serum bottles with butyl rubber septa and screw caps.
Methane and carbon dioxide contents were determined by gas chromatography using a thermal conductivity detector and normalised so methane and carbon dioxide sum to 1.0.
Data in vol
, mass
, comp
, and setup
are from the same reactors.
Measurements by Charlotte Rennuit and Ali Heidarzadeh Vazifehkhoran.
data(comp)
data(comp)
Methane content (biogas composition) measurements from 15 batch reactors.
data("comp2")
data("comp2")
A data frame with 360 observations on the following 3 variables.
bottle
identification code, a unique value for each reactor in the dataset. A factor with levels 1_1
, 1_2
, 1_3
, 2_1
, 2_2
, 2_2
, ... through 5_3
. The first number indicates the sample, the second the replicate.
days
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
CH4.conc
biogas methane content as a mole fraction, excluding water and all other gases other than carbon dioxide, a numeric vector
These data are meant to be example data for multiple functions, e.g., interp
, cumBg
, or summBg
.
Reactors were 500 mL or 1000 mL glass serum bottles with butyl rubber septa and screw caps.
Methane and carbon dioxide contents were determined by gas chromatography using a thermal conductivity detector and normalised so methane and carbon dioxide sum to 1.0.
Data in vol2
, comp2
, and setup2
are from the same reactors.
Measurements made by Ali Heidarzadeh Vazifehkhoran
data(comp2)
data(comp2)
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.
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 )
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 )
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 |
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.
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 |
Sasha D. Hafner and Charlotte Rennuit
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.
calcBgMan
,
calcBgVol
,
calcBgGD
,
summBg
,
interp
,
stdVol
,
options
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
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
Information on bottle id, substrates and, inoculum initial masses for 12 anaerobic bottles with animal feed ingredients for substrate.
data("feedSetup")
data("feedSetup")
A data frame with 12 observations on the following 3 variables:
descrip
description of bottle contents.
id
identification code, a unique value for each bottle in the dataset. Numeric with all values from 1 to 12.
m.inoc
mass of inoculum added to the bottle at the start in g, a numeric vector.
m.sub.vs
mass of volatile solids (VS) of substrate added to the bottle at the start in g, a numeric vector.
These data are meant to be example data for summBg
.
Inoculum was digestate from a stable laboratory reactor (400 L) operated at mesophilic temperatures (38 degrees C) and a retention time of ca. 98 days
Substrates were cellulose, wheat straw (WS), and animal feed ingredients (FI).
Additinally, 1 mL each of a vitamin mixture and trace element solution was added to each BMP bottle.
BMP tests were operated with a total volume of ca. 400 mL at 38 degrees C.
Data in feedVol
and feedSetup
are from the same bottles.
Data were originally collected by Soeren Weinrich and others at DBFZ in Leipzig Germany.
data(feedSetup)
data(feedSetup)
Cumulative standardized measurements of biogas volume from 12 batch bottles, organized in a “wide” format.
data("feedVol")
data("feedVol")
A data frame with 44 observations on the following 13 variables (note that all biogas volume columns, 2-13, are similar):
time.d
elapsed time of volume measurements in days, a numeric vector.
1
cumulative standardized volume of biogas produced at time given in time
from bottle “1” in mL, a numeric vector.
2
volume of biogas from bottle “2”.
3
volume of biogas from bottle “3”.
4
volume of biogas from bottle “4”.
5
volume of biogas from bottle “5”.
6
volume of biogas from bottle “6”.
7
volume of biogas from bottle “7”.
8
volume of biogas from bottle “8”.
9
volume of biogas from bottle “9”.
10
volume of biogas from bottle “10”.
11
volume of biogas from bottle “11”.
12
volume of biogas from bottle “12”.
These data are meant to be example data for calcBgVol
and summBg
.
Inoculum was digestate from a stable laboratory reactor (400 L) operated at mesophilic temperatures (38 degrees C) and a retention time of ca. 98 days
Substrates were cellulose, wheat straw (WS), and animal feed ingredients (FI).
Additinally, 1 mL each of a vitamin mixture and trace element solution was added to each BMP bottle.
BMP tests were operated with a total volume of ca. 400 mL at 38 degrees C.
Biogas productions was measured using the online volumtric AMPTS II method. Carbon dioxide was produced using an alkaline trap, so biogas volume is equal to methane volume.
Data in feedSetup
and feedVol
are from the same bottles.
Data were originally collected by Soeren Weinrich and others at DBFZ in Leipzig Germany.
data(feedVol)
data(feedVol)
fitFOM
(FOM is for first order model) is a flexible function for fitting first-order models to batch biogas production data, typically from a biochemical methane potential (BMP) test.
fitFOM(dat, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4', fit.to = 'yield', method = 'Nelder-Mead', abs.err = FALSE, trans = TRUE, init = if (n.pool == 1) c(B = 'yield', k = 0.5) else c(B = 'yield', f = 0.5, k1 = 0.01, k2 = 0.5), fixed = NULL, fit.last = FALSE, lower = NULL, upper = NULL, lag.phase = FALSE)
fitFOM(dat, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4', fit.to = 'yield', method = 'Nelder-Mead', abs.err = FALSE, trans = TRUE, init = if (n.pool == 1) c(B = 'yield', k = 0.5) else c(B = 'yield', f = 0.5, k1 = 0.01, k2 = 0.5), fixed = NULL, fit.last = FALSE, lower = NULL, upper = NULL, lag.phase = FALSE)
dat |
a data frame with columns for elapsed time and cumulative methane yield ("specific methane production" SMP) or another response variable. |
n.pool |
Number of substrate pools to include in the model. 1 or 2. Length-one numeric vector. |
time.name |
Name of the column in |
resp.name |
Name of the column in |
fit.to |
Should fitting be to cumulative yield ( |
method |
Method used to fit the model, i.e., to estimate best-fit parameter values.
Default of |
abs.err |
Should fitting be based on mean absolute error ( |
trans |
Should parameter values be transformed for fitting?
If |
init |
Vector of initial parameter estimates.
See defaults for elements.
For |
fixed |
Fixed parameters that should be excluded from optimization. Named numeric vector. |
fit.last |
Set to |
lower |
Optional lower parameter value limits.
Only available with some |
upper |
Optional upper parameter value limits.
Only available with some |
lag.phase |
Should the "lag phase" be excluded from fitting?
This period is defined as all observations prior to maximum average production rate.
Default of |
Use for fitting a first-order model (estimation of best-fit parameter values). Intended for extracting kinetic constants and maximum methane potential from biochemical methane potential (BMP) test measurements.
A list with parameter estimates and additional information.
Most useful elements are coefs
and coef.tab
(best-fit parameter values), summ
(a summary that includes model efficiency, error, and convergence information), and pred
(model predicted or fitted values).
Sasha D. Hafner
Hafner, S.D., Koch, K., Carrere, H., Astals, S., Weinrich, S., Rennuit, C. 2018. Software for biogas research: Tools for measurement and prediction of methane production. SoftwareX 7 205-210. doi:10.1016/j.softx.2018.06.005
# First use example data to generate a specific methane potential (SMP) curve library(biogas) data('feedVol') data('feedSetup') # Cumulative biogas and CH4 production cbg <- calcBgVol(feedVol, comp = 1, temp = 0, pres = 1, interval = FALSE, data.struct = 'wide', id.name = 'id', time.name = 'time.d', vol.name = '1', dry = TRUE) # Get SMP SMP <- summBg(vol = cbg, setup = feedSetup, time.name = 'time.d', inoc.name = 'BK', inoc.m.name = 'm.inoc', when = 'meas', norm.name = 'm.sub.vs', show.obs = TRUE) # Select bottle 9 s9 <- subset(SMP, id == 9) # Fit model mod1 <- fitFOM(s9, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4') # View summary mod1$summ # Add model predictions s9$cvCH4.pred <- mod1$pred # And plot plot(cvCH4 ~ time.d, data = s9, type = 'o') lines(cvCH4.pred ~ time.d, data = s9, col = 'red') # Fit to rates instead mod1b <- fitFOM(s9, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4', fit.to = 'rate') mod1b$summ # Try 2 pools mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4') mod2$summ # First pool effectively ignored in the fit # Try different method (this one required minpack.lm package) ## Not run: mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', method = 'LM') mod2$summ ## End(Not run) # Unfortunately, here is a big effect of method on the result! s9$cvCH4.pred2 <- mod2$pred plot(cvCH4 ~ time.d, data = s9, type = 'o') lines(cvCH4.pred ~ time.d, data = s9, col = 'red') lines(cvCH4.pred2 ~ time.d, data = s9, col = 'blue') # Drop (exclude) lag phase mod3 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', lag.phase = TRUE) mod3$summ s9$cvCH4.pred3 <- mod3$pred lines(cvCH4.pred3 ~ time.d, data = s9, col = 'darkgreen')
# First use example data to generate a specific methane potential (SMP) curve library(biogas) data('feedVol') data('feedSetup') # Cumulative biogas and CH4 production cbg <- calcBgVol(feedVol, comp = 1, temp = 0, pres = 1, interval = FALSE, data.struct = 'wide', id.name = 'id', time.name = 'time.d', vol.name = '1', dry = TRUE) # Get SMP SMP <- summBg(vol = cbg, setup = feedSetup, time.name = 'time.d', inoc.name = 'BK', inoc.m.name = 'm.inoc', when = 'meas', norm.name = 'm.sub.vs', show.obs = TRUE) # Select bottle 9 s9 <- subset(SMP, id == 9) # Fit model mod1 <- fitFOM(s9, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4') # View summary mod1$summ # Add model predictions s9$cvCH4.pred <- mod1$pred # And plot plot(cvCH4 ~ time.d, data = s9, type = 'o') lines(cvCH4.pred ~ time.d, data = s9, col = 'red') # Fit to rates instead mod1b <- fitFOM(s9, n.pool = 1, time.name = 'time.d', resp.name = 'cvCH4', fit.to = 'rate') mod1b$summ # Try 2 pools mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4') mod2$summ # First pool effectively ignored in the fit # Try different method (this one required minpack.lm package) ## Not run: mod2 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', method = 'LM') mod2$summ ## End(Not run) # Unfortunately, here is a big effect of method on the result! s9$cvCH4.pred2 <- mod2$pred plot(cvCH4 ~ time.d, data = s9, type = 'o') lines(cvCH4.pred ~ time.d, data = s9, col = 'red') lines(cvCH4.pred2 ~ time.d, data = s9, col = 'blue') # Drop (exclude) lag phase mod3 <- fitFOM(s9, n.pool = 2, time.name = 'time.d', resp.name = 'cvCH4', lag.phase = TRUE) mod3$summ s9$cvCH4.pred3 <- mod3$pred lines(cvCH4.pred3 ~ time.d, data = s9, col = 'darkgreen')
interp
interpolates (or extrapolates) biogas composition (methane concentration) or cumulative production data to a wanted time using one of several possible methods.
interp(times, y, time.out, method = "linear", extrap = FALSE)
interp(times, y, time.out, method = "linear", extrap = FALSE)
times |
measurement times.
Numeric vector or |
y |
response variable at |
time.out |
time or times at which interpolated values are needed.
Numeric vector or |
method |
method used for interpolation.
Default is |
extrap |
should |
interp
is really a wrapper for the interpolation functions approx
and spline
.
For cumulative production, which (usually) must monotonically increase, method = "hyman"
is the best choice.
Extrapolation behavior depends on method
.
For method = "linear"
, extrap = TRUE
simply returns the value of the closest y
.
For manometric measurement with mix of venting/no venting with composition measurements only when venting use method = "f1"
.
See approx
and spline
for more information.
Interpolated estimates of y
at given times
.
Sasha D. Hafner and Charlotte Rennuit
# Fake composition data dat <- data.frame(time = c(1, 7, 14, 28), xCH4 = c(0.3, 0.5, 0.61, 0.65)) interp(dat$time, dat$xCH4, time.out = 10) interp(dat$time, dat$xCH4, time.out = 10, method = "natural") interp(dat$time, dat$xCH4, time.out = c(10, 30)) interp(dat$time, dat$xCH4, time.out = c(10, 30), method = "natural") interp(dat$time, dat$xCH4, time.out = c(10, 30), extrap = TRUE) # Actual data data(comp) # Work with one reactor bgc <- subset(comp, id=="2_1") # With numeric time, interpolate to 1, 7, and 30 days interp(bgc$days, bgc$xCH4, time.out = c(1, 7, 30)) # If extrapolation is OK interp(bgc$days, bgc$xCH4, time.out = c(1, 7, 30), extrap = TRUE) # Or POSIXct interp(bgc$date.time, bgc$xCH4, time.out = as.POSIXct("2014-07-12 13:00:00")) # For cumulative gas production data(vol) # Work with one reactor bgv <- subset(vol, id=="2_1") # Calculate cumulative volume bgv <- cumBg(bgv, time.name = "days") # The interpolate of cumulative production to 1, 7, and 30 days interp(bgv$days, bgv$cvBg, time.out = c(1, 7, 30), method = "hyman")
# Fake composition data dat <- data.frame(time = c(1, 7, 14, 28), xCH4 = c(0.3, 0.5, 0.61, 0.65)) interp(dat$time, dat$xCH4, time.out = 10) interp(dat$time, dat$xCH4, time.out = 10, method = "natural") interp(dat$time, dat$xCH4, time.out = c(10, 30)) interp(dat$time, dat$xCH4, time.out = c(10, 30), method = "natural") interp(dat$time, dat$xCH4, time.out = c(10, 30), extrap = TRUE) # Actual data data(comp) # Work with one reactor bgc <- subset(comp, id=="2_1") # With numeric time, interpolate to 1, 7, and 30 days interp(bgc$days, bgc$xCH4, time.out = c(1, 7, 30)) # If extrapolation is OK interp(bgc$days, bgc$xCH4, time.out = c(1, 7, 30), extrap = TRUE) # Or POSIXct interp(bgc$date.time, bgc$xCH4, time.out = as.POSIXct("2014-07-12 13:00:00")) # For cumulative gas production data(vol) # Work with one reactor bgv <- subset(vol, id=="2_1") # Calculate cumulative volume bgv <- cumBg(bgv, time.name = "days") # The interpolate of cumulative production to 1, 7, and 30 days interp(bgv$days, bgv$cvBg, time.out = c(1, 7, 30), method = "hyman")
Mass measurements for 9 batch anaerobic reactors.
data("mass")
data("mass")
A data frame with 18 observations on the following 4 variables.
id
identification code, a unique value for each reactor in the dataset. A factor with levels 2_1
, 2_2
, 2_3
, 2_4
, 2_5
, 2_6
, 2_10
, 2_11
, and 2_12
date.time
date and time of mass measurement, a POSIXct object.
days
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
mass
total reactor mass in g, a numeric vector.
when
when was measurement taken? A character vector with two values.
These data are meant to be example data for mass2vol
, for gravimetric determination of biogas production.
Reactors were 500 mL glass serum bottles with butyl rubber septa and screw caps.
Masses were measured with an electronic balance to 100 mg.
Data in vol
, mass
, massw
, comp
, and setup
are from the same reactors.
Measurements by Charlotte Rennuit and Sasha Hafner.
data(mass)
data(mass)
mass2vol
calculates biogas volume based on measured reactor mass loss.
mass2vol(mass, xCH4, xCO2 = 1 - xCH4 - xN2, xN2 = 0, temp, pres, 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'), value = "CH4", headspace = NULL, headcomp = 'N2', temp.init = NULL, std.message = TRUE)
mass2vol(mass, xCH4, xCO2 = 1 - xCH4 - xN2, xN2 = 0, temp, pres, 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'), value = "CH4", headspace = NULL, headcomp = 'N2', temp.init = NULL, std.message = TRUE)
mass |
reactor mass loss in g. A numeric vector. |
xCH4 |
biogas mole fraction of methane, considering CH4, CO2, and N2 content. A numeric vector. |
xCO2 |
biogas mole fraction of carbon dioxide, considering CH4, CO2, and N2 content. A numeric vector. |
xN2 |
biogas mole fraction of dinitrogen, considering CH4, CO2, and N2 content. A numeric vector. |
temp |
the temperature of biogas as it exited the reactor. A length-one numeric vector.
Degrees Celcius by default (see |
pres |
the pressure of biogas as it exited the reactor. A length-one numeric vector.
Atmospheres (atm) by default (see |
temp.std |
standard temperature for presentation of biogas and methane results.
Default value is 0 degrees C.
Argument is passed to |
pres.std |
standard pressure for presentation of biogas and methane results.
Default value is 1.0 atm.
Argument is passed to |
unit.temp |
temperature units for |
unit.pres |
pressure units for |
value |
what should be returned?
Default is |
headspace |
(optional) reactor headspace volume in mL. Used to correct for effect of initial reactor headspace on mass loss. A numeric vector. |
headcomp |
(optional) composition of the initial reactor headspace.
Only required if |
temp.init |
(optional) initial headspace temperature in unit.temp units. Used to correct for effect of initial reactor headspace on mass loss. |
std.message |
should a message with the standard conditions be displayed? Default is TRUE. |
This function uses the method described in Hafner et al. (2015) to calculate biogas production from reactor mass loss.
It is essential that the only change in reactor mass is due to biogas removal!
Users are advised to read the original reference before applying the method.
This function is vectorized.
Instead of using this function directly when working with multiple measurements on multiple reactors, use the cumBg
function (which can call up mass2vol
).
Standard values and units of temperature and pressure can be globally set using the function options
.
volume of methane in mL as a numeric vector (if value = "CH4"
) or a matrix with columns for biogas, methane, and carbon dioxide volumes in mL.
vBg |
standardised volume of biogas in mL |
vCH4 |
standardised volume of methane in mL |
vCH4 |
standardised volume of carbon dioxyde in mL |
All volumes are standardised using pres.std
and temp.std
arguments (see stdVol
).
Sasha D. Hafner and Charlotte Rennuit
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.
vol2mass
,
stdVol
,
cumBg
,
options
# Volume of methane if measured mass loss was 3.1 g mass2vol(3.1, xCH4 = 0.65, temp = 35, pres = 1) # More details mass2vol(3.1, xCH4 = 0.65, temp = 35, pres = 1, value = "all") # Vectorized data("massw") massw$massloss <- massw$start - massw$end massw$vCH4 <- mass2vol(massw$massloss, xCH4 = 0.65, temp = 35, pres = 1) massw
# Volume of methane if measured mass loss was 3.1 g mass2vol(3.1, xCH4 = 0.65, temp = 35, pres = 1) # More details mass2vol(3.1, xCH4 = 0.65, temp = 35, pres = 1, value = "all") # Vectorized data("massw") massw$massloss <- massw$start - massw$end massw$vCH4 <- mass2vol(massw$massloss, xCH4 = 0.65, temp = 35, pres = 1) massw
Mass measurements for 9 batch anaerobic reactors in a “wide” format (separate columns for initial and final mass).
data("massw")
data("massw")
A data frame with 9 observations on the following 3 variables.
id
identification code, a unique value for each reactor in the dataset. A factor with levels 2_1
, 2_2
, 2_3
, 2_4
, 2_5
, 2_6
, 2_10
, 2_11
, and 2_12
start
total reactor mass at the start of its incubation in g, a numeric vector.
end
total reactor mass at the end of its incubation in g, a numeric vector.
These data are meant to be example data for application of mass2vol
, for gravimetric determination of biogas production.
Reactors were 500 mL glass serum bottles with butyl rubber septa and screw caps.
Masses were measured with an electronic balance to 100 mg.
These are the same data as in mass
, but simply in a “wide” format.
Data in vol
, mass
, massw
, comp
, and setup
are from the same reactors.
Measurements by Charlotte Rennuit and Sasha Hafner.
data(massw)
data(massw)
molMass
calculates the molar mass of any organic compound (and some salts) based on its chemical formula.
molMass(form)
molMass(form)
form |
a chemical formula, as a character vector, e.g., |
Standard atomic weights are from CIAAW, and were rounded to three or more digits (with the exception of Li) depending on the range of the reported interval for “normal materials”.
In general form
should follow capitalization rules for elements (i.e., first letter capitalized, second lower-case).
However, if form
contains single-letter elements only, it is possible to use lower-case letters for all elements (but for clarity this is not recommended).
The function is vectorized.
Numeric vector with length equal to length of form
with molar mass (g/mol)
Charlotte Rennuit and Sasha D. Hafner
CIAAW <http://www.ciaaw.org/atomic-weights.htm>
molMass("C6H12O6") molMass("CH3COOH") molMass("CH3CH2OH") molMass("CH4") molMass("ch4") molMass(c("C6H12O6", "CH3COOH", "CH3CH2OH")) # Case-sentitive for two letter elements molMass("NaHCO3") # Complex formulas OK molMass("H3C(CH2)5COOH") molMass("(C6H12O6)0.24999 (H3COOH)0.75001") # Database is quite complete molMass('CdSiO3') # Use care for, e.g., hydrates molMass('FeSO4(H2O)7')
molMass("C6H12O6") molMass("CH3COOH") molMass("CH3CH2OH") molMass("CH4") molMass("ch4") molMass(c("C6H12O6", "CH3COOH", "CH3CH2OH")) # Case-sentitive for two letter elements molMass("NaHCO3") # Complex formulas OK molMass("H3C(CH2)5COOH") molMass("(C6H12O6)0.24999 (H3COOH)0.75001") # Database is quite complete molMass('CdSiO3') # Use care for, e.g., hydrates molMass('FeSO4(H2O)7')
planBMP
assists in the design of BMP experiments.
It can be used to determine inoculum and substrate masses based on inoculum-to-substrate ratio and volatile solids concentrations, or to calculate inoculum-to-substrate ratio based on masses.
planBMP(vs.inoc, vs.sub, isr = NA, m.inoc = NA, m.sub = NA, m.tot = m.inoc + m.sub, m.vs.sub = vs.sub*m.sub/1000, digits = 3, warn = TRUE, nice = TRUE)
planBMP(vs.inoc, vs.sub, isr = NA, m.inoc = NA, m.sub = NA, m.tot = m.inoc + m.sub, m.vs.sub = vs.sub*m.sub/1000, digits = 3, warn = TRUE, nice = TRUE)
vs.inoc |
volatile solids (VS) concentration of inoculum (g/kg = g VS per kg inoculum). Required. Numeric vector. |
vs.sub |
volatile solids (VS) concentration of substrate (g/kg = g VS per kg substrate). Required. Numeric vector. |
isr |
inoculum-to-substrate ratio, VS mass basis. Optional. Numeric vector. |
m.inoc |
total mass of inoculum (g). Optional. Numeric vector. |
m.sub |
total mass of substrate (g). Optional. Numeric vector. |
m.tot |
total mass of mixture (inoculum plus substrate) (g). Optional. Numeric vector. |
m.vs.sub |
VS mass of substrate (g). Optional. Numeric vector. |
digits |
number of significant digits to display in output. Default of 3. Integer vector with length 1. |
warn |
control whether warnings are displayed. Default of TRUE. Logical vector with length 1. |
nice |
control whether output is formatted to look nice and make reading easier. Default of TRUE. Only applied for non-vectorized (length 1) calls. Logical vector with length 1. |
BMP experiments should be designed giving consideration to the inoculum-to-substrate ratio (ISR), the substrate VS mass, and the mixture VS concentration. This function calculates inoculum and substrate masses based on VS concentrations and ISR, along with either total mixture mass or substrate VS mass. Alternatively, it can be used to calculate ISR if the masses have been selected. Warnings are based on the guidelines of Holliger et al. (2016).
A named numeric vector, or (if any of the first 7 input arguments have a length > 1, i.e., a vectorized call), a data frame. Names and interpretation are identical to the first 7 input arguments, and also include:
vs.mix |
VS concentration in mixture (g/kg) |
m.vs.tot |
total VS mass in mixture (g) |
For non-vectorized calls, the results are returned invisibly and a easy-to-read summary is printed (see nice
argument).
Calculations used in this function are trivial, and they could also be done with a spreadsheet or even pencil and paper. The advantage here is ease and some flexibility. In addition to ISR and the other parameters included in this function, expected biogas production rate and bottle headspace volume are important, depending on the method. For more details, see Holliger et al. (2016).
Sasha D. Hafner, based on suggestion by Konrad Koch
Holliger, C., Alves, M., Andrade, D., Angelidaki, I., Astals, S., Baier, U., Bougrier, C., Buffiere, P., Carbella, M., de Wilde, V., Ebertseder, F., Fernandez, B., Ficara, E., Fotidis, I., Frigon, J.-C., Fruteau de Laclos, H., S. M. Ghasimi, D., Hack, G., Hartel, M., Heerenklage, J., Sarvari Horvath, I., Jenicek, P., Koch, K., Krautwald, J., Lizasoain, J., Liu, J., Mosberger, L., Nistor, M., Oechsner, H., Oliveira, J.V., Paterson, M., Pauss, A., Pommier, S., Porqueddu, I., Raposo, F., Ribeiro, T., Rusch Pfund, F., Stromberg, S., Torrijos, M., van Eekert, M., van Lier, J., Wedwitschka, H., Wierinck, I., 2016. Towards a standardization of biomethane potential tests. Water Science and Technology 74, 2515-2522.
calcBgVol
,
calcBgMan
,
calcBgGD
,
cumBg
,
summBg
,
predBg
# Bottles are 500 mL, substrate is wastewater sludge. # Assume we want no more than 250 mL reacting volume (~250 g) # First try setting ISR and total mass. # VS concentrations: 20 g/kg in inoculum, 70 g/kg for substrate, ISR = 2. planBMP(vs.inoc = 20, vs.sub = 70, isr = 2, m.tot = 250) # Get 31 g substrate, 220 g inoculum. # After setup, we can check final values. planBMP(vs.inoc = 18, vs.sub = 72, m.sub = 32, m.inoc = 218) # We didn't quite meet our target in this case--next time use more inoculum to be sure # We can alternatively specify substrate VS mass planBMP(vs.inoc = 20, vs.sub = 70, isr = 2, m.vs.sub = 2) # Some options planBMP(vs.inoc = 20, vs.sub = 70, isr = 2, m.vs.sub = 2, nice = FALSE) # Perhaps we want to use three different ISRs planBMP(vs.inoc = 20, vs.sub = 70, isr = 2:4, m.vs.sub = 2, nice = FALSE)
# Bottles are 500 mL, substrate is wastewater sludge. # Assume we want no more than 250 mL reacting volume (~250 g) # First try setting ISR and total mass. # VS concentrations: 20 g/kg in inoculum, 70 g/kg for substrate, ISR = 2. planBMP(vs.inoc = 20, vs.sub = 70, isr = 2, m.tot = 250) # Get 31 g substrate, 220 g inoculum. # After setup, we can check final values. planBMP(vs.inoc = 18, vs.sub = 72, m.sub = 32, m.inoc = 218) # We didn't quite meet our target in this case--next time use more inoculum to be sure # We can alternatively specify substrate VS mass planBMP(vs.inoc = 20, vs.sub = 70, isr = 2, m.vs.sub = 2) # Some options planBMP(vs.inoc = 20, vs.sub = 70, isr = 2, m.vs.sub = 2, nice = FALSE) # Perhaps we want to use three different ISRs planBMP(vs.inoc = 20, vs.sub = 70, isr = 2:4, m.vs.sub = 2, nice = FALSE)
predBg
predicts biogas and methane production based on composition and other, optional, details.
predBg(form = NULL, mass = 1, mol = NULL, fs = 0, fd = 1, mcomp = NULL, COD = NULL, conc.sub = NULL, pH = NULL, temp = NULL, mu = 0.1, shortform = NULL, value = "CH4")
predBg(form = NULL, mass = 1, mol = NULL, fs = 0, fd = 1, mcomp = NULL, COD = NULL, conc.sub = NULL, pH = NULL, temp = NULL, mu = 0.1, shortform = NULL, value = "CH4")
form |
(optional) a chemical formula for the substrate, as a character vector of length one, e.g., |
mass |
mass of substrate present, in g. A numeric vector. |
mol |
(optional) moles of substrate present. A numeric vector. |
fs |
fraction of substrate used for microbial biomass production ( |
fd |
fraction of substrate that is degradable ( |
mcomp |
(optional) “macromolecule”-based composition of the substrate.
A named numeric vector with relative masses of macromolecular groups or any chemical.
Options for macromolecular groups include: |
COD |
(optional) chemical oxygen demand (COD) of the substrate (g oxygen).
If provided, |
conc.sub |
(optional) concentration of the substrate relative to water, as g substrate per kg water. Used only for carbon dioxide partitioning. A numeric vector. |
pH |
(optional) pH of the solution. Used only for carbon dioxide partitioning. A numeric vector. |
temp |
(optional) temperature of the system in degrees C. Used only for carbon dioxide partitioning. A numeric vector. |
mu |
(optional) ionic strength of the solution. Used only for carbon dioxide partitioning. A numeric vector. |
shortform |
should formula from |
value |
what should be returned?
Four options are currently available.
|
predBg
is a flexible function that returns different details depending on the data provided.
Calculations can be based on form
, COD
, or mcomp
(at least one of these is required).
See ‘Examples’ for more information.
In its simplest usage, predBg
calculates theoretical biochemical methane potential (theoretical BMP).
With more parameters, it can also predict carbon dioxide partitioning, total biogas production and composition, as well as microbial biomass production and nitrogen requirement.
Stoichiometry is based on Eq. 13.5 in Rittmann and McCarty (2001).
Partitioning of carbon dioxide is based on an equilibrium speciation model using temperature-dependent parameters (Henry's law constant and dissociation constants) based on Hafner et al. (2012).
predBg
is vectorized for all arguments except mcomp
, and will recycle argument elements as needed.
Standardised volume (at 0 degrees C and 1 atmosphere) of methane produced in mL (for value = "CH4"
), or a data frame with some of these columns (depending on provided arguments):
form |
empirical chemical formula of substrate, typically from the input argument |
mass |
substrate mass in g, typically from the input argument |
mol.mass |
substrate molar mass in g/mol |
moles |
moles of subtrate |
COD |
total calculated oxygen demand (COD') based on |
fs |
|
fe |
Rittmann and McCarty's fe ( |
fd |
|
conc.sub |
|
temp |
|
pH |
|
hydro |
hydrolytic water consumption (g water) |
fCH4 |
moles methane producted divided by the sum of methane and carbon dioxide moles. Equal to |
xCH4 |
mole fraction of methane in dry biogas |
vCH4 |
standardised volume (dry, 0 degrees C, 1.0 atm) of methane produced in mL |
mCH4 |
mass of methane produced in g |
mCO2 |
mass of carbon dioxide produced in g (including both biogas and inorganic carbon in solution) |
mCO2Bg |
mass of carbon dioxide in biogas in g |
mCO2.sol |
mass of inorganic carbon in solution in g |
cTIC |
concentration of inorganic carbon in solution in mol/kg (per kg water) |
m.bio |
mass of microbial biomass produced, VS only, in g |
N.req |
nitrogen required for production of required microbial biomass in g of N. Negative value indicates mineralization |
Predictions will only be as good as the parameter values provided, and maybe not even that good.
fs
should be interpreted as $f_s$ in Ritttmann and McCarty (2001), i.e., the effective value after decay of microbial biomass, and not $f_s^0$.
The original reference (Section 2.3 and Eq. (3.33) in Rittmann and McCarty (2001)) and the predBg
vignette provide more details.
Partitioning of carbon dioxide is based on equilibrium between all biogas produced and the solution, and represents a continuous reactor running at steady-state.
Sasha D. Hafner and Charlotte Rennuit
Hafner, S.D. 2007 Ammonia Speciation in Anaerobic Digesters. PhD dissertation, Cornell University.
Hafner, S.D., Montes, F., Rotz, C.A. 2012 The role of carbon dioxide in emission of ammonia from manure. Atmospheric Environment 66, 63-71.
Moller, H.B., Sommer, S.G., Ahring, B.K. 2004 Methane productivity of manure, straw and solid fractions of manure. Biomass and Bioenergy 26, 485-495.
Rittmann, B., McCarty, P. 2001 Environmental Biotechnology. McGraw-Hill.
Triolo, J.M., Sommer, S.G., Moller, H.B., Weisbjerg, M.R., Jiang, X.Y. 2011 A new algorithm to characterize biodegradability of biomass during anaerobic digestion: Influence of lignin concentration on methane production potential. Bioresource Technology 102, 9395-9402.
# BMP of cellulose in mL CH4/g predBg("C6H10O5") # How much is produced in a real reactor? Assume 10% goes to # biomass production predBg("C6H10O5", fs = 0.1) # And substrate is 80% degradable predBg("C6H10O5", fs = 0.1, fd = 0.8) # More detailed results predBg("C6H10O5", value = "all") # Given a substrate with a COD of 1.4 g predBg(COD = 1.4) # But CH4 production is reduced if substrate is 80% degradable # and 10% goes to cell synthesis predBg(COD = 1.4, fd = 0.8, fs = 0.1) # Can use macromolecule composition, e.g., for pig manure predBg(mcomp = c(vfa = 0.2, protein = 0.25, carbohydrate = 0.32, lipid = 0.15, lignin = 0.08), value = "all") # Function expects sum(mcomp) == 1 but this is not required # But unless mass is set, mass is taken as sum(mcomp) predBg(mcomp = c(vfa = 20, protein = 25, carbohydrate = 32, lipid = 15, lignin = 8), value = "all") # Specify mass if this is not the case predBg(mcomp = c(vfa = 20, protein = 25, carbohydrate = 32, lipid = 15, lignin = 8), mass = 1, value = "all") # Can mix formulas and macromolecular groups in mcomp predBg(mcomp = c(C6H12O6 = 0.5, protein = 0.5)) # For CO2 partitioning, must provide conc.sub, pH, and temp # cattle manure example from Hafner (2007) predBg("C13H20O11N", mass = 1, fs = 0.1, fd = 0.56, conc.sub = 85, pH = 7.7, temp = 35, value = "all") # Or, mix of waste paper and waste vegetable oil from vignette predBg(mcomp = c(C6H10O5 = 5/6, C54H100O7 = 1/6), mass = 1, fd = 0.8, fs = 0.1, conc.sub = 50, pH = 7.5, temp = 35, value = "all") # Note that form can also be used for mixtures, but here it is # molar ratios that are specified predBg('(C6H10O5)5(C54H100O7)1)', mass = 1, fd = 0.8, fs = 0.1, conc.sub = 50, pH = 7.5, temp = 35, value = "all") # Function is vectorized for everything except mcomp, e.g., # fs predBg("C6H10O5", fs = c(0, 0.05, 0.1), value = "all") # form predBg(c("C6H10O5", "C10H19O3N", "CH3CH2OH"), value = "all") # pH predBg("C13H20O11N", conc.sub = 85, fs = 0.1, fd = 0.56, pH = 7+0:10/10, temp = 35, value = "all")
# BMP of cellulose in mL CH4/g predBg("C6H10O5") # How much is produced in a real reactor? Assume 10% goes to # biomass production predBg("C6H10O5", fs = 0.1) # And substrate is 80% degradable predBg("C6H10O5", fs = 0.1, fd = 0.8) # More detailed results predBg("C6H10O5", value = "all") # Given a substrate with a COD of 1.4 g predBg(COD = 1.4) # But CH4 production is reduced if substrate is 80% degradable # and 10% goes to cell synthesis predBg(COD = 1.4, fd = 0.8, fs = 0.1) # Can use macromolecule composition, e.g., for pig manure predBg(mcomp = c(vfa = 0.2, protein = 0.25, carbohydrate = 0.32, lipid = 0.15, lignin = 0.08), value = "all") # Function expects sum(mcomp) == 1 but this is not required # But unless mass is set, mass is taken as sum(mcomp) predBg(mcomp = c(vfa = 20, protein = 25, carbohydrate = 32, lipid = 15, lignin = 8), value = "all") # Specify mass if this is not the case predBg(mcomp = c(vfa = 20, protein = 25, carbohydrate = 32, lipid = 15, lignin = 8), mass = 1, value = "all") # Can mix formulas and macromolecular groups in mcomp predBg(mcomp = c(C6H12O6 = 0.5, protein = 0.5)) # For CO2 partitioning, must provide conc.sub, pH, and temp # cattle manure example from Hafner (2007) predBg("C13H20O11N", mass = 1, fs = 0.1, fd = 0.56, conc.sub = 85, pH = 7.7, temp = 35, value = "all") # Or, mix of waste paper and waste vegetable oil from vignette predBg(mcomp = c(C6H10O5 = 5/6, C54H100O7 = 1/6), mass = 1, fd = 0.8, fs = 0.1, conc.sub = 50, pH = 7.5, temp = 35, value = "all") # Note that form can also be used for mixtures, but here it is # molar ratios that are specified predBg('(C6H10O5)5(C54H100O7)1)', mass = 1, fd = 0.8, fs = 0.1, conc.sub = 50, pH = 7.5, temp = 35, value = "all") # Function is vectorized for everything except mcomp, e.g., # fs predBg("C6H10O5", fs = c(0, 0.05, 0.1), value = "all") # form predBg(c("C6H10O5", "C10H19O3N", "CH3CH2OH"), value = "all") # pH predBg("C13H20O11N", conc.sub = 85, fs = 0.1, fd = 0.56, pH = 7+0:10/10, temp = 35, value = "all")
Methane content (biogas composition) measurements from three batch bottles, organized in a “long” format.
data("s3compl")
data("s3compl")
A data frame with 14 observations on the following 3 variables:
id
identification code, a unique value for each bottle in the dataset.
time.d
elapsed time of mass measurements (from bottle setup) in days, a numeric vector.
xCH4
biogas methane content as a mole fraction, excluding water and all other gases other than carbon dioxide, a numeric vector
These data are meant to be example data for cumBg
.
Reactors were 300 mL glass serum bottles with butyl rubber septa and screw caps.
Substrate was municipal wastewater sludge.
Methane and carbon dioxide contents were determined by gas chromatography using a thermal conductivity detector and normalised so methane and carbon dioxide sum to 1.0.
Data in s3voll
, s3compl
, s3volw
, s3compw
, and s3lcombo
are from the same bottles.
Sasha D. Hafner. Measurements by Johanna Maria Pedersen.
data(s3compl)
data(s3compl)
Methane content (biogas composition) measurements from three batch bottles, organized in a “wide” format.
data("vol")
data("vol")
A data frame with 5 observations on the following 4 variables:
time.d
elapsed time of mass measurements (from bottle setup) in days, a numeric vector.
D
biogas methane content at time
from bottle “D” as mole fraction, a numeric vector.
E
biogas methane content at time
from bottle “E” as mole fraction, a numeric vector.
F
biogas methane content at time
from bottle “F” as mole fraction, a numeric vector.
These data are meant to be example data for cumBg
.
Reactors were 300 mL glass serum bottles with butyl rubber septa and screw caps.
Substrate was municipal wastewater sludge.
Methane and carbon dioxide contents were determined by gas chromatography using a thermal conductivity detector and normalised so methane and carbon dioxide sum to 1.0.
Data in s3voll
, s3compl
, s3volw
, s3compw
, and s3lcombo
are from the same bottles.
Sasha D. Hafner. Measurements by Johanna Maria Pedersen.
data(s3compw)
data(s3compw)
Biogas volume and methane content measurements from three batch bottles, organized in a “long” format.
data("s3lcombo")
data("s3lcombo")
A data frame with 21 observations on the following 4 variables:
id
identification code, a unique value for each bottle in the dataset.
time.d
elapsed time of mass measurements (from bottle setup) in days, a numeric vector.
vol.ml
volume of biogas removed at time
in mL, a numeric vector.
xCH4
biogas methane content as a mole fraction, excluding water and all other gases other than carbon dioxide, a numeric vector
These data are meant to be example data for cumBg
.
Reactors were 300 mL glass serum bottles with butyl rubber septa and screw caps.
Substrate was municipal wastewater sludge.
Volume was measured using syringes.
Methane and carbon dioxide contents were determined by gas chromatography using a thermal conductivity detector and normalised so methane and carbon dioxide sum to 1.0.
Data in s3voll
, s3compl
, s3volw
, s3compw
, and s3lcombo
are from the same bottles.
Sasha D. Hafner. Measurements by Johanna Maria Pedersen.
data(s3lcombo)
data(s3lcombo)
Biogas volume measurements from three batch bottles, organized in a “long” format.
data("s3voll")
data("s3voll")
A data frame with 21 observations on the following 4 variables:
id
identification code, a unique value for each bottle in the dataset.
time.d
elapsed time of mass measurements (from bottle setup) in days, a numeric vector.
vol.ml
volume of biogas removed at time
in mL, a numeric vector.
cvol.ml
cumulative sum of vol
.
These data are meant to be example data for cumBg
.
Reactors were 300 mL glass serum bottles with butyl rubber septa and screw caps.
Substrate was municipal wastewater sludge.
Volume was measured using syringes.
Data in s3voll
, s3compl
, s3volw
, s3compw
, and s3lcombo
are from the same bottles.
Sasha D. Hafner. Measurements by Johanna Maria Pedersen.
data(s3voll)
data(s3voll)
Biogas volume measurements from three batch bottles, organized in a “wide” format.
data("vol")
data("vol")
A data frame with 7 observations on the following 5 variables:
time.d
elapsed time of mass measurements (from bottle setup) in days, a numeric vector.
D
volume of biogas removed at time
from bottle “D” in mL, a numeric vector.
E
volume of biogas removed at time
from bottle “E” in mL, a numeric vector.
F
volume of biogas removed at time
from bottle “F” in mL, a numeric vector.
These data are meant to be example data for cumBg
.
Reactors were 300 mL glass serum bottles with butyl rubber septa and screw caps.
Volume was measured using syringes.
Data in s3voll
, s3compl
, s3volw
, s3compw
, and s3lcombo
are from the same bottles.
Sasha D. Hafner. Measurements by Johanna Maria Pedersen.
data(vol)
data(vol)
Description of reactor substrates and information on reactor, substrates and, inoculum initial masses for twelve anaerobic reactors.
data("setup")
data("setup")
A data frame with 12 observations on the following 11 variables:
id
identification code, a unique value for each reactor in the dataset. A factor with levels 2_1
, 2_2
, 2_3
, 2_4
, 2_5
, 2_6
, 2_7
, 2_8
, 2_9
, 2_10
, 2_11
, and 2_12
descrip
description of substrate, a factor with levels A
B
inoc
.
msub
mass of substrate added to the reactor at the start in g, a numeric vector.
minoc
mass of inoculum added to the reactor at the start in g, a numeric vector.
mvs.sub
mass of volatile solids (VS) of substrate added to the reactor at the start in g, a numeric vector.
mvs.inoc
mass of volatile solids (VS) of inoculum added to the reactor at the start in g, a numeric vector.
mcod.sub
mass of chemical oxygen demand (COD) of substrate added to the reactor at the start in g oxygen, a numeric vector.
mcod.inoc
mass of chemical oxygen demand (COD) of inoculum added to the reactor at the start in g oxygen, a numeric vector.
m.tot
total mass added to the reactor at the start in g, a numeric vector.
mvs.tot
total mass of VS in the reactor at the start in g, a numeric vector.
mcod.tot
total mass of COD in the reactor at the start in g oxygen, a numeric vector.
These data are meant to be example data for summBg
.
Reactors were 500 mL glass serum bottles with butyl rubber septa and screw caps.
Data in vol
, mass
, massw
, comp
, and setup
are from the same reactors.
Measurements made by Charlotte Rennuit and Ali Heidarzadeh Vazifehkhoran
data(setup)
data(setup)
Information on reactor substrates and substrate and inoculum masses for 15 anaerobic reactors.
data("setup2")
data("setup2")
A data frame with 15 observations on the following 4 variables:
bottle
identification code, a unique value for each reactor in the dataset. A factor with levels 1_1
, 1_2
, 1_3
, 2_1
, 2_2
, 2_2
, ... through 5_3
. The first number indicates the sample, the second the replicate.
description
description of substrate, a factor.
sub.vs
mass of substrate volatile solids (VS) added to the reactor at the start in g, a numeric vector
inoc.mass
mass of inoculum added to the reactor at the start in g, a numeric vector.
These data are meant to be example data for summBg
.
Reactors were 500 mL or 1000 mL glass serum bottles with butyl rubber septa and screw caps.
Data in vol2
, xCH42
, and setup2
are from the same reactors.
Measurements made by Ali Heidarzadeh Vazifehkhoran
data(setup2)
data(setup2)
Interval-based measurements of headspace pressure, mass, and methane and carbondioxide content from anaerobic batch bottles, organized in a “longcombo” format.
data("sludgeTwoBiogas")
data("sludgeTwoBiogas")
A data frame with 224 observations on the following 8 variables:
id
identification code, a unique value for each bottle in the dataset.
time.d
elapsed time of mass and pressure measurements in days, a numeric vector.
pres
bottle headspace pressure at time
in mbar (gauge), a numeric vector
mass.init
total reactor mass at the start of its incubation in g, a numeric vector.
mass.final
total reactor mass at the end of its incubation in g, a numeric vector.
xCH4
biogas methane content as a mole fraction, excluding water, a numeric vector
xCO2
biogas carbon dioxide content as a mole fraction, excluding water, a numeric vector
xCH4n
biogas methane content as a mole fraction in dry biogas, normalized so the sum of mole fractions of CH$_4$ and CO$_2$ is unity, a numeric vector.
These data are meant to be example data for cumBg
and calcBgMan
for respectively, gravimetric and manometric determination of biogas production.
BMP test were carried out in 160 mL serum bottles sealed with a butyl rubber septum retained with an aluminum crimp seal at mesophilic conditions (37 degrees C).
Substrate was primary wastewater sludge.
Cumulative methane production was measured from the same set of bottles by both manometric and gravimetric methods. BMP was evaluated at 18 days At each sampling event, headspace pressure was measured using a manometer and composition (CH4 and CO2) with a gas chromatograph). All reported pressure measurements are gauge unless stated otherwise. After each sampling event, the headspace of the serum bottles (including blanks) was vented to near atmospheric pressure.
Data in sludgeTwoBiogas
and sludgeTwoSetup
are from the same batch bottles.
Data were originally collected by Sergi Astals at the University of Queensland and are described in the following paper. Hafner, S.D., Astals, S. 2019.Systematic error in manometric measurement of biochemical methane potential: Sources and solutions. Waste Management 91, 147-155.
data(sludgeTwoBiogas)
data(sludgeTwoBiogas)
Description of reactor substrates and information on bottle, substrates, inoculum initial masses, and headspace volume for 18 anaerobic bottles with primary wastewater sludge for substrate.
data("sludgeTwoSetup")
data("sludgeTwoSetup")
A data frame with 18 observations on the following 5 variables:
id
identification code, a unique value for each bottle in the dataset. Numeric with all values within a range of 1-21.
descrip
treatment of the substrate (primary wastewater sludge), a character.
vol.hs
bottle headspace volume, in mL. A numeric vector.
m.inoc
mass of inoculum added to the bottle at the start in g, a numeric vector.
m.sub.vs
mass of volatile solids (VS) of substrate added to the reactor at the start in g, a numeric vector.
These data are meant to be example data for summBg
.
Substrate was primary wastewater sludge.
BMP test were carried out in 160 mL serum bottles sealed with a butyl rubber septum retained with an aluminum crimp seal at mesophilic conditions (37 degrees C). All bottles contained inoculum and the amount of primary sludge required to achieve an inoculum-to-substrate ratio (ISR) of 2 (VS basis). Bottles containing only inoculum (blanks) were used to correct for the background CH4 potential of the inoculum (endogenous CH4 production).
Data in sludgeTwoBiogas
and sludgeTwoSetup
are from the same batch bottles.
Data were originally collected by Sergi Astals at the University of Queensland and are described in the paper listed below. Hafner, S.D., Astals, S. 2019.Systematic error in manometric measurement of biochemical methane potential: Sources and solutions. Waste Management 91, 147-155.
data(sludgeTwoSetup)
data(sludgeTwoSetup)
stdVol
corrects gas volumes to dry conditions at a specified temperature and pressure.
stdVol(vol, temp, pres, rh = 1, 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'), std.message = TRUE, warn = TRUE)
stdVol(vol, temp, pres, rh = 1, 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'), std.message = TRUE, warn = TRUE)
vol |
measured gas volume at |
temp |
temperature of gas in degrees C by default (see |
pres |
pressure of gas in atm by default (see |
rh |
relative humidity of the gas ( |
temp.std |
"standard" temperature. Default value is 0 degrees C. |
pres.std |
"standard" pressure. Default value is 1.0 atm. |
unit.pres |
pressure units for |
unit.temp |
temperature units for |
std.message |
should a message with the standard conditions be displayed? Default is TRUE. |
warn |
if |
Standardisation is done in a two-step process following Hafner et al. (2015). First, the contribution of water vapor is removed and volume is corrected to the standard pressure:
vd = vm*(pm - rh*pw)/ps
where vd = dry volume at standard pressure ps, vm = measured volume at pressure pm, pw = saturation vapor pressure of water (all pressures in Pa), and rh = relative humidity (rh
above).
Water vapor pressure pw is calculated from the Magnus form equation given in Alduchov and Eskridge (1996) (Eqs. (21) and (22)).
In the second step, the volume is adjusted for temperature.
vs = vd*Ts/T
where vs = standardised volume and Ts = standardisation temperature (K, converted from temp.std
argument).
This approach is based on Charles's and Boyle's laws.
Comparison with calculations using the Peng-Robinson equation of state suggests that error in stdVol
is around 0.1% for typical biogas with volume measured at 25 degrees C, and higher at higher temperatures (up to 0.3% at 55 degrees C).
Standard temperature and pressure and their units can be defined by the user using the temp.std
, pres.std
, temp.unit
, and pres.unit
arguments.
Alternatively, standard values and units of temperature and pressure can be globally set using the function options
.
Default values are 0 degrees C and 1.0 atm.
stdVol
is vectorized, and if one argument has a shorter length than the others, it will be recycled.
Standardised gas volume in the same units as vol
.
A numeric vector.
Sasha D. Hafner and Charlotte Rennuit
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.
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.
cumBg
,
summBg
,
stdVol
,
options
# 100 mL, measured at 35 C stdVol(100, temp = 35, pres = 1) # Or, with different units stdVol(100, temp = 35, pres = 103, unit.pres = "kPa", pres.std = 101.325) # Vectorized data(vol) head(vol) vol$vol.std <- stdVol(vol$vol, temp = 20, pres = 1.02) head(vol) #using options() (recommended!) oldoptions <- options(temp.std = 273.15, pres.std = 101325, unit.temp = 'K', unit.pres = 'Pa') vol$vol.std <- stdVol(vol$vol, temp = 293.15, pres = 101325) head(vol) options(oldoptions)
# 100 mL, measured at 35 C stdVol(100, temp = 35, pres = 1) # Or, with different units stdVol(100, temp = 35, pres = 103, unit.pres = "kPa", pres.std = 101.325) # Vectorized data(vol) head(vol) vol$vol.std <- stdVol(vol$vol, temp = 20, pres = 1.02) head(vol) #using options() (recommended!) oldoptions <- options(temp.std = 273.15, pres.std = 101325, unit.temp = 'K', unit.pres = 'Pa') vol$vol.std <- stdVol(vol$vol, temp = 293.15, pres = 101325) head(vol) options(oldoptions)
Methane content (biogas composition) measurements from 12 anaerobic batch reactors with straw for substrate.
data("comp")
data("comp")
A data frame with 63 observations on the following 4 variables.
bottle
identification code, a unique value for each reactor in the dataset. Integer with all values from 1 to 12.
date.time
date and time of mass measurement, a POSIXct object.
time
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
xCH4
biogas methane content as a mole fraction, excluding water and all other gases other than carbon dioxide, a numeric vector
These data are meant to be example data for cumBg
.
Reactors were ca. 600 mL glass serum bottles with butyl rubber septa and screw caps.
Pressure was measured using an electronic manometer.
Data in strawMass
, strawSetup
, and strawPressure
are from the same reactors.
Measurements by Charlotte Rennuit.
data(strawComp)
data(strawComp)
Mass measurements for 12 batch anaerobic reactors with ground straw as a substrate.
data("mass")
data("mass")
A data frame with 89 observations on the following 4 variables.
bottle
identification code, a unique value for each reactor in the dataset. Integer with all values from 1 to 12.
date.time
date and time of mass measurement, a POSIXct object.
time
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
mass
total reactor mass in g, a numeric vector.
These data are meant to be example data for mass2vol
or cumBg
, for gravimetric determination of biogas production.
Reactors were ca. 600 mL glass serum bottles with butyl rubber septa and screw caps.
Masses were measured with an electronic balance to 10 mg.
Data in strawPressure
, strawSetup
, and strawComp
are from the same reactors.
Measurements by Charlotte Rennuit.
data(strawMass)
data(strawMass)
Interval-based measurements of headspace pressure in 12 anaerobic batch reactors with straw as the substrate.
data("strawPressure")
data("strawPressure")
A data frame with 72 observations on the following 5 variables:
bottle
identification code, a unique value for each reactor in the dataset. Integer with all values from 1 to 12.
date.time
date and time of mass measurement, a POSIXct object.
time
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
pres
absolute bottle headspace pressure at the stated time, in kPa. Biogas accumulated in bottles from the previous time.
pres.resid
absolute bottle headspace pressure after venting, in kPa.
These data are meant to be example data for cumBg
.
Reactors were ca. 600 mL glass serum bottles with butyl rubber septa and screw caps.
Pressure was measured using an electronic manometer.
Data in strawMass
, strawSetup
, and strawComp
are from the same reactors.
Measurements by Charlotte Rennuit.
data(vol)
data(vol)
Description of reactor substrates and information on reactor, substrates and, inoculum initial masses for 12 anaerobic reactors with straw for substrate.
data("setup")
data("setup")
A data frame with 12 observations on the following 6 variables:
bottle
identification code, a unique value for each reactor in the dataset. Integer with all values from 1 to 12.
treatment
treatment of the substrate (ground straw), a factor.
start
starting date and time, when the reactors were set up.
sub.mass
mass of substrate added to the reactor at the start in g, a numeric vector.
inoc.mass
mass of inoculum added to the reactor at the start in g, a numeric vector.
headspace
bottle headspace volume, in mL. A numeric vector.
These data are meant to be example data for summBg
.
Reactors were ca. 600 mL glass serum bottles with butyl rubber septa and screw caps.
Masses were measured with an electronic balance to 10 mg.
Data in strawPressure
, strawMass
, and strawComp
are from the same reactors.
Measurements by Charlotte Rennuit.
data(setup)
data(setup)
From cumulative gas production, use summBg
to standardise, interpolate, subtract innoculum contribution, normalise by substrate mass, and summarise the output calculating mean and standard devations for each type of sample (groups of replicates).
The function is flexible: some, all, or none of these operations can be carried out in a call.
Typically summBg
is used to calculate biochemical methane potential (BMP) from cumulative methane production.
summBg(vol, setup, id.name = "id", time.name = "time", descrip.name = "descrip", inoc.name = NULL, inoc.m.name = NULL, norm.name = NULL, norm.se.name = NULL, vol.name = "cvCH4", imethod = "linear", extrap = FALSE, when = 30, when.min = 0, rate.crit = 'net', show.obs = FALSE, show.rates = FALSE, show.more = FALSE, sort = TRUE, set.name = 'set', quiet = FALSE)
summBg(vol, setup, id.name = "id", time.name = "time", descrip.name = "descrip", inoc.name = NULL, inoc.m.name = NULL, norm.name = NULL, norm.se.name = NULL, vol.name = "cvCH4", imethod = "linear", extrap = FALSE, when = 30, when.min = 0, rate.crit = 'net', show.obs = FALSE, show.rates = FALSE, show.more = FALSE, sort = TRUE, set.name = 'set', quiet = FALSE)
vol |
a data frame with the columns bottle identification code; time of measurement (as |
setup |
a data frame containing information to summarise, substract inoculum effect or normalise the data. Should contain at least the column |
id.name |
name of the bottle identification code column in |
time.name |
name of column containing time data in |
descrip.name |
(optional) name of column containing a description of bottle substrate (or a code for this) in |
inoc.name |
(optional) the value in the |
norm.name |
(optional) the name of the column in |
norm.se.name |
(optional) the name of the column in |
inoc.m.name |
(optional) the name of the column in |
vol.name |
the name of the column(s) in |
imethod |
the interpolation method to be used.
This is passed as the |
extrap |
should extrapolation be carried out? Set to |
when |
value(s) of |
when.min |
minimum duration (value of |
rate.crit |
type of rate criterion to be applied for relative |
show.obs |
set to |
show.rates |
set to |
show.more |
set to |
sort |
controls sorting of results, which is by |
set.name |
column name in result for set of observations, corresponding to elements in |
quiet |
use to suppress messages. Default is |
summBg
was primarily designed to calculate the biochemical methane potential (BMP) from cumulative methane production of a set of batch bottles through these steps: interpolation of cumulative production to a specified time (if needed), subtratction of apparent innoculum contribution, normalisation of the results by substrate mass (typically volatile solids (VS) mass, but could be the mass of anything within the bottle) and calculation of mean and standard deviation for each sample type (set of replicates, identified by descrip.name
).
If needed summBg
can return values for all observations and be used for simpler operations e.g., determining cumulative biogas production at some specified time or normalising gas volume by different substrate characteristics.
To summarise data, the setup
data frame should have a column with a description of bottle substrate (or a code for this).
The name of the column is set by the descrip.name
argument.
If the inoculum effect is to be subtracted out, a column named descrip.name
(for identifying replicates) and a column with the mass of inoculum present (any units), with a name set by inoc.m.name
are both required in setup
.
To normalise by substrate mass (or any mass to be used for normalisation), an additional column with the mass of substrate is needed in setup
–its name is set by norm.name
.
This function is probably easier to understand by example. See ‘Examples’.
a data frame, with the colums:
descrip |
from the input data frame setup |
mean |
mean of the response variable |
sd |
standard deviation of the response variable |
se |
standard error of the response variable |
n |
number of bottles |
If show.more = TRUE
additional columns are returned:
summ2 <- summ2[ , c(descrip.name, time.name, 'mean', 'se', 'sd', 'n', 'rsd.inoc', 'fv.inoc', 'se1', 'se2', 'se3')]
rsd.inoc |
relative standard deviation in specific |
fv.inoc |
(mean) fraction of bottle |
se1 |
standard error contribution from variation among replicate substrate bottles |
se2 |
standard error contribution from variation among inoculum-only bottles |
se2 |
standard error contribution from uncertainty in substrate mass addition |
If show.obs = TRUE
even more columns are returned:
cvCH4.tot |
name based on |
cvCH4.inoc |
name based on |
se.inoc |
standard error from inoculum used to calculate |
cvCH4.se |
name based on |
Reported standard deviation and standard error includes an estimate of variability from subtracting the inoculum contribution when this is done.
Sasha D. Hafner and Charlotte Rennuit
data("vol") data("comp") data("setup") # First need to calculate cumulative methane production data cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, time.name = "days", extrap = TRUE) head(cum.prod) # Cumulative methane production (default) at 30 d # Uses default names for some columns summBg(vol = cum.prod, setup = setup, time.name = "days", when = 30) # Or total cumulative biogas summBg(vol = cum.prod, setup = setup, time.name = "days", vol.name = "cvBg", when = 30) # Cumulative CH4 only, subtract inoculum contribution summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 30) # And normalise by mvs.sub column (mass of substrate VS here) (so the result is BMP) summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 30, norm.name = "mvs.sub") # Same example, but return results for three times summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = c(10, 30, 60), norm.name = "mvs.sub") # Back to earlier example, but return all individual observations # (and total production and individual contributions of substrate # and inoculum) summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 30, norm.name = "mvs.sub", show.obs = TRUE) # Something different: interpolated biogas production rates summBg(vol = cum.prod, setup = setup, time.name = "days", vol.name = "rvBg", when = 30, show.obs = TRUE) # The when argument could also be 'meas', 'end', or '1p3d' (or related) for any of these examples summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "end", norm.name = "mvs.sub") summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "meas", norm.name = "mvs.sub") summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p3d", norm.name = "mvs.sub") # Or combine multiple values of when in a list summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = list(30, "1p3d", "end"), norm.name = "mvs.sub") # If you want to apply the 1% criterion but also want a single fixed time for all bottles, # you have to use two calls summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p3d", norm.name = "mvs.sub") # From the first call, the longest time is 42 days, so use when = 42 summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 42, norm.name = "mvs.sub") # If an error is thrown because a bottle doesn't meet the 1% criterion, use # show.rates = TRUE to see rates ## Not run: # Will return error cpshort <- cum.prod[cum.prod$days < 10, ] summBg(vol = cpshort, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p", norm.name = "mvs.sub") ## End(Not run) # So then use this to see which bottles are causing problems cpshort <- cum.prod[cum.prod$days < 10, ] summBg(vol = cpshort, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p", norm.name = "mvs.sub", show.rates = TRUE) # Example with dataset with different column names data("vol2") data("comp2") data("setup2") # First need to calculate cumulative methane production data 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) # Cumulative CH4 production at 30 d, subtract inoculum contribution # and normalise by sub.vs column (mass of substrate VS here) (look at setup2). summBg(vol = cum.prod, setup = setup2, id.name = "bottle", time.name = "days", descrip.name = "description", inoc.name = "Inoculum", inoc.m.name = "inoc.mass", norm.name = "sub.vs", when = 30)
data("vol") data("comp") data("setup") # First need to calculate cumulative methane production data cum.prod <- cumBg(vol, comp = comp, temp = 20, pres = 1, time.name = "days", extrap = TRUE) head(cum.prod) # Cumulative methane production (default) at 30 d # Uses default names for some columns summBg(vol = cum.prod, setup = setup, time.name = "days", when = 30) # Or total cumulative biogas summBg(vol = cum.prod, setup = setup, time.name = "days", vol.name = "cvBg", when = 30) # Cumulative CH4 only, subtract inoculum contribution summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 30) # And normalise by mvs.sub column (mass of substrate VS here) (so the result is BMP) summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 30, norm.name = "mvs.sub") # Same example, but return results for three times summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = c(10, 30, 60), norm.name = "mvs.sub") # Back to earlier example, but return all individual observations # (and total production and individual contributions of substrate # and inoculum) summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 30, norm.name = "mvs.sub", show.obs = TRUE) # Something different: interpolated biogas production rates summBg(vol = cum.prod, setup = setup, time.name = "days", vol.name = "rvBg", when = 30, show.obs = TRUE) # The when argument could also be 'meas', 'end', or '1p3d' (or related) for any of these examples summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "end", norm.name = "mvs.sub") summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "meas", norm.name = "mvs.sub") summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p3d", norm.name = "mvs.sub") # Or combine multiple values of when in a list summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = list(30, "1p3d", "end"), norm.name = "mvs.sub") # If you want to apply the 1% criterion but also want a single fixed time for all bottles, # you have to use two calls summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p3d", norm.name = "mvs.sub") # From the first call, the longest time is 42 days, so use when = 42 summBg(vol = cum.prod, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = 42, norm.name = "mvs.sub") # If an error is thrown because a bottle doesn't meet the 1% criterion, use # show.rates = TRUE to see rates ## Not run: # Will return error cpshort <- cum.prod[cum.prod$days < 10, ] summBg(vol = cpshort, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p", norm.name = "mvs.sub") ## End(Not run) # So then use this to see which bottles are causing problems cpshort <- cum.prod[cum.prod$days < 10, ] summBg(vol = cpshort, setup = setup, time.name = "days", inoc.name = "inoc", inoc.m.name = "minoc", when = "1p", norm.name = "mvs.sub", show.rates = TRUE) # Example with dataset with different column names data("vol2") data("comp2") data("setup2") # First need to calculate cumulative methane production data 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) # Cumulative CH4 production at 30 d, subtract inoculum contribution # and normalise by sub.vs column (mass of substrate VS here) (look at setup2). summBg(vol = cum.prod, setup = setup2, id.name = "bottle", time.name = "days", descrip.name = "description", inoc.name = "Inoculum", inoc.m.name = "inoc.mass", norm.name = "sub.vs", when = 30)
Gas density biochemical methane potential (GD-BMP) measurements for 9 batch anaerobic bottles.
data("UQGDBiogas")
data("UQGDBiogas")
A data frame with 135 observations on the following variables.
id
identification code, a unique value for each bottle in the dataset. A factor.
time.d
elapsed time of measurements (from bottle setup) in days, a numeric vector.
vol
measured biogas volume at the end of a sampling interval, a numeric vector.
mass.init
total bottle mass prior to biogas venting in g, a numeric vector.
mass.final
total bottle mass after biogas venting in g, a numeric vector.
These data are meant to be example data for calcBgGD
, for gas density-based determination of biogas production (GD-BMP).
Reactors were glass serum bottles with butyl rubber septa.
Masses were measured with an analytical balance.
Data in UQGDSetup
are from the same bottles.
Measurements were made by Sergi Astals and are described in the following paper.
Justesen, C.G., Astals, S., Mortensen, J.R., Thorsen, R., Koch, K., Weinrich, S., Triolo, J.M., Hafner, S.D. 2019. Development and validation of a low-cost gas density method for measuring biochemical potential (BMP) Water (MDPI) 11(12): 2431.
data(UQGDBiogas)
data(UQGDBiogas)
Details on bottle contents and more from GD-BMP experiment.
data("UQGDSetup")
data("UQGDSetup")
A data frame with 9 observations on the following variables.
id
identification code, a unique value for each bottle in the dataset. A factor.
descrip
description of substrate, a factor with levels Inoculum
, Cellulose
, Substrate C
.
m.inoc
mass of inoculum added to the bottle at the start in g. Numeric.
m.sub
mass of substrate added to the bottle at the start in g. Numeric.
m.tot
total mass added to the bottle at the start in g. Numeric.
m.sub.vs
mass of volatile solids (VS) of substrate added to the bottle at the start in g. Numeric.
vol.hs
bottle headspace in mL. Numeric.
isr
VS-based inoculum-to-substrate ratio.
These data are meant to be example data for calcBgGD
, for gas density-based determination of biogas production (GD-BMP).
Reactors were glass serum bottles with butyl rubber septa.
Data in UQGDBiogas
are from the same bottles.
Measurements were made by Sergi Astals and are described in the following paper.
Justesen, C.G., Astals, S., Mortensen, J.R., Thorsen, R., Koch, K., Weinrich, S., Triolo, J.M., Hafner, S.D. 2019. Development and validation of a low-cost gas density method for measuring biochemical potential (BMP) Water (MDPI) 11(12): 2431.
data(UQGDSetup)
data(UQGDSetup)
Gravimetric biochemical methane potential measurements for 9 batch anaerobic bottles.
data("UQGravBiogas")
data("UQGravBiogas")
A data frame with 135 observations on the following variables.
id
identification code, a unique value for each bottle in the dataset. A factor.
day
elapsed time of measurements (from bottle setup) in days, a numeric vector.
mass.init
total bottle mass prior to biogas venting in g, a numeric vector.
mass.final
total bottle mass after biogas venting in g, a numeric vector.
xCH4
biogas methane content as a mole fraction (normalized so methane and carbon dioxide sum to 1.0), a numeric vector.
These data are meant to be example data for calcBgGrav
, for gravimetric determination of biogas production.
Reactors were glass serum bottles with butyl rubber septa.
Masses were measured with an analytical balance.
Data in UQGravSetup
are from the same bottles.
Measurements were made by Sergi Astals and are described in the following paper.
Justesen, C.G., Astals, S., Mortensen, J.R., Thorsen, R., Koch, K., Weinrich, S., Triolo, J.M., Hafner, S.D. 2019. Development and validation of a low-cost gas density method for measuring biochemical potential (BMP) Water (MDPI) 11(12): 2431.
data(UQGravBiogas)
data(UQGravBiogas)
Details on bottle contents and more from a gravimetric BMP test.
data("UQGravSetup")
data("UQGravSetup")
A data frame with 9 observations on the following variables.
id
identification code, a unique value for each bottle in the dataset. A factor.
descrip
description of substrate, a factor with levels Inoculum
, Cellulose
, Substrate C
.
m.inoc
mass of inoculum added to the bottle at the start in g. Numeric.
m.sub
mass of substrate added to the bottle at the start in g. Numeric.
m.tot
total mass added to the bottle at the start in g. Numeric.
vol.hs
bottle headspace in mL. Numeric.
m.sub.vs
mass of volatile solids (VS) of substrate added to the bottle at the start in g. Numeric.
m.inoc.vs
mass of volatile solids (VS) of inoculum added to the bottle at the start in g. Numeric.
isr
VS-based inoculum-to-substrate ratio.
These data are meant to be example data for calcBgGrav
, for gravimetric determination of biogas production.
Reactors were glass serum bottles with butyl rubber septa.
Data in UQGravBiogas
are from the same bottles.
Measurements were made by Sergi Astals and are described in the following paper.
Justesen, C.G., Astals, S., Mortensen, J.R., Thorsen, R., Koch, K., Weinrich, S., Triolo, J.M., Hafner, S.D. 2019. Development and validation of a low-cost gas density method for measuring biochemical potential (BMP) Water (MDPI) 11(12): 2431.
data(UQGravSetup)
data(UQGravSetup)
Biogas volume measurements from twelve batch reactors.
data("vol")
data("vol")
A data frame with 288 observations on the following 4 variables:
id
identification code, a unique value for each reactor in the dataset. A factor with levels 2_1
, 2_2
, 2_3
, 2_4
, 2_5
, 2_6
, 2_7
, 2_8
, 2_9
, 2_10
, 2_11
, and 2_12
date.time
date and time of mass measurement, a POSIXct object.
days
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
vol
volume of biogas removed at date.time
in mL, a numeric vector.
These data are meant to be example data for multiple functions, e.g., stdVol
, cumBg
, or summBg
.
Reactors were 500 mL glass serum bottles with butyl rubber septa and screw caps.
Volume was measured using syringes.
Data in vol
, mass
, xCH4
, and setup
are from the same reactors.
Measurements by Charlotte Rennuit and Ali Heidarzadeh Vazifehkhoran.
data(vol)
data(vol)
Biogas volume measurements from 15 batch reactors.
data("vol2")
data("vol2")
A data frame with 216 observations on the following 4 variables:
bottle
identification code, a unique value for each reactor in the dataset. A factor with levels 1_1
, 1_2
, 1_3
, 2_1
, 2_2
, 2_2
, ... through 5_3
. The first number indicates the sample, the second the replicate.
days
elapsed time of mass measurements (from reactor setup) in days, a numeric vector.
meas.vol
volume of biogas removed at days
in mL, a numeric vector
These data are meant to be example data for multiple functions, e.g., stdVol
, cumBg
, or summBg
.
Reactors were 500 mL or 1000 mL glass serum bottles with butyl rubber septa and screw caps.
Volume was measured using syringes.
Data in vol2
, xCH42
, and setup2
are from the same reactors.
Measurements by Ali Heidarzadeh Vazifehkhoran.
data(vol2)
data(vol2)
vol2mass
calculates the mass of biogas removed from a reactor, based on its composition, temperature, and pressure.
This function is the inverse of mass2vol
.
vol2mass(volBg, xCH4, temp.hs, temp.vol, pres.hs, pres.vol, unit.temp = getOption('unit.temp', 'C'), unit.pres = getOption('unit.pres', 'atm'), rh.hs = 1, rh.vol = 1)
vol2mass(volBg, xCH4, temp.hs, temp.vol, pres.hs, pres.vol, unit.temp = getOption('unit.temp', 'C'), unit.pres = getOption('unit.pres', 'atm'), rh.hs = 1, rh.vol = 1)
volBg |
measured (not standardised) biogas volume in mL. Numeric vector. |
xCH4 |
mole fraction of methane within biogas (dry, methane and carbon dioxide only). Numeric vector. |
temp.hs |
temperature of biogas just prior to removal, in the units specified in |
temp.vol |
temperature of biogas at the time of volume measurement, in the units specified in |
pres.hs |
pressure of biogas just prior to removal, in the units specified in |
pres.vol |
pressure of gas at the time of measurement in atm by default (see |
unit.pres |
pressure units.
Options are |
unit.temp |
temperature units.
Options are |
rh.hs |
relative humidity of the reactor headspace just prior to biogas removal. Length one numeric vector between zero and 1.0. |
rh.vol |
relative humidity of the biogas at the time of volume measurement. Length one numeric vector between zero and 1.0. |
This function is vectorized.
Argument elements will be recycled as needed.
Note that this function is conceptually but not numerically the inverse of mass2vol
, because the volBg
argument here is not standardised, and is assumed to be saturated with water vapor just prior to removal.
The mass that is calculated may not be equal to the mass of the biogas at the time of volume measurement–as long as temp.vol
is less than temp.hs
, some of the water lost from the reactor condenses and is not present in the biogas at the time of volume measurement.
Standard values and units of temperature and pressure can be globally set using the function options
.
biogas mass in g as a numeric vector.
Sasha D. Hafner and Charlotte Rennuit
Hafner, S.D., Rennuit, C., Triolo, J.M., Richards, B.K. In review. A gravimetric method for measuring biogas production. Biomass and Bioenergy.
# Mass loss from reactor for 100 mL biogas measured at 20 degrees C # and 1.0 atm, with headspace at 1.5 atm and 35 degrees C at the # time of biogas exit vol2mass(100, xCH4 = 0.65, temp.hs = 35, temp.vol = 20, pres.hs = 1.5, pres.vol = 1) # If the measured volume has already been standardised to dry # conditions at 0 C and 1 atm vol2mass(100, xCH4 = 0.65, temp.hs = 35, temp.vol = 0, pres.hs = 1.5, pres.vol = 1, rh.vol = 0) # Here vol2mass *is* numerically the inverse of mass2vol vol2mass(mass2vol(1.234, xCH4 = 0.65, temp = 35, pres = 1.5, value = "Bg"), xCH4 = 0.65, temp.hs = 35, temp.vol = 0, pres.hs = 1.5, pres.vol = 1, rh.vol = 0)
# Mass loss from reactor for 100 mL biogas measured at 20 degrees C # and 1.0 atm, with headspace at 1.5 atm and 35 degrees C at the # time of biogas exit vol2mass(100, xCH4 = 0.65, temp.hs = 35, temp.vol = 20, pres.hs = 1.5, pres.vol = 1) # If the measured volume has already been standardised to dry # conditions at 0 C and 1 atm vol2mass(100, xCH4 = 0.65, temp.hs = 35, temp.vol = 0, pres.hs = 1.5, pres.vol = 1, rh.vol = 0) # Here vol2mass *is* numerically the inverse of mass2vol vol2mass(mass2vol(1.234, xCH4 = 0.65, temp = 35, pres = 1.5, value = "Bg"), xCH4 = 0.65, temp.hs = 35, temp.vol = 0, pres.hs = 1.5, pres.vol = 1, rh.vol = 0)
vol2mol
calculates the moles of a gas for a measured volume, temperature, and pressure.
vol2mol(vol, gas = "CH4", temp, pres, rh = 0, unit.temp = getOption('unit.temp', 'C'), unit.pres = getOption('unit.pres', 'atm'), tp.message = TRUE)
vol2mol(vol, gas = "CH4", temp, pres, rh = 0, unit.temp = getOption('unit.temp', 'C'), unit.pres = getOption('unit.pres', 'atm'), tp.message = TRUE)
vol |
measured gas volume in mL. Numeric vector. |
gas |
chemical formula of gas.
Currently options are |
temp |
temperature of gas at time of volume measurement. Numeric vector. |
pres |
pressure of gas at time of volume measurement, in the units specified in |
rh |
relative humidity of the gas at time of measurement. Length one numeric vector between zero and 1.0. Default is zero (dry gas). |
unit.temp |
temperature units.
Options are |
unit.pres |
pressure units.
Options are |
tp.message |
should a message display |
This function uses a simple and approximate approach for the conversion, based on Charles's and Boyle's laws, with NIST values for 0 degrees C and 1.0 atm taken as the reference state (Lemmon et al. 2011).
Measured volume is normalized to 1.0 atm and 0 degrees C using stdVol
, and the result is divided by the molar volume at the same conditions, as reported by NIST.
Resulting error should be within 0.5% for temperature and pressure close to ambient, and is usually below 0.2%.
gas amount in moles as a numeric vector.
Sasha D. Hafner
Lemmon EW, McLinden MO, Friend DG. Thermophysical Properties of Fluid Systems. In Linstrom PJ, Mallard WG, editors. Chemistry WebBook, NIST Standard Reference Database Number 69. Gaithersburg, MD: National Institute of Standards and Technology, 2011.
# Assume we have measured 253 mL CH4 at 1.0 atm and 22 C, dry vol2mol(253, "CH4", temp = 22, pres = 1) # Compare to results to NIST values for the least ideal gas # Results are within 0.5% # Expect 0.04108 mol vol2mol(1000, "CO2", temp = 25, pres = 1) # Expect 0.08258 mol vol2mol(1000, "CO2", temp = 25, pres = 2) # Expect 0.07482 mol vol2mol(1000, "CO2", temp = 55, pres = 2)
# Assume we have measured 253 mL CH4 at 1.0 atm and 22 C, dry vol2mol(253, "CH4", temp = 22, pres = 1) # Compare to results to NIST values for the least ideal gas # Results are within 0.5% # Expect 0.04108 mol vol2mol(1000, "CO2", temp = 25, pres = 1) # Expect 0.08258 mol vol2mol(1000, "CO2", temp = 25, pres = 2) # Expect 0.07482 mol vol2mol(1000, "CO2", temp = 55, pres = 2)