Created
October 22, 2025 22:35
-
-
Save oousmane/759a2d7f7fe95f9b21bc695faad9a1d5 to your computer and use it in GitHub Desktop.
Calculates the radiative forcing in W m-2 based on changes in CO2 concentration #' using the formula from Myrhe et al. (1998).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Calculate Radiative Forcing from CO2 Concentration | |
| #' | |
| #' Calculates the radiative forcing in W m-2 based on changes in CO2 concentration | |
| #' using the formula from Myrhe et al. (1998). | |
| #' | |
| #' The radiative forcing is calculated using the equation: | |
| #' \deqn{\Delta F = 5.35 \times \ln(C/C_0)}{ΔF = 5.35 * ln(C/C0)} | |
| #' | |
| #' @param C numeric vector. Current CO2 concentration in ppm. | |
| #' @param C0 numeric. Reference CO2 concentration in ppm. Default is 280 ppm | |
| #' (pre-industrial level). Can be a single value or vector of same length as C. | |
| #' | |
| #' @return numeric vector. Radiative forcing in W m-2. | |
| #' | |
| #' @details | |
| #' The function is vectorized and works with multiple CO2 values. | |
| #' All input values must be positive. | |
| #' | |
| #' @references | |
| #' Myrhe, G., Highwood, E. J., Shine, K. P., & Stordal, F. (1998). | |
| #' New estimates of radiative forcing due to well mixed greenhouse gases. | |
| #' \emph{Geophysical Research Letters}, 25(14), 2715-2718. | |
| #' \doi{10.1029/98GL01908} | |
| #' | |
| #' @examples | |
| #' # Current CO2 levels (420 ppm) vs pre-industrial (280 ppm) | |
| #' radiative_forcing(420, C0 = 280) | |
| #' | |
| #' # Doubled CO2 concentration | |
| #' radiative_forcing(560, C0 = 280) | |
| #' | |
| #' # Multiple CO2 levels (vectorized) | |
| #' radiative_forcing(c(350, 400, 450, 500, 550), C0 = 280) | |
| #' | |
| #' @export | |
| radiative_forcing <- function(C, C0 = 280) { | |
| # Input validation | |
| if (!is.numeric(C) || !is.numeric(C0)) { | |
| stop("C and C0 must be numeric values") | |
| } | |
| if (any(C0 <= 0) || any(C <= 0)) { | |
| stop("C and C0 must be positive values") | |
| } | |
| # Calculate radiative forcing using Myrhe et al. (1998) formula | |
| delta_F <- 5.35 * log(C / C0) | |
| return(delta_F) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment