## load example data
data(tt.pre)
## extract field concentration measurements
gcd <- tt.pre[tt.pre$sampletype_a=="P",]
## partition the data into data tables per chamber measurement
# first tell which columns of the data you want to carry on
columns <- c("date", "veg", "spot", "time_min", "temp_dC", "cham_area",
"cham_vol", "CO2ppm", "CO2Code", "CH4ppb", "CH4Code", "N2Oppb", "N2OCode")
# then do the partitioning
gcd.parts <- conz.prep(gcd, columns, factors = c("date", "spot", "veg"),
nmes = c("date", "veg", "spot"))
## calculate flux rates for methane
# first define a global CH4 range limit
CH4.lim <- 30
# do the flux rate estimation (it will often be best to define
# var.par separately, note that p.air is given as a parameter)
vp.CH4 <- list(ghg = "CH4ppb", time = "time_min", gc.qual = "CH4Code",
volume = "cham_vol", t.air = "temp_dC", area = "cham_area", p.air = 101325)
flux.CH4 <- flux(gcd.parts, var.par = vp.CH4, ghg = "CH4", co2ntrol = NULL)
# look at the results table
flux.CH4
# now we extract range limits from the calibration gas measurements
# and attach them to gcd.parts. first we get the calibration gas
# measurements from tt.pre (we change the date because it is in
# a strange format and has to be the same as the dates in gcd.parts
cgm <- tt.pre[tt.pre$sampletype_a=="E",c("date_gc", "CH4ppb", "CH4Code",
"CO2ppm", "CO2Code", "N2Oppb", "N2OCode")]
names(cgm)[1] <- "date"
cgm$date <- "2011-03-16"
# now we can do the flux.calib
gcd.parts.cal <- flux.calib(gcd.parts, columns = c("date", "CH4ppb"),
calib = cgm, format="%Y-%m-%d")
# do the flux rate estimation (we use the same var.par as before)
flux.CH4 <- flux(gcd.parts.cal, var.par=vp.CH4, ghg = "CH4",
co2ntrol = NULL, range.lim=NULL)
# look at the results table
flux.CH4
## plot the concentration-change-with-time-plots as kind of diagnostic
plot(flux.CH4, subs = NULL, dims = c(3,6))
## do the flux rate estimation whilst using CO2 concentrations to
## control for possible chamber leakage
# first set the desired controls (without outlier transfer)
cntrl <- CO2.control(relay = FALSE, range.lim = 40, min.allow = 3,
max.nrmse = 0.2)
# do the flux rate estimation
flux.CH4.b <- flux(gcd.parts, var.par=vp.CH4, ghg = "CH4", co2ntrol = cntrl)
# look at the results table
flux.CH4.b
# plot the concentration-change-with-time-plots as kind of diagnostic
plot(flux.CH4.b, subs = NULL, dims = c(3,6))
## do the flux rate estimation whilst using CO2 concentrations to
## control for outliers and possible chamber leakage
# first set the desired controls
cntrl <- CO2.control(relay = TRUE, range.lim = 40, min.allow = 4,
max.nrmse = 0.2)
# do the flux rate estimation
flux.CH4.c <- flux(gcd.parts, var.par=vp.CH4, ghg = "CH4",
co2ntrol = cntrl)
# look at the results table
flux.CH4.c
# plot the concentration-change-with-time-plots as kind of diagnostic
plot(flux.CH4.c, subs = NULL, dims = c(3,6))Run the code above in your browser using DataLab