forked from rich-iannone/splitr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_emissions.R
68 lines (60 loc) · 1.78 KB
/
add_emissions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#' Add emissions parameters to a dispersion model
#'
#' Add a set of emissions parameters to a dispersion model object. Multiple sets
#' of emissions parameters can can be added to a single dispersion model object.
#'
#' @param model a splitr modeling object.
#' @param rate the rate of emissions for the pollutant in mass units per hour.
#' @param duration the duration of emissions in hours.
#' @param start_day the day that the emissions will begin. This should take the
#' form of a single-length vector for a day (`"YYYY-MM-DD"`).
#' @param start_hour a single daily hour as an integer hour (from `0` to
#' `23`).
#' @param name an identifier for the group of emissions parameters.
#'
#' @export
add_emissions <- function(model,
rate = NULL,
duration = NULL,
start_day = NULL,
start_hour = NULL,
name = NULL) {
if (is.null(name)) {
if (is.null(model$emissions)) {
name <- "emissions_1"
} else {
name <- paste0("emissions_", nrow(model$emissions) + 1
)
}
}
if (is.null(rate)) {
rate <- 1
}
if (is.null(duration)) {
duration <- 1
}
if (is.null(start_day)) {
start_day <- "10-05-01"
}
if (is.null(start_hour)) {
start_hour <- 0
}
# Write emissions parameters to a data frame
emissions <-
data.frame(
name = name,
rate = rate,
duration = duration,
start_day = start_day,
start_hour = start_hour,
stringsAsFactors = FALSE
)
# Write data frame to the `emissions` list
# component of `model`
if (is.null(model$emissions)) {
model$emissions <- emissions
} else {
model$emissions <- rbind(model$emissions, emissions)
}
model
}