JGCRI / hector

The Hector Simple Climate Model
http://jgcri.github.io/hector/
GNU General Public License v3.0
111 stars 47 forks source link

Honor ocean preindustrial C values in INI file or via R #666

Closed bpbond closed 1 year ago

bpbond commented 1 year ago

The model now creates default values for surface (both HL and LL) and intermediate + deep ocean carbon in ocean_component::init(), but it accepts and respects those data from INI files and/or R.

This PR adds functionality but shouldn't change any science results.

Via INI files:

ini

Via R:

library(hector)
hc <- newcore("inst/input/hector_ssp245.ini")
fetchvars(hc, NA, OCEAN_PREIND_C_ID())

             scenario year           variable value units
1 Unnamed Hector core   NA preind_interdeep_c 37100  Pg C

run(hc)
original <- fetchvars(hc, 1750:2300)
original$which <- "original"

setvar(hc, NA, OCEAN_PREIND_C_ID(), 38100, "Pg C")
fetchvars(hc, NA, OCEAN_PREIND_C_ID())

             scenario year           variable value units
1 Unnamed Hector core   NA preind_interdeep_c 38100  Pg C

reset(hc)
run(hc)

changed <- fetchvars(hc, 1750:2300)
changed$which <- "changed"
shutdown(hc)

library(ggplot2)
ggplot(rbind(original, changed), aes(year, value, color = which)) + geom_line() + facet_wrap(~variable, scales="free")

R

One thing to note

Because of the logic of ocean_component::prepareToRun(), it was easiest to allow the user to set the preindustrial values of total surface and total intermediate + deep — NOT the individual high lat, low lat, intermediate, deep. As a result you can read the latter from R but you can't write them.

Closes #530

bpbond commented 1 year ago

@kdorheim Ah, thanks! Ocean parameters added to unitstable in e6f20d43.