sashahafner / biogas Goto Github PK
View Code? Open in Web Editor NEWTools for biogas research in R: process biogas data and predict biogas production
Tools for biogas research in R: process biogas data and predict biogas production
The current (old) approach is within the heart of the function, complicated, and would not work for e.g., a combination of pdwhen and a numeric. Nor would new rate.crit.met column work with more than one when element. Should rewrite as recursive call as with other additions at top.
This function replaces hard-wired N2 gas density. At least mass2vol() needs to be updated.
cum.prodl.man <- cumBgMan(strawPressure, comp = strawComp, temp = 31,
data.struct = 'long',
id.name = "bottle", time.name = "time",
dat.name = "pres", comp.name = "xCH4",
temp.init = 21.55, pres.resid = "pres.resid", pres.init = 0.0,
headspace = strawSetup, vol.hs.name = "headspace",
pres.amb = 101.3, absolute = FALSE,
extrap = TRUE, addt0 = TRUE,
unit.pres = "kPa")
Biogas composition is interpolated.
Pressure measurements are GAUGE If this is incorrect, change 'absolute' argu
ment to TRUE.
Using a standard pressure of 101.325 kPa and standard temperature of 0 C for
standardizing volume.
Warning message:
In stdVol(dat[, vol.hs.name], temp = dat[, "temp.prev"], pres = dat$pres.res
id.prev, :
pres ranges from 101.3 kPa to 203.4356 kPa. Is this really correct?
For example, there is no check that m.pre.name or m.post.name are actually columns in data frame -> useless errors!
Why did I ever user 'vol.name' to sort here?
else if (length(when) == 1 && tolower(when) == "end") {
summ1 <- data.frame(id = ids, time = NA, vol = NA)
names(summ1) <- c(id.name, time.name, vol.name)
vol <- vol[order(vol[, id.name], vol[, vol.name]), ]
for (i in ids) {
dc <- vol[vol[, id.name] == i, ]
summ1[summ1[, id.name] == i, c(time.name, vol.name)] <- dc[nrow(
dc),
c(time.name, vol.name)]
}
}
Means time returned may not be latest time.
If final time is selected by e.g. when = "1p3d" but not all bottles have the same final time, function will tag a bottle as pdnotyet (rate criterion not met). Can we interpolate first in the function so we have the same times for all bottles?
dat <- calcBgVol(dat, comp = 0.65, comp.name = 'xCH4', temp = 'temp.c', pres = 'pres.hPa', data.struct = 'long',
id.name = 'channel', time.name = 'time.d', vol.name = 't.vol', unit.pres = 'hPa')
will not work (gives useless error) without comp.name. Although DataPrep function has default for comp.name, call in calcBg will send in NULL and so there is no place to put xCH4/comp in the returned data frame. So DataPrep has to check for null with comp exists and use a default name xCH4.
Should accept diftime and maybe others as well but does not.
temp.init, pres.init are used with assumption that bottle is not vented once warmed up. But it is in some cases.
No description
Error when there is no subtraction of inoculum contribution with show.when = TRUE.
IMP <- summBg(cbg, setup = ds, id.name = 'id', time.name = 'time.d',
descrip.name = 'substrate', norm.name = 'm.inoc.vs',
show.more = TRUE, when = 'end')
Response variable (volume) is cbg$cvCH4.
Inoculum contribution not subtracted.
Response normalized by setup$m.inoc.vs.
Error in [.data.frame
(summ2, , s2cols) : undefined columns selected
In line 14 it says 'Check arguments', but there is nothing there. Check arguments should be added similar to how it is done in cumBg function.
From Alexandre B.: When we set show.more to TRUE , we get extra columns, such as "rsd.inoc" "fv.inoc" "se1" "se2" "se3" (if show.obs = F) and "vol.mi.rsd" "cvCH4.tot" "cvCH4.inoc" "fv.inoc" "se.inoc" "cvCH4.se" (if show.obs = T). What do they mean? I could not find anything about them.
For testing GD-BMP method
Can use recursive call after check of molar volume to get a more precise result, if only to exactly match mass2vol(). Should be able to do by adding molar volume of biogas as gdComp() argument.
New rate.crit argument in summBg() works but is not complete. Needs to be able to identify cases where net yield drops (rates are negative). Not clear how this should be handled with respect to maximum 1% gross time based on VDI report.
There seems to be an error in mass output. See example below.
planBMP(15.6, 850, isr = 2, m.tot = 250)
Parameter Unit Value
Inoc. VS conc. g/g 15.6
Substrate VS conc. g/g 850
Mix. VS conc. g/g 23.2
ISR (VS basis) g/g 2
Inoc. mass g 248
Substrate mass g 2.27
Mixture mass g 250
Sub. VS mass g 1930
Inoc. VS mass g 3860
Mix. VS mass g 5800
When bottles are not vented and residual pressure is the same as initial pressure, missing composition data should be set to earliest following available observation, and not interpolated. Realized this when working with LeAF data.
Simple but really useful function. Needs to be advertised.
pres.std does not seem to automatically convert to new units in mass2vol() calls.
Including test of different data structures.
I noticed another bug on OBA. In the theoretical biogas tab, if you set COD mass, when you choose ‘More details’ or ‘Reaction’ as output, you get a wrong value, i.e. 0.001 L for 1 g COD, instead of 0.349 L for 1 g COD. Moreover, choosing one of these options does not display the reaction or extra details…
Last time I tried, package did not pass CRAN tests on R-devel because of this issue. Best option would be to get rid of all of the && and || operators if possible. I am not sure which ones remain.
With headspace correction, should be an error when temp.init is missing
The data processing functions should be able to handle tibbles.
While looking at the other summBg() problem with show.rates = TRUE
, I observed an unexpected behavior with regard to rates when inoculum contribution is not subtracted. Starting from the previous example, on latest dev branch:
data(feedSetup)
data(feedVol)
cpw <- calcBgVol(feedVol, comp = 1, temp = 0, pres = 1, data.struct = "wide",
time.name = "time.d", vol.name = "1", dry = TRUE, interval = FALSE)
s1.noinoc <- summBg(cpw, feedSetup, id.name = 'id', time.name = 'time.d', descrip.name = 'descrip', norm.name = 'm.sub.vs', show.obs = TRUE, show.rates = TRUE)
The column rrvCH4 is now improperly sorted. Output from plot(s1.noinoc[s1.noinoc$id==4,]$rrvCH4)
:
Commenting out this line makes the data properly ordered again:
Line 480 in 20b2488
It seems to me that this line may be superfluous, as the dataframe is also sorted before returning (e.g., lines 501, 660, 694-704), but maybe I am missing an edge case here?
For a headspace pressure of 3 atm at 35 C, expanded nearly 3x when measured at 1 atm and 20C, water vapor pressure will be slightly below saturation. For measurement at 35C, error would be larger.
Encountered this issue in GD functions. Should be "NULL" not NULL, it seems. Must be present in other functions.
v. 1.23.3:
Oops.
Should there be any? Can we delete all of them?
Function picks the latest one and then cannot find matching replicates. Would be better to pick earliest final time and use that.
> mv <- calcBgGD(mv, temp.vol = 20, temp.grav = 30, pres.vol = 1, pres.grav = 1.
5,
+ id.name = 'id', time.name = 'time.d',
+ vol.name = 'vol', m.pre.name = 'm.init', m.post.name = 'm.final
', comp.sub = 0)
Error: Expect class "logical, character" for argument comp.sub but got "numeric"
.
Check the check. Should be numeric.
See Asger and Monica's code. Why is there an error message saying that comp is needed for gravimetric method in some cases?
Currently does not.
biogas_quick_start.Rnw still uses cumBg()
. Should be changed to calcBgVol()
etc.
Should it be a warning? For very small mass gain should it be ignored?
Would be useful to have estimates of daily biogas production and headspace pressure for planning. Would need kinetic constant input and bottle headspace.
Following code gives some negative or very large volumes for pressure close to 1 kPa:
plot(mass2vol(0.1, xCH4 = 0.65, temp = 35, pres = c(1:200)/2, unit.pres = "kPa"))
Is this correct result? And why? May not be a problem with code but would be good to clarify.
How about a single function to handle the different data structures?
Function needed for calculating leakage from mass measurements.
Something like:
leakBg(
dat,
time.name,
m.pre.name,
m.post.name,
...
)
Output should include:
Interval
Leak mass
Total mass
Venting mass
Cumulative
Leak mass
Total mass
Venting mass
The CRAN and master versions of biogas are almost 2 years old. Let's try to sort out the remaining important open issues and merge with master, create a release on GitHub, and submit a new version to CRAN.
In mass2vol() and probably others, there is no pres.init, it is assumed to be 1 atm. Should be argument.
But they should
From Alex B. (see message below)
library(biogas)
data(vol2)
data(comp2)
data(setup2)
cbg <- cumBg(vol2, comp = comp2, temp = 20, pres = 1,
id.name = "bottle", time.name = "days",
dat.name = "meas.vol", comp.name = "CH4.conc",
extrap = TRUE)
s1 <- summBg(vol = cbg, setup = setup2, id.name = "bottle",
time.name = "days", descrip.name = "description",
inoc.name = "Inoculum", inoc.m.name = "inoc.mass",
norm.name = "sub.vs", show.obs = TRUE, show.rates = TRUE)
s2 <- summBg(vol = cbg, setup = setup2, id.name = "bottle",
time.name = "days", descrip.name = "description",
inoc.name = "Inoculum", inoc.m.name = "inoc.mass",
norm.name = "sub.vs", show.obs = TRUE, when = "meas", show.rates = FALSE)
Problems:
These are from R CMD check --as-cran
with a76aaff
Nothing too difficult, just needs some time.
* checking tests ...
Running ‘testthat.R’
ERROR
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
Component 14: 'is.NA' value mismatch: 6 in current 1 in target
── Failure (test_LowLevelFunctions.R:126:3): mass2vol non vectorised result is correct ──
mass2vol(...) not equal to `stdVCH4`.
1/1 mismatches
[1] 1673 - 1676 == -2.56
── Failure (test_LowLevelFunctions.R:131:5): planBMP works ─────────────────────
planBMP(...) not equal to c(...).
3/10 mismatches (average diff: 2)
[8] 0.001 - 1 == -0.999
[9] 0.002 - 2 == -1.998
[10] 0.003 - 3 == -2.997
[ FAIL 3 | WARN 2 | SKIP 0 | PASS 35 ]
Error: Test failures
Execution halted
* checking for code/documentation mismatches ... WARNING
Codoc mismatches from documentation object 'mass2vol':
mass2vol
Code: function(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)
Docs: function(mass, xCH4, 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)
Argument names in code not in docs:
xCO2 xN2
Mismatches in argument names (first 3):
Position: 3 Code: xCO2 Docs: temp
Position: 4 Code: xN2 Docs: pres
Position: 5 Code: temp Docs: temp.std
Codoc mismatches from documentation object 'planBMP':
planBMP
Code: function(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)
Docs: function(vs.inoc, vs.sub, isr = NA, m.inoc = NA, m.sub = NA,
m.tot = NA, m.vs.sub = vs.sub * m.sub, digits = 3,
warn = TRUE, nice = TRUE)
Mismatches in argument default values:
Name: 'm.tot' Code: m.inoc + m.sub Docs: NA
Name: 'm.vs.sub' Code: vs.sub * m.sub/1000 Docs: vs.sub * m.sub
Data codoc mismatches from documentation object 'feedSetup':
Variables in data frame 'feedSetup'
Code: descrip id m.inoc m.sub.vs
Docs: id m.inoc m.sub.vs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.