Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
91f9069
documenation change
kdorheim Dec 26, 2025
f930ba4
temporarily commit these debugging changes
kdorheim Dec 26, 2025
6a1c706
change molar mass to unitval
kdorheim Dec 26, 2025
a3b9f8c
remove the accidental commits
kdorheim Dec 26, 2025
83624a0
ignore the output csv files
kdorheim Dec 26, 2025
4fe9a47
minor inline documeation change
kdorheim Dec 26, 2025
0e05377
simplify the rf calculation
kdorheim Dec 27, 2025
886169c
remove the time step
kdorheim Dec 27, 2025
1538c20
makign dec set up short
kdorheim Dec 27, 2025
eb02d30
saving wip
kdorheim Jan 3, 2026
aae70aa
simplify forcing componet
kdorheim Jan 3, 2026
0bf67ff
swtich from macros to defined constants
kdorheim Jan 3, 2026
4a2f4d4
switch RF halocarbon calls
kdorheim May 22, 2026
47069b8
update halocarbon params
kdorheim May 23, 2026
8c00f04
Merge branch 'dev' into halocarb_fix
kdorheim May 23, 2026
f43d23c
revert accidental commits
kdorheim May 26, 2026
761dd3d
feedback from Steve
kdorheim Jul 17, 2026
dbb5263
update old new test data
kdorheim Jul 17, 2026
895fce3
Merge branch 'halocarb_fix' of https://github.com/JGCRI/hector into h…
kdorheim Jul 17, 2026
df6b1bb
remove output csv files from git
kdorheim Jul 17, 2026
e78cf43
add the CH3CCl3 constraint and fix the halocarbon emission units in t…
kdorheim Jul 17, 2026
ad8dcdd
fix the typo in the HFC245fa concentration constraint
kdorheim Jul 17, 2026
3bb65fc
fix rounding error on physical constatnt
kdorheim Aug 5, 2026
8b6987c
add some helper functions that list possible halocarbon outputs and i…
kdorheim Aug 5, 2026
2f72e66
fix internal pacakge data and add testing also update the get units t…
kdorheim Aug 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ Collate:
'hector.R'
'messages.R'
'units.R'
'zzz.R'
VignetteBuilder: knitr
Config/Needs/website: kableExtra, nleqslv
RoxygenNote: 7.3.2
SystemRequirements: GNU make
URL: https://github.com/JGCRI/hector, https://jgcri.github.io/hector/
BugReports: https://github.com/JGCRI/hector/issues
Language: en-US
Config/roxygen2/version: 8.1.0
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
S3method(format,hcore)
S3method(print,hcore)
export(AERO_SCALE)
export(ALL_HALOCARBON_CONCENTRATIONS)
export(ALL_HALOCARBON_CONSTRAINTS)
export(ALL_HALOCARBON_EMISSIONS)
export(ALL_HALOCARBON_RF)
export(ALL_VARS)
export(ATMOSPHERIC_CO2)
export(BETA)
Expand Down
8 changes: 0 additions & 8 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,6 @@ RF_MISC <- function() {
.Call('_hector_RF_MISC', PACKAGE = 'hector')
}

RFADJ_PREFIX <- function() {
.Call('_hector_RFADJ_PREFIX', PACKAGE = 'hector')
}

RF_PREFIX <- function() {
.Call('_hector_RF_PREFIX', PACKAGE = 'hector')
}

