Skip to content

Commit 9a5b418

Browse files
committed
Polynomial fit to cCO2
1 parent ad5b8c2 commit 9a5b418

File tree

10 files changed

+94
-19
lines changed

10 files changed

+94
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: growR
22
Type: Package
3-
Version: 1.3.0.9007
3+
Version: 1.3.0.9008
44
Date: 2024-05-23
55
Authors@R: person(
66
given = "Kevin",

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* `growR_run_loop` allows to suppress returning the simulation objects. This
1010
is useful to prevent overkill memory usage.
1111
* CO2 affects plant transpiration, according to `fCO2_transpiration_mod`.
12+
* Coefficients for polynomial fits to atmospheric CO2 concentration
13+
projections for different RCPs according to IPCC (`cCO2_coefficients`).
1214

1315
## Changed
1416

R/data.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,31 @@
126126
#' @md
127127
"parameter_scan_example"
128128

129+
#' Coefficients for polynomial fits to atmospheric CO2 concentration scenarios.
130+
#'
131+
#' @description
132+
#' The fifth IPCC assessment report provides data for atmospheric CO2
133+
#' concentration under different representative concentration pathway (RCP)
134+
#' scenarios on decadal resolution. The values in this matrix represent the
135+
#' coefficients of a second order polynomial fit to said data.
136+
#'
137+
#' @details
138+
#' These coefficients can be used to produce functions of the form `f(year) =
139+
#' a3*year^3 + a2*year^2 + a1*year + a0` which return the estimated
140+
#' atmospheric CO2 concentration in ppm for a given year.
141+
#' The validity of the polynomial fit is restricted to the years 2000 to 2100.
142+
#'
143+
#' @format A data.frame with columns
144+
#' \describe{
145+
#' \item{RCP}{Name of the RCP.}
146+
#' \item{a3}{Coefficient of the quadratic term.}
147+
#' \item{a2}{Coefficient of the quadratic term.}
148+
#' \item{a1}{Coefficient of the linear term.}
149+
#' \item{a0}{Coefficient of the constant term.}
150+
#' }
151+
#'
152+
#' @seealso [atmospheric_CO2()], [WeatherData()]`$aCO2()`
153+
#'
154+
#' @md
155+
"cCO2_coefficients"
156+

R/growR-package.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"_PACKAGE"
99

1010
globalVariables(c("yield_parameters",
11-
"management_parameters"))
11+
"management_parameters",
12+
"cCO2_coefficients"))
1213

1314
#' Default options introduced by package growR
1415
#'

R/weather.R

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,13 @@ WeatherData = R6Class(
286286
#' @description Choose the RCP to be used for the calculation of
287287
#' atmospheric CO2 concentration.
288288
#'
289-
#' @param RCP float or string. One of {2.6, 4.5, 8.5}.
289+
#' @param RCP float or string. One of 2.6, 4.5, 8.5.
290290
#'
291291
set_RCP = function(RCP) {
292292
RCP = as.character(RCP)
293-
allowed_RCPs = private$cCO2_table$RCP
294-
if (!RCP %in% allowed_RCPs) {
293+
if (!RCP %in% private$allowed_RCPs) {
295294
message = "[WeatherData]RCP `%s` not recognized. Allowed values:"
296-
message = paste(message, paste(allowed_RCPs, collapse = ", "))
295+
message = paste(message, paste(private$allowed_RCPs, collapse = ", "))
297296
warning(sprintf(message, RCP))
298297
} else {
299298
logger(sprintf("[WeatherData]Setting RCP to `%s`.", RCP), level = TRACE)
@@ -321,22 +320,21 @@ WeatherData = R6Class(
321320
if (is.null(RCP)) {
322321
RCP = private$RCP
323322
}
324-
row = private$cCO2_table[private$cCO2_table$RCP == RCP, ]
325-
c2020 = atmospheric_CO2(2020)
326-
c2050 = row[["c2050"]]
327-
c2100 = row[["c2100"]]
328-
if (year < 2050) {
329-
return((c2050 - c2020)/(2050 - 2020) * (year - 2020) + c2020)
330-
} else {
331-
return((c2100 - c2050)/(2100 - 2050) * (year - 2050) + c2050)
332-
}
323+
RCP_string = paste0("RCP", RCP)
324+
row_selector = cCO2_coefficients[["order"]] == 3
325+
row_selector = row_selector & cCO2_coefficients[["RCP"]] == RCP_string
326+
row = cCO2_coefficients[row_selector, ]
327+
res = row[["a3"]]*year^3 +
328+
row[["a2"]]*year^2 +
329+
row[["a1"]]*year +
330+
row[["a0"]]
331+
return(res)
333332
}
334333
}
335334
),
335+
336336
private = list(
337337
RCP = "2.6",
338-
cCO2_table = data.frame(RCP = c("2.6", "4.5", "8.5"),
339-
c2050 = c(450, 500, 550),
340-
c2100 = c(420, 600, 900))
338+
allowed_RCPs = c("2.6", "4.5", "8.5")
341339
)
342340
)

data-raw/IPCC_CO2_concentration.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library(usethis)
2+
cCO2_coefficients = read.csv("inst/extdata/IPCC_CO2_concentration.csv")
3+
usethis::use_data(cCO2_coefficients)

data/cCO2_coefficients.rda

546 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
order,RCP,a3,a2,a1,a0
2+
2,RCP2.6,0,-0.0198632946998996,81.8862194078263,-83949.6436918251
3+
2,RCP4.5,0,-0.0130613032884067,55.3716644757848,-58136.8986124938
4+
2,RCP6.0,0,0.0165884691095227,-64.9708171781507,63959.1605297345
5+
2,RCP8.5,0,0.0444312061725033,-176.484106167858,175614.278395903
6+
3,RCP2.6,0.000145298883194069,-0.913314482967777,1912.91709994921,-1334602.40391603
7+
3,RCP4.5,-0.00022427439053681,1.36601482116832,-2770.89462030362,1872293.53145368
8+
3,RCP6.0,-2.7338283163742E-05,0.18469314438927,-409.483036359746,299272.044888644
9+
3,RCP8.5,-2.09876022881761E-05,0.173485179548328,-440.966165860248,356263.99954439

man/WeatherData.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/cCO2_coefficients.Rd

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)