Skip to content

Commit

Permalink
fix more errors, make Rd for calcBgGrav
Browse files Browse the repository at this point in the history
  • Loading branch information
sashahafner committed Dec 3, 2024
1 parent 9d8b907 commit 82887c7
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: biogas
Type: Package
Title: Process Biogas Data and Predict Biogas Production
Version: 1.50
Version: 1.52
Date: 2024-12-03
Authors@R: c(person("Sasha D.", "Hafner", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0955-0327")),
person("Charlotte", "Rennuit", role = "aut"),
Expand Down
10 changes: 5 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function throws an error. To help identify those bottles that haven't met the
criterion, set when = "1p" and show.obs = TRUE to see relative rates for all bottles
(rrvCH4 column).

# BUG FIXES
## BUG FIXES

*cumBg()
Fixed bug in dat.struct = "wide" option that caused problems when the number of
Expand All @@ -182,7 +182,7 @@ and suggestions related to cumBg().

# biogas 1.6.0
2016 December 16
# NEW FEATURES
## NEW FEATURES

*cumBg()
New dry argument (dry = FALSE by default) so that standardised gas volumes can be
Expand All @@ -199,7 +199,7 @@ inoculum-only bottle, with a warning.
Slight updates to "Getting started" vignette on data structures (more details in
cumBg() help file).

# BUG FIXES
## BUG FIXES

*cumBg()
When gauge = FALSE, pres.init should now be gauge pressure (pres.amb must be absolute
Expand All @@ -217,7 +217,7 @@ significantly among replicates was fixed.

*Other minor fixes

# REMOVED FUNCTIONALITY
## REMOVED FUNCTIONALITY
*summBg()
Removed default value for inoc.m.name argument to avoid mistakes.

Expand Down Expand Up @@ -249,7 +249,7 @@ function can find the time when the production rate drops below 1% of cumulative
production per day. This value can be different for each substrate and can be applied
with or without inoculum subtraction. To use, set when = "1p".

# BUG FIXES
## BUG FIXES

*cumBg()
Corrected calculation of initial standardized gas volume for manometric method
Expand Down
6 changes: 4 additions & 2 deletions R/mass2vol.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ mass2vol <- function(
warning('Sum of mole fractions > 1, is this correct?')
}

if (length(xN2) == 1 && length(xCH4) > 1) xN2 <- rep(xN2, length(xCH4))
if (length(xCO2) == 1 && length(xCH4) > 1) xCO2 <- rep(xCO2, length(xCH4))
if (length(mass) == 1 && length(xCH4) > 1) mass <- rep(mass, length(xCH4))
if (length(xCH4) == 1 && length(mass) > 1) xCH4 <- rep(xCH4, length(mass))
if (length(xN2) == 1 && length(mass) > 1) xN2 <- rep(xN2, length(mass))
if (length(xCO2) == 1 && length(mass) > 1) xCO2 <- rep(xCO2, length(mass))

xCH4 <- round(xCH4, 5)
xCO2 <- round(xCO2, 5)
Expand Down
2 changes: 1 addition & 1 deletion R/molMass.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ molMass <- function(form) {
fc <- readFormula(f)

# Check for unidentified element
if(any(!names(fc) %in% names(atom.weights))) stop('One or more elements in \"form\" is not in the database. You can add it to the \"atom.weights\" vector if you want to modify the function code. Otherwise send a request to sasha.hafner@eng.au.dk.')
if(any(!names(fc) %in% names(atom.weights))) stop('One or more elements in \"form\" is not in the database. You can add it to the \"atom.weights\" vector if you want to modify the function code. Otherwise send a request to sasha.hafner@bce.au.dk.')

# Calculate molar mass, using names of fc for indexing
mmass <- c(mmass, sum(atom.weights[names(fc)]*fc))
Expand Down
301 changes: 301 additions & 0 deletions man/calcBgGrav.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
\name{calcBgGrav}
\alias{calcBgGrav}
%- Also NEED an "\alias" for EACH other topic documented here.
\title{
Calculate Biogas Production from Gravimetric Data
}
\description{
\code{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
)
}
%- maybe also "usage" for other objects documented here.
\arguments{
\item{dat}{
a data frame with at least bottle identification code, time of measurement (as \code{numeric}, or \code{POSIX}), and bottle mass.
Structure depends on \code{data.struct} argument.
Additional columns can be present--these will be returned in the output data frame.
}

\item{comp}{
(optional) a data frame with the columns bottle identification code; time of measurement, (as \code{numeric}, or \code{POSIX}); and methane concentration within dry biogas as a mole fraction, considering only methane and carbon dioxide (unless \code{cmethod = "total"}) or a single numeric value.
The names of these columns are specified with \code{id.name}, \code{time.name}, and \code{xCH4.name}.
Default is \code{NULL}.
}
\item{temp}{
the temperature of biogas just prior to venting.
A length-one numeric vector.
Degrees Celcius by default (see \code{unit.temp} argument).
}
\item{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 \code{dat} with the pressure measurements.
Atmospheres by default (see \code{unit.pres} argument).
}

\item{data.struct}{
the structure of input data. The default of 'longcombo' means bottle mass and biogas composition (if available) are both in \code{dat}.
The \code{dat} data frame must have bottle identification code and time columns with names specified with \code{id.name} and \code{time.name}, mass data in a single column with the name specified by \code{mass.name}, and biogas composition in a single column with the name specified by \code{comp.name}
For the \code{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 \code{id.name} and \code{time.name}.
The \code{dat} data frame must have mass data in a single column with the name specified by \code{mass.name}.
The \code{comp} data frame must have biogas composition in a single column with the name specified by \code{comp.name}.
For the \code{data.struct = 'wide'} option, two separate data frames are needed as in \code{'long'}, but there are no bottle identification code columns.
Instead, in \code{dat}, mass data are in a separate column for each bottle, and column names are bottle identification codes.
Here, \code{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 \code{comp}, biogas composition data are also in a separate column for each bottle, also with bottle identification codes for column names.
Here, \code{comp.name} should be the name of the first column with biogas composition data, as for \code{dat}.
}

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

\item{time.name}{
name of column containing time data in \code{dat} and \code{comp} data frames. Default is \code{"time"}.
}

\item{mass.name}{
name of column containing the primary response variable (bottle mass) in \code{dat} data frame.
}

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

\item{xCO2.name}{
name of column containing biogas mole fraction of carbon dioxide in \code{comp} data frame.
Only needed if \code{cmethod = "total"}.
}

\item{xN2.name}{
name of column containing biogas mole fraction of dinitrogen in \code{comp} data frame.
Only needed if \code{cmethod = "total"}.
}

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

\item{vol.hs.name}{
name of column containing headspace volume data in optional \code{headspace} data frame.
Default is \code{"vol.hs"}.
}

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

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

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

\item{headcomp}{
initial headspace composition as a chemical formula.
Optional, for correcting for change in headspace density.
Mixtures accepted.
Default is \code{'N2'} for pure dinitrogen.
}

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

\item{imethod}{
method used for interpolation of \code{xCH4}.
This is passed as the \code{method} argument to \code{\link{interp}}.
Length one character vector.
Default is \code{"linear"} for linear interpolation.
}

\item{extrap}{
should \code{comp.name} be extrapolated?
Length one logical vector.
This is passed as the \code{extrap} argument to \code{\link{interp}}.
Default is \code{FALSE}.
}

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

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

\item{std.message}{
should a message with the standard conditions be displayed?
Default is \code{TRUE}.
}

\item{check}{
should input data be checked for unreasonable values (with warnings)?
Default is \code{TRUE}.
}

\item{temp.std}{
standard temperature for presentation of biogas and methane results.
Length one numeric vector.
Default value is 0 degrees C (set in \code{\link{stdVol}}).
Argument is passed to \code{\link{stdVol}}.
}

\item{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 \code{\link{stdVol}}).
Argument is passed to \code{\link{stdVol}}.
}

\item{unit.temp}{
temperature units for \code{temp} and \code{temp.std} arguments.
%Options are \code{"C"} (degrees Celcius), \code{"F"} (degrees Fahrenheit), and \code{"K"} (Kelvin).
Default is \code{"C"}.
Argument is passed to \code{\link{stdVol}}.
}

\item{unit.pres}{
pressure units for \code{pres} and \code{pres.std} arguments.
%Options are \code{"atm"}, \code{"Pa"}, \code{"kPa"}, \code{"hPa"}, and \code{"bar"}.
Default is \code{"atm"}.
Argument is passed to \code{\link{stdVol}}.
}

\item{quiet}{
use to suppress messages. Default is \code{FALSE}.
}

}

\details{
Using mass loss data from \code{dat} and composition data from \code{dat} or \code{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 \code{\link{options}}.
See \code{\link{stdVol}}.

}

\value{
a data frame with all the columns originally present in \code{dat}, plus others including these:
\item{vBg}{Standardized volume of biogas production for individual event.}
\item{xCH4}{Calculated mole fraction of methane in biogas.}
\item{vCH4}{Standardized volume of methane production for individual event.}
\item{cvBg}{Standardized cumulative volume of biogas production.}
\item{cvCH4}{Standardized cumulative volume of methane production.}
\item{rvBg}{Production rate of biogas.}
\item{rvCH4}{Production rate of methane.}
Units are based on units in input data.
}

\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. \emph{Biomass and Bioenergy} \bold{83}, 297-301.
}

\author{
Sasha D. Hafner
}

\seealso{
\code{\link{calcBgMan}},
\code{\link{calcBgVol}},
\code{\link{calcBgGD}},
\code{\link{summBg}},
\code{\link{interp}},
\code{\link{stdVol}},
\code{\link{options}}
}

\examples{

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)

}
%% Add one or more standard keywords, see file "KEYWORDS" in the
%% R documentation directory.
\keyword{chron}
\keyword{manip}
\concept{biogas}
2 changes: 1 addition & 1 deletion man/calcBgVol.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ calcBgVol(
}

\item{data.struct}{
the structure of input data. The default of 'longcombo' means separate objects for volume and composition (if available).
the structure of input data. The default of 'longcombo' means volume and composition (if available) are both in \code{dat}.
The \code{dat} data frame must have bottle identification code and time columns with names specified with \code{id.name} and \code{time.name}, volume data in a single column with the name specified by \code{vol.name}, and biogas composition in a single column with the name specified by \code{comp.name}
For the \code{data.struct = 'long'} option, two separate data frames are needed, one for volume and one for composition (if available).
Each data frame must have bottle identification code and time columns with names specified with \code{id.name} and \code{time.name}.
Expand Down
Loading

0 comments on commit 82887c7

Please sign in to comment.