#' @describeIn haloforcings Radiative forcing due to CF4
#' @export
RF_CF4 <- function() {
Expand Down
4 changes: 0 additions & 4 deletions R/aadoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,3 @@ NULL
#' }
"fxntable"

#' A vector containing all the hector output names.
#'
#' @format A vector of length 82.
"all_vars"
98 changes: 88 additions & 10 deletions R/fxns.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#' getfxn("beta")
#' getfxn("q10_rh")
getfxn <- function(str) {
rows <- match(str, hector::fxntable$string)
rslt <- hector::fxntable$fxn[rows]
if (any(is.na(rows))) {
warning(
"Functions for the following are not found: ",
paste(str[is.na(rslt)], collapse = ", ")
)
}
as.character(rslt)
rows <- match(str, hector::fxntable$string)
rslt <- hector::fxntable$fxn[rows]
if (any(is.na(rows))) {
warning(
"Functions for the following are not found: ",
paste(str[is.na(rslt)], collapse = ", ")
)
}
as.character(rslt)
}


Expand All @@ -37,5 +37,83 @@ getfxn <- function(str) {
#' print(out)
#' }
ALL_VARS <- function() {
hector::all_vars
getFromNamespace("all_vars", "hector")
}

#' Get all of the possible Hector halocarbon concentrations
#'
#' This function returns a vector of the possible hector halocarbon concentrations
#' that can be accessed with \code{\link{fetchvars}}.
#' @return Character vector of variable names.
#' @export
#' @family outputs
#' @examples
#' \dontrun{
#' ini <- system.file(package = "hector", "input/hector_ssp245.ini")
#' hc <- newcore(ini)
#' run(hc)
#' out <- fetchvars(core = hc, dates = 1900:2100, vars = ALL_HALOCARBON_CONCENTRATIONS())
#' print(out)
#' }
ALL_HALOCARBON_CONCENTRATIONS <- function() {
getFromNamespace("halo_conc", "hector")
}


#' Get all of the possible Hector halocarbon emissions
#'
#' This function returns a vector of the possible hector halocarbon emissions
#' that can be accessed with \code{\link{fetchvars}} or set with \code{\link{setvar}}.
#' @return Character vector of variable names.
#' @export
#' @family haloemiss
#' @examples
#' \dontrun{
#' ini <- system.file(package = "hector", "input/hector_ssp245.ini")
#' hc <- newcore(ini)
#' run(hc)
#' out <- fetchvars(core = hc, dates = 1900:2100, vars = ALL_HALOCARBON_EMISSIONS())
#' print(out)
#' }
ALL_HALOCARBON_EMISSIONS <- function() {
getFromNamespace("halo_emiss", "hector")
}


#' Get all of the possible Hector halocarbon constraints
#'
#' This function returns a vector of the possible hector halocarbon constraints
#' that can be accessed with \code{\link{fetchvars}} or set with \code{\link{setvar}}.
#' @return Character vector of variable names.
#' @export
#' @family outputs, inputs
#' @examples
#' \dontrun{
#' ini <- system.file(package = "hector", "input/hector_ssp245.ini")
#' hc <- newcore(ini)
#' run(hc)
#' out <- fetchvars(core = hc, dates = 1900:2100, vars = ALL_HALOCARBON_CONSTRAINTS())
#' print(out)
#' }
ALL_HALOCARBON_CONSTRAINTS <- function() {
getFromNamespace("halo_constraints", "hector")
}

#' Get all of the possible Hector halocarbon radiative forcings
#'
#' This function returns a vector of the possible hector halocarbon forcings
#' that can be accessed with \code{\link{fetchvars}}.
#' @return Character vector of variable names.
#' @export
#' @family outputs
#' @examples
#' \dontrun{
#' ini <- system.file(package = "hector", "input/hector_ssp245.ini")
#' hc <- newcore(ini)
#' run(hc)
#' out <- fetchvars(core = hc, dates = 1900:2100, vars = ALL_HALOCARBON_RF())
#' print(out)
#' }
ALL_HALOCARBON_RF <- function() {
getFromNamespace("halo_rf", "hector")
}
3 changes: 0 additions & 3 deletions R/messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ fetchvars <- function(core, dates, vars = NULL, scenario = NULL) {
sendmessage(core, GETDATA(), v, dates, NA, "")
})
)
## Fix the variable name for the adjusted halocarbon forcings so that they are
## consistent with other forcings.
rslt$variable <- sub(paste0("^", RFADJ_PREFIX()), RF_PREFIX(), rslt$variable)
cols <- names(rslt)
rslt$scenario <- scenario
## reorder the columns to put the scenario name first
Expand Down
Binary file added R/sysdata.rda
Binary file not shown.
7 changes: 7 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Silence package checks
utils::globalVariables(c(
"halo_conc",
"halo_constraints",
"halo_emiss",
"halo_rf"
))
17 changes: 0 additions & 17 deletions data-raw/all_hector_vars.R

This file was deleted.

32 changes: 32 additions & 0 deletions data-raw/internal_pkgdata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generate the strings that are used in the ALL_OUTPUT function.
# This script does require that an output stream has already been generated
# from the command line.


file <- list.files(path = "output", pattern = "outputstream_", full.names = TRUE)
stopifnot("need to generate outputstream file" = length(file) > 0)

dat <- read.csv(file = file[[1]], comment.char = "#")

# Extract all of the halocarbon base names.
componet_names <- unique(dat$component)
halo_base_names <- gsub(x = componet_names[grepl(pattern = "halocarbon", x = componet_names)],
pattern = "_halocarbon", replacement = "")

