Learn R Programming

biogas (version 1.61)

calcBgGrav: Calculate Biogas Production from Gravimetric Data

Description

calcBgGrav calculates cumulative biogas, methane production and production rates from mass loss (gravimetric measurements) and volume measurements for any number of bottles.

Usage

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
  )

Value

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.

Arguments

dat

a data frame with at least bottle identification code, time of measurement (as numeric, or POSIX), and bottle mass. Structure depends on data.struct argument. Additional columns can be present--these will be returned in the output data frame.

comp

(optional) a data frame with the columns bottle identification code; time of measurement, (as numeric, or POSIX); and methane concentration within dry biogas as a mole fraction, considering only methane and carbon dioxide (unless cmethod = "total") or a single numeric value. The names of these columns are specified with id.name, time.name, and xCH4.name. Default is NULL.

temp

the temperature of biogas just prior to venting. A length-one numeric vector. Degrees Celcius by default (see unit.temp argument).

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 dat with the pressure measurements. Atmospheres by default (see unit.pres argument).

data.struct

the structure of input data. The default of 'longcombo' means bottle mass and biogas composition (if available) are both in dat. The dat data frame must have bottle identification code and time columns with names specified with id.name and time.name, mass data in a single column with the name specified by mass.name, and biogas composition in a single column with the name specified by comp.name For the data.struct = 'long' option, two separate data frames are needed, one for mass and one for composition (if available). Each data frame must have bottle identification code and time columns with names specified with id.name and time.name. The dat data frame must have mass data in a single column with the name specified by mass.name. The comp data frame must have biogas composition in a single column with the name specified by comp.name. For the data.struct = 'wide' option, two separate data frames are needed as in 'long', but there are no bottle identification code columns. Instead, in dat, mass data are in a separate column for each bottle, and column names are bottle identification codes. Here, mass.name should be the name of the first column with mass data. All following columns are assumed to also have mass data. And in comp, biogas composition data are also in a separate column for each bottle, also with bottle identification codes for column names. Here, comp.name should be the name of the first column with biogas composition data, as for dat.

id.name

name of the bottle identification code column in dat. Must be the same in all data frames used in the function. Default is "id".

time.name

name of column containing time data in dat and comp data frames. Default is "time".

mass.name

name of column containing the primary response variable (bottle mass) in dat data frame.

xCH4.name

name of column containing biogas mole fraction of methane in comp data frame. Default is "xCH4". Must be normalised so xCH4 + xCO2 = 1.0 unless cmethod = "total".

xCO2.name

name of column containing biogas mole fraction of carbon dioxide in comp data frame. Only needed if cmethod = "total".

xN2.name

name of column containing biogas mole fraction of dinitrogen in comp data frame. Only needed if cmethod = "total".

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 id (bottle identification code) column (see id.name) and headspace volume column (see vol.hs.name argument). Default is NULL.

vol.hs.name

name of column containing headspace volume data in optional headspace data frame. Default is "vol.hs".

temp.init

the initial headspace temperature. Optional. A length-one numeric vector. Degrees Celcius by default (see unit.temp argument). Default is NULL, which suppresses correction for initial temperature.

pres.init

the initial headspace pressure. Optional. A length-one numeric vector. Atmospheres by default (see unit.pres argument). Default is NULL, which suppresses correction for initial pressure.

pres.resid

residual headspace pressure after venting. Optional. A length-one numeric vector. Atmospheres by default (see unit.pres argument). Default is NULL.

headcomp

initial headspace composition as a chemical formula. Optional, for correcting for change in headspace density. Mixtures accepted. Default is 'N2' for pure dinitrogen.

cmethod

method for calculating cumulative methane production. Use "removed" to base production on xCH4 and gas volumes removed (default). Use "total" to base it on the sum of methane removed and methane remaining in the bottle headspace. For "removed", xCH4 should be calculated based on methane and CO2 only (xCH4 + xCO2 = 1.0). For "total", xCH4 should be calculated including all biogas components (CH4, CO2, N2, H2S, etc.) except water. Length one character vector.

imethod

method used for interpolation of xCH4. This is passed as the method argument to interp. Length one character vector. Default is "linear" for linear interpolation.

extrap

should comp.name be extrapolated? Length one logical vector. This is passed as the extrap argument to interp. Default is FALSE.

addt0

is the earliest time in dat data frame “time zero” (start time)? If not, this argument adds a row with time.name = 0 for each bottle in order to calculate production rates for the first observation. This addition is only made when time.name is numeric (or integer). Length-one logical vector. Default is TRUE. To return these additional rows in the output, see showt0.

showt0

should “time zero” rows be returned in the output? Can be convenient for plotting cumulative volumes. Only applies if time.name is numeric (or integer). These rows may have been present in the original data (dat) or added by the function (see addt0). Default value depends on dat time.name column content. If time.name column is numeric and contains 0 then the default value is TRUE and otherwise FALSE.

std.message

should a message with the standard conditions be displayed? Default is TRUE.

check

should input data be checked for unreasonable values (with warnings)? Default is TRUE.

temp.std

standard temperature for presentation of biogas and methane results. Length one numeric vector. Default value is 0 degrees C (set in stdVol). Argument is passed to stdVol.

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 stdVol). Argument is passed to stdVol.

unit.temp

temperature units for temp and temp.std arguments. Default is "C". Argument is passed to stdVol.

unit.pres

pressure units for pres and pres.std arguments. Default is "atm". Argument is passed to stdVol.

quiet

use to suppress messages. Default is FALSE.

Author

Sasha D. Hafner

Details

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.

References

Hafner, S.D., Rennuit, C., Triolo, J.M., Richards, B.K. 2015. Validation of a simple gravimetric method for measuring biogas production in laboratory experiments. Biomass and Bioenergy 83, 297-301.

See Also

calcBgMan, calcBgVol, calcBgGD, summBg, interp, stdVol, options

Examples

Run this code

# 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)

Run the code above in your browser using DataLab