alfam2 | R Documentation |
An implementation of the ALFAM2 model for predicting ammonia emission from field-applied manure. The model is described in Hafner et al. (2019).
alfam2(
dat,
pars = ALFAM2::alfam2pars02,
add.pars = NULL,
app.name = 'TAN.app',
time.name = 'ct',
time.incorp = NULL,
group = NULL,
center = TRUE,
cmns = c(app.rate = 40,
man.dm = 6.0,
man.tan = 1.2,
man.ph = 7.5,
air.temp = 13,
wind.2m = 2.7,
wind.sqrt = sqrt(2.7),
crop.z = 10),
check.NA = TRUE,
pass.col = NULL,
incorp.names = c('incorp', 'deep', 'shallow'),
add.incorp.rows = FALSE,
prep = FALSE,
warn = TRUE,
parallel = FALSE,
n.cpus = 1,
...)
dat |
data frame containing values for predictor variables |
pars |
A numeric vector (or a list of vectors) with model parameters (secondary parameters). Two parameter sets are provided with the package: |
add.pars |
Additional parameter values that will extend or overwrite the |
app.name |
name of column in |
time.name |
name of column in |
time.incorp |
either name of column in |
group |
name of column in |
center |
should numeric predictors be centered? Default parameters are based on centered values. |
cmns |
numeric vector with means for centering. |
check.NA |
should the function check for |
pass.col |
character vector with name(s) of column(s) in |
incorp.names |
character vector with name(s) of column(s) in |
add.incorp.rows |
function will add additional rows that exactly match the incorporation time(s) (no more than one per level of |
prep |
set to |
warn |
set to |
parallel |
should parallel processing be used? Helpful for very large |
n.cpus |
numeric. Defines the number of cores used if |
... |
additional optional arguments as length-one vectors that set values of fixed predictor variables. See examples. |
Parameter sets are provided for convenience. Both are numeric vectors. Set 1 (alfam2pars01
) (Hafner et al., 2019) contains the following:
c(int.f0 = -0.7364889,
int.r1 = -1.1785848,
int.r2 = -0.9543731,
int.r3 = -2.9012937,
app.mthd.os.f0 = -1.1717859,
app.rate.f0 = -0.0134681,
man.dm.f0 = 0.407466,
incorp.deep.f4 = -3.6477259,
incorp.shallow.f4 = -0.4121023,
app.mthd.bc.r1 = 0.6283396,
man.dm.r1 = -0.075822,
air.temp.r1 = 0.0492777,
wind.2m.r1 = 0.0486651,
man.ph.r1 = 0.5327231,
air.temp.r3 = 0.0152419,
incorp.deep.r3 = -0.3838862,
app.mthd.os.r3 = -0.122883,
man.ph.r3 = 0.2663616,
rain.rate.r2 = 0.4327281,
rain.cum.r3 = -0.0300936)
For Set 2, some parameters were removed, and others added, and all values changed at least slightly.
Calculation of this set is described in a report on Danish emission factors (Hafner et al., 2021).
c(int.f0 = -0.605683,
app.mthd.os.f0 = -1.74351,
app.rate.ni.f0 = -0.0111490,
man.dm.f0 = 0.399670,
man.source.pig.f0 = -0.592028,
app.mthd.cs.f0 = -7.63373,
int.r1 = -0.939215,
app.mthd.bc.r1 = 0.793524,
man.dm.r1 = -0.139881,
air.temp.r1 = 0.0735427,
wind.2m.r1 = 0.150267,
app.mthd.ts.r1 = -0.459071,
ts.cereal.hght.r1 = -0.244712,
man.ph.r1 = 0.665,
int.r2 = -1.79919,
rain.rate.r2 = 0.394022,
int.r3 = -3.22841,
app.mthd.bc.r3 = 0.561540,
app.mthd.cs.r3 = -0.666474,
man.ph.r3 = 0.238,
incorp.shallow.f4 = -0.964967,
incorp.shallow.r3 = -0.580527,
incorp.deep.f4 = -3.69495,
incorp.deep.r3 = -1.26570)
A data frame with the same number of rows as dat
(unless add.incorp.rows = TRUE
).
Deafult columns are:
ct
cumulative time since manure was applied
dt
interval duration (time step)
f0
f0 parameter
r1
r1 parameter
r2
r2 parameter
r3
r3 parameter
f4
r4 parameter
f
fast pool size at ct
(kg/ha)
s
slow pool size at ct
(kg/ha)
j
average NH3 flux in interval (kg/ha-h)
ei
interval emission (kg/ha)
e
cumulative emission (from time = 0 to ct
) (kg/ha)
er
relative cumulative emission (fraction of applied TAN)
ALFAM2mod()
is an alias for alfam2
.
The parameter sets also have aliases with capital ALFAM2
.
Sasha D. Hafner
Hafner, S.D., Pacholski, A., Bittman, S., Carozzi, M., Chantigny, M., Genermont, S., Haeni, C., Hansen, M., Huijsmans, J., Kupper, T., Misselbrook, T., Neftel, A., Nyord, T., Sommer, S. 2019. A flexible semi-empirical model for estimating ammonia volatilization from field-applied slurry. Atmospheric Environment 199 474-484.
Hafner, S.D., Nyord, T., Sommer, S.G., Adamsen, A.P.S. 2021. Estimation of Danish emission factors for ammonia from field-applied liquid manure for 1980 to 2019. Danish Centre for Food and Agriculture, Aarhus University, Aarhus, Denmark. Report no. 2021-0251862. https://pure.au.dk/portal/files/223538048/EFreport23092021.pdf
The AlFAM2 project website. https://projects.au.dk/alfam/
# Example 1
# Create predictor variable data
dat1 <- data.frame(ctime = 0:12*4, TAN.app = 100, man.dm = 8, air.temp = 15, app.mthd.bc = TRUE)
# Run model, using default parameter values
pred1 <- alfam2(dat1, app.name = 'TAN.app', time.name = 'ctime')
pred1
plot(e ~ ctime, data = pred1, type = 'o')
# For fixed variables (constant over time), they can be given as optional argument.
dat1b <- data.frame(ctime = 0:12*4)
# Run model, using default parameter values
pred1b <- alfam2(dat1b, app.name = 'TAN.app', time.name = 'ctime', TAN.app = 100,
man.dm = 8, air.temp = 15, app.mthd.bc = TRUE)
all.equal(pred1, pred1b)
# Example 2
# Add incorporation (can occur at any time)
dat2 <- dat1
dat2$incorp.deep <- TRUE
dat2$t.incorp <- 4
pred2 <- alfam2(dat2, app.name = 'TAN.app', time.name = 'ctime', time.incorp = 't.incorp')
# See change in r3
pred2
lines(e ~ ctime, data = pred2, type = 'o', col = 'red')
# Example 3
# Time step doesn't matter
dat3 <- data.frame(ctime = c(0, 48), TAN.app = 100, man.dm = 8, air.temp = 15, app.mthd.bc = TRUE)
pred3 <- alfam2(dat3, app.name = 'TAN.app', time.name = 'ctime')
lines(e ~ ctime, data = pred3, type = 'o', col = 'blue')
# Example 4
# Incorporation does not need to occur at end of interval
dat4 <- dat3
dat4$incorp.deep <- TRUE
dat4$t.incorp <- 4
pred4 <- alfam2(dat4, app.name = 'TAN.app', time.name = 'ctime', time.incorp = 't.incorp')
lines(e ~ ctime, data = pred4, type = 'o', col = 'orange')
# Incorporation time can be numeric also (not very practical for groups)
alfam2(dat4, app.name = 'TAN.app', time.name = 'ctime', time.incorp = 4)
# To see incorporation time in output, use add.incorp.rows
alfam2(dat4, app.name = 'TAN.app', time.name = 'ctime', time.incorp = 4, add.incorp.rows = TRUE)
# Example 5
# Function accepts multiple groups
dat5 <- data.frame(field.plot = 1:5, ctime = 48, TAN.app = 100, man.dm = 5, air.temp = 15,
app.mthd.bc = TRUE, t.incorp = 4)
pred5 <- alfam2(dat5, app.name = 'TAN.app', time.name = 'ctime', group = 'field.plot',
time.incorp = 't.incorp')
pred5
# See vignette for more examples. Run:
# vignette("ALFAM2-start")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.