# Format the halocarbon emissions, constraints, concentrations, and forcings
# helper vectors.
halo_emiss <- paste0(halo_base_names, "_emissions")
halo_constraints <- paste0(halo_base_names, "_constrain")
halo_conc <- paste0(halo_base_names, "_concentration")
halo_rf <- paste0("RF_", halo_base_names)

all_vars <- unique(c(dat$variable, halo_conc, halo_rf))
all_vars <- all_vars[!all_vars %in% c(
"hc_concentration", "HL_downwelling", "HL_OmegaAr", "LL_OmegaAr",
"HL_OmegaCa", "LL_OmegaCa", "atmos_c_residual", "HL_Revelle", "HL_Revelle",
"LL_Revelle", "slr", "slr_no_ice", "sl_rc", "sl_rc_no_ice"
)]


usethis::use_data(halo_emiss, all_vars, halo_constraints, halo_conc, halo_rf, internal = TRUE, overwrite = TRUE)

2 changes: 1 addition & 1 deletion data-raw/lookup-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lines <- readLines("./src/rcpp_constants.cpp")
# Specific functions to exclude
# TODO is there a way to make this not hard coded?
lines <- lines[!grepl(
pattern = "GETDATA|SETDATA|BIOME_SPLIT_CHAR|RFADJ_PREFIX|RF_PREFIX",
pattern = "GETDATA|SETDATA|BIOME_SPLIT_CHAR|RF_PREFIX",
x = lines
)]

