calc_yield: Data transformation functions

View source: R/data_transformation.R

calc_yieldR Documentation

Data transformation functions

Description

A set of functions that allow to calculate and summarize biogas yield and production on the one hand, or allow to remove certain data points of a fermentation based on the fermentation/ observation time.

Usage

calc_yield(x, pos = 6, feedback = FALSE)

summarize_yield(x, timep = "auto", feedback = FALSE)

relative_production(x, feedback = FALSE)

calculate_flow_from_volume(x)

Arguments

x

a BGF

pos

a integer or character referencing the column with reference masses in the metaData layer

feedback

logic; if TRUE, the function will print a feedback to the console

timep

a numeric. The fermentation/ observation time at which to calculate the yield. Can be the character string 'auto' instead (default). In this case the final time is automatically chosen

Details

The function calc_yield allows to calculates a biogas yield (volume per mass) based on the 'netGas' column of the BioGasData layer of a BGF. In addition, a reference mass for each fermentation must be present in the metaData layer of the respective BGF. If a fermentation is classified as 'Blank', this mass will not be used.

The function summarize_yield summarizes the 'production' and 'yield' column of a BioGasData layer at a chosen time. The summary will be transferred to the metaData layer of the same BGF. It contains the information of what was the mean yield, the may production and when did max production occur for each reactor layout. If several fermentations share the same reactor layout standard deviations for the those three parameters are calculated as well.

The function relative_production calculates the relative biogas production ((accumulated biogas volume at time)/(final accumulated biogas volume)). It uses the values of the 'production' column in the BioGasData layer of a BGF and stores its results in the 'rel_production' column.

The function calculate_flow_from_volume uses the 'product' column of a BGFs BioGasData layer and generates values for the 'production' column. In particular, it takes the 'product' value at each time and subtracts the previous 'product' value, specifically for each fermentation. This reflects the amount of product formed in between time_now and time_previous and has the unit 'volume/time'. However, if the 'product' column does not contain volumetric biogas data (e.g. gravimetric biogas data instead) the unit of the production column can be different (e.g. 'mass/time'). The first 'product' value is subtracted by itself.

Value

a BGF

Examples

# create an example BGF
myBGF <- BGF(
        ReactorLayout = c("2*Meso","Cellulose","2*S1 ctrl","2*S1 7d","2*S1 4d",
                          "2*S2 ctrl","2*S2 4d","2*S2 6d"),
        BlankLabel = "Meso",
        name = "myBGF",
        ProcessTemp = 42,
        MeasurementType = "AMPTSV2")

# add data to BGF
myBGF <- add_bmp_measurement(
        x = myBGF,
        path = base::system.file("extdata","AMPTSV2.csv",package = "bgfanalyzer"))

# correct data
myBGF <- cols_to_numeric(myBGF)
myBGF <- close_gaps(myBGF)

# calculate netGas
myBGF <- netGas(myBGF)

# print the BGF; the yield was not calculated yet
myBGF

# calculate yield
myBGF <- calc_yield(myBGF)

# summarize yield
myBGF <- summarize_yield(myBGF)

# print the BGF again; now the yield was calculated
myBGF

# calculate relative production
myBGF <- relative_production(myBGF,TRUE)

# create another example BGF
myBGF2 <- from_standard_record(
        ReactorLayout = "A",
        ProcessTemp = 80,
        InocToSubRatio = .1,
        path = base::system.file("extdata","Fermentation_A.tsv",package = "bgfanalyzer"),
        time_col = 1,
        product_col = 3)

# calculate production
myBGF2 <- calculate_flow_from_volume(myBGF2)


bgfanalyzer documentation built on Sept. 26, 2026, 5:07 p.m.