Expand Down
30 changes: 7 additions & 23 deletions data-raw/units-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,15 @@ temp_uni <- c(
misc_emiss_vars <- c(EMISSIONS_BC(), EMISSIONS_OC(), EMISSIONS_NH3())
misc_emiss_uni <- c("Tg", "Tg", "Tg")

haloemis_vars <- c(
EMISSIONS_CF4(), EMISSIONS_C2F6(), EMISSIONS_HFC23(),
EMISSIONS_HFC32(), EMISSIONS_HFC4310(), EMISSIONS_HFC125(),
EMISSIONS_HFC134A(), EMISSIONS_HFC143A(), EMISSIONS_HFC227EA(),
EMISSIONS_HFC245FA(), EMISSIONS_SF6(), EMISSIONS_CFC11(),
EMISSIONS_CFC12(), EMISSIONS_CFC113(), EMISSIONS_CFC114(),
EMISSIONS_CFC115(), EMISSIONS_CCL4(), EMISSIONS_CH3CCL3(),
EMISSIONS_HCFC22(), EMISSIONS_HCFC141B(), EMISSIONS_HCFC142B(),
EMISSIONS_HALON1211(), EMISSIONS_HALON1301(),
EMISSIONS_HALON2402(), EMISSIONS_CH3CL(), EMISSIONS_CH3BR()
)
haloemis <- ALL_HALOCARBON_EMISSIONS()
haloemis_uni <- "Gg"

haloconstrain_vars <- c(
CF4_CONSTRAIN(), C2F6_CONSTRAIN(), HFC23_CONSTRAIN(),
HFC32_CONSTRAIN(), HFC4310_CONSTRAIN(), HFC125_CONSTRAIN(),
HFC134A_CONSTRAIN(), HFC143A_CONSTRAIN(), HFC227EA_CONSTRAIN(),
HFC245FA_CONSTRAIN(), SF6_CONSTRAIN(), CFC11_CONSTRAIN(),
CFC12_CONSTRAIN(), CFC113_CONSTRAIN(), CFC114_CONSTRAIN(),
CFC115_CONSTRAIN(), CCL4_CONSTRAIN(), CH3CCL3_CONSTRAIN(),
HCFC22_CONSTRAIN(), HCFC141B_CONSTRAIN(), HCFC142B_CONSTRAIN(),
HALON1211_CONSTRAIN(), HALON1301_CONSTRAIN(), HALON2402_CONSTRAIN(),
CH3CL_CONSTRAIN(), CH3BR_CONSTRAIN(), "HFC245_constrain"
)
haloconstrain_vars <- ALL_HALOCARBON_CONSTRAINTS()
haloconstrain_uni <- "pptv"

haloconc_vars <- ALL_HALOCARBON_CONCENTRATIONS()
haloconc_uni <- haloconstrain_uni

halodeltas_vars <- c(
DELTA_CF4(), DELTA_C2F6(), DELTA_HFC23(), DELTA_HFC32(),
DELTA_HFC4310(), DELTA_HFC125(), DELTA_HFC134A(), DELTA_HFC143A(),
Expand All @@ -104,8 +87,9 @@ unitstable <- rbind(
data.frame(variable = forcing_vars, units = forcing_uni),
data.frame(variable = temp_vars, units = temp_uni),
data.frame(variable = misc_emiss_vars, units = misc_emiss_uni),
data.frame(variable = haloemis_vars, units = haloemis_uni),
data.frame(variable = haloemis, units = haloemis_uni),
data.frame(variable = haloconstrain_vars, units = haloconstrain_uni),
data.frame(variable = haloconc_vars, units = haloconc_uni),
data.frame(variable = halodeltas_vars, units = halodeltas_uni),
data.frame(variable = misc_var, units = misc_uni)
)
Expand Down
Binary file removed data/all_vars.rda
Binary file not shown.
Binary file modified data/unitstable.rda
Binary file not shown.
61 changes: 31 additions & 30 deletions inst/include/component_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
#define D_VOLCANIC_SCALE "vol_scalar"

// halocarbon components
// These capabilities allow a caller to fetch the
// adjusted values from the forcing component.
#define D_RF_CF4 D_RF_PREFIX CF4_COMPONENT_BASE
#define D_RF_C2F6 D_RF_PREFIX C2F6_COMPONENT_BASE
#define D_RF_HFC23 D_RF_PREFIX HFC23_COMPONENT_BASE
Expand Down Expand Up @@ -96,37 +98,36 @@
#define D_RF_CH3Cl D_RF_PREFIX CH3Cl_COMPONENT_BASE
#define D_RF_CH3Br D_RF_PREFIX CH3Br_COMPONENT_BASE

// Adjusted (i.e., relative) halocarbon forcings
// Unadjusted halocarbon forcings
// Forcings are tracked relative to the base year forcings, but the
// halocarbon components don't know that. These capabilities allow
// a caller to fetch the adjusted values from the forcing component.
#define D_RFADJ_PREFIX "Fadj"
#define D_RFADJ_CF4 D_RFADJ_PREFIX CF4_COMPONENT_BASE
#define D_RFADJ_C2F6 D_RFADJ_PREFIX C2F6_COMPONENT_BASE
#define D_RFADJ_HFC23 D_RFADJ_PREFIX HFC23_COMPONENT_BASE
#define D_RFADJ_HFC32 D_RFADJ_PREFIX HFC32_COMPONENT_BASE
#define D_RFADJ_HFC4310 D_RFADJ_PREFIX HFC4310_COMPONENT_BASE
#define D_RFADJ_HFC125 D_RFADJ_PREFIX HFC125_COMPONENT_BASE
#define D_RFADJ_HFC134a D_RFADJ_PREFIX HFC134a_COMPONENT_BASE
#define D_RFADJ_HFC143a D_RFADJ_PREFIX HFC143a_COMPONENT_BASE
#define D_RFADJ_HFC227ea D_RFADJ_PREFIX HFC227ea_COMPONENT_BASE
#define D_RFADJ_HFC245fa D_RFADJ_PREFIX HFC245fa_COMPONENT_BASE
#define D_RFADJ_SF6 D_RFADJ_PREFIX SF6_COMPONENT_BASE
#define D_RFADJ_CFC11 D_RFADJ_PREFIX CFC11_COMPONENT_BASE
#define D_RFADJ_CFC12 D_RFADJ_PREFIX CFC12_COMPONENT_BASE
#define D_RFADJ_CFC113 D_RFADJ_PREFIX CFC113_COMPONENT_BASE
#define D_RFADJ_CFC114 D_RFADJ_PREFIX CFC114_COMPONENT_BASE
#define D_RFADJ_CFC115 D_RFADJ_PREFIX CFC115_COMPONENT_BASE
#define D_RFADJ_CCl4 D_RFADJ_PREFIX CCl4_COMPONENT_BASE
#define D_RFADJ_CH3CCl3 D_RFADJ_PREFIX CH3CCl3_COMPONENT_BASE
#define D_RFADJ_HCFC22 D_RFADJ_PREFIX HCFC22_COMPONENT_BASE
#define D_RFADJ_HCFC141b D_RFADJ_PREFIX HCFC141b_COMPONENT_BASE
#define D_RFADJ_HCFC142b D_RFADJ_PREFIX HCFC142b_COMPONENT_BASE
#define D_RFADJ_halon1211 D_RFADJ_PREFIX halon1211_COMPONENT_BASE
#define D_RFADJ_halon1301 D_RFADJ_PREFIX halon1301_COMPONENT_BASE
#define D_RFADJ_halon2402 D_RFADJ_PREFIX halon2402_COMPONENT_BASE
#define D_RFADJ_CH3Cl D_RFADJ_PREFIX CH3Cl_COMPONENT_BASE
#define D_RFADJ_CH3Br D_RFADJ_PREFIX CH3Br_COMPONENT_BASE
// halocarbon components don't know that.
#define D_RFUNADJ_PREFIX "RF_unadj"
#define D_RFUNADJ_CF4 D_RFUNADJ_PREFIX CF4_COMPONENT_BASE
#define D_RFUNADJ_C2F6 D_RFUNADJ_PREFIX C2F6_COMPONENT_BASE
#define D_RFUNADJ_HFC23 D_RFUNADJ_PREFIX HFC23_COMPONENT_BASE
#define D_RFUNADJ_HFC32 D_RFUNADJ_PREFIX HFC32_COMPONENT_BASE
#define D_RFUNADJ_HFC4310 D_RFUNADJ_PREFIX HFC4310_COMPONENT_BASE
#define D_RFUNADJ_HFC125 D_RFUNADJ_PREFIX HFC125_COMPONENT_BASE
#define D_RFUNADJ_HFC134a D_RFUNADJ_PREFIX HFC134a_COMPONENT_BASE
#define D_RFUNADJ_HFC143a D_RFUNADJ_PREFIX HFC143a_COMPONENT_BASE
#define D_RFUNADJ_HFC227ea D_RFUNADJ_PREFIX HFC227ea_COMPONENT_BASE
#define D_RFUNADJ_HFC245fa D_RFUNADJ_PREFIX HFC245fa_COMPONENT_BASE
#define D_RFUNADJ_SF6 D_RFUNADJ_PREFIX SF6_COMPONENT_BASE
#define D_RFUNADJ_CFC11 D_RFUNADJ_PREFIX CFC11_COMPONENT_BASE
#define D_RFUNADJ_CFC12 D_RFUNADJ_PREFIX CFC12_COMPONENT_BASE
#define D_RFUNADJ_CFC113 D_RFUNADJ_PREFIX CFC113_COMPONENT_BASE
#define D_RFUNADJ_CFC114 D_RFUNADJ_PREFIX CFC114_COMPONENT_BASE
#define D_RFUNADJ_CFC115 D_RFUNADJ_PREFIX CFC115_COMPONENT_BASE
#define D_RFUNADJ_CCl4 D_RFUNADJ_PREFIX CCl4_COMPONENT_BASE
#define D_RFUNADJ_CH3CCl3 D_RFUNADJ_PREFIX CH3CCl3_COMPONENT_BASE
#define D_RFUNADJ_HCFC22 D_RFUNADJ_PREFIX HCFC22_COMPONENT_BASE
#define D_RFUNADJ_HCFC141b D_RFUNADJ_PREFIX HCFC141b_COMPONENT_BASE
#define D_RFUNADJ_HCFC142b D_RFUNADJ_PREFIX HCFC142b_COMPONENT_BASE
#define D_RFUNADJ_halon1211 D_RFUNADJ_PREFIX halon1211_COMPONENT_BASE
#define D_RFUNADJ_halon1301 D_RFUNADJ_PREFIX halon1301_COMPONENT_BASE
#define D_RFUNADJ_halon2402 D_RFUNADJ_PREFIX halon2402_COMPONENT_BASE
#define D_RFUNADJ_CH3Cl D_RFUNADJ_PREFIX CH3Cl_COMPONENT_BASE
#define D_RFUNADJ_CH3Br D_RFUNADJ_PREFIX CH3Br_COMPONENT_BASE
#define N_HALO_FORCINGS 26

// halocarbon emissions
Expand Down
2 changes: 1 addition & 1 deletion inst/include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IModelComponent;
*/
class Core : public IVisitable {
public:
Core(Logger::LogLevel loglvl = Logger::DEBUG, bool echotoscreen = true,
Core(Logger::LogLevel loglvl = Logger::DEBUG, bool echotoscreen = true,
bool echotofile = true);
~Core();

Expand Down
4 changes: 2 additions & 2 deletions inst/include/forcing_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class ForcingComponent : public IModelComponent {
Logger logger; //! Logger

static const char
*adjusted_halo_forcings[]; //! Capability strings for halocarbon forcings
*unadjusted_halo_forcings[]; //! Capability strings for unadjusted halocarbon forcings
static const char
*halo_forcing_names[]; //! Internal names of halocarbon forcings
*halo_forcing_names[]; //! Names of adjusted (relative) halocarbon forcings
static std::map<std::string, std::string> forcing_name_map;
};

Expand Down
Loading