Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion data-raw/input_params.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ocean,twi,n,n,y,1.25E+07,m3 s-1,Ocean warm-intermediate exchange
ocean,tid,n,n,y,2.00E+08,m3 s-1,Ocean intermediate-deep exchange
ocean,preind_surface_c,n,n,n,900,Pg C,Initial surface ocean carbon
ocean,preind_interdeep_c,n,n,n,37100,Pg C,Initial intermediate + deep ocean carbon
simpleNbox,atmos_co2,n,n,y,588.071,Pg C,Initial atmospheric CO2
simpleNbox,C0,n,n,y,277.15,Pg C,Initial atmospheric C pool
simpleNbox,pf.veg_c,y,n,n,55,Pg C,Initial vegetation C pool
simpleNbox,nonpf.veg_c,y,n,n,495,Pg C,Initial vegetation C pool
Expand Down
Binary file modified data/inputstable.rda
Binary file not shown.
5 changes: 4 additions & 1 deletion inst/include/csv_table_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class CSVTableReader {
//! Current line (that has just been read)
int lineNum;

// Helper function to find next non-commented line
//! Helper function to find next non-commented line
std::string csv_getline();

//! Helper function that reads the header row and returns all column names as a vector
std::vector<std::string> read_header();
};

} // namespace Hector
Expand Down
1 change: 0 additions & 1 deletion inst/input/hector_picontrol.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6, CO2 radiative forcing question is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011

Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp119.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp126.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp245.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp370.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp434.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp460.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp534-over.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
3 changes: 1 addition & 2 deletions inst/input/hector_ssp585.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
; - the nppv, nppd, and litterd partitioning parameters
; - beta and q10_rh

atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
Expand Down Expand Up @@ -180,7 +179,7 @@ RF_misc[1750]=0
;------------------------------------------------------------------------
[temperature]
S=3.0 ; equilibrium climate sensitivity for 2xCO2 degC (A.4.4 of IPCC AR6)
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
diff=1.042 ; ocean heat diffusivity, cm2/s calibrated to historical observations see PR 789 for details
qco2=3.75 ; 2×CO2 RF (7.3.2 of IPCC AR6)

; Optional global temperature constraint
Expand Down
4 changes: 2 additions & 2 deletions scripts/leeyabot.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ oldnew_commit <- unique(oldnew_data$commit)


# Read in the comparison data associated with the official releases minted on Zenodo
read.csv("https://zenodo.org/records/13286176/files/leeyabot-data.csv?download=1") %>%
read.csv("https://zenodo.org/records/17458844/files/leeyabot-data.csv?download=1") %>%
filter(variable %in% vars) ->
zenodo_data

#TODO eventually we will probably need the ability to determine what the most recent
# release version is since the zenodo archive might include results from multiple
zenodo_data %>%
filter(version == "3.2.0") ->
filter(version == "3.5.0") ->
release_data

# Save oldnew version and commit tag
Expand Down
60 changes: 18 additions & 42 deletions src/csv_outputstream_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ CSVOutputStreamVisitor::CSVOutputStreamVisitor(ostream &outputStream,
current_date = 0;
datestring = "";
spinupstring = "";
csvFile.precision(15);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -109,18 +110,6 @@ void CSVOutputStreamVisitor::visit(Core *c) {
core = c;
}

// TODO: consolidate these macros into the two MESSAGE ones,
// and shift string literals to D_xxxx definitions

// Macro to send a variable with associated unitval units to some output stream
// Takes s (stream), c (component), xname (variable name), x (output variable)
#define STREAM_UNITVAL(s, c, xname, x) \
{ \
s << linestamp() << c->getComponentName() << DELIMITER << xname \
<< DELIMITER << x.value(x.units()) << DELIMITER << x.unitsName() \
<< std::endl; \
}

// Macro to send a variable with associated unitval units to some output stream
// This uses new sendMessage interface in imodel_component
// Takes s (stream), c (component), xname (variable name)
Expand All @@ -146,7 +135,6 @@ void CSVOutputStreamVisitor::visit(Core *c) {
void CSVOutputStreamVisitor::visit(ForcingComponent *c) {
if (!core->outputEnabled(c->getComponentName()))
return;
streamsize oldPrecision = csvFile.precision(4);

if (c->currentYear < c->baseyear)
return;
Expand All @@ -155,10 +143,9 @@ void CSVOutputStreamVisitor::visit(ForcingComponent *c) {

// Walk through the forcings map, outputting everything
for (auto f : forcings) {
STREAM_UNITVAL(csvFile, c, f.first, f.second);
STREAM_MESSAGE_DATE(csvFile, c, f.first, current_date);
}

csvFile.precision(oldPrecision);
}

//------------------------------------------------------------------------------
Expand All @@ -171,11 +158,11 @@ void CSVOutputStreamVisitor::visit(SimpleNbox *c) {
// Note if there are multiple biomes, these values will be totals, summed
// across all biomes
STREAM_MESSAGE(csvFile, c, D_NBP);
STREAM_UNITVAL(csvFile, c, D_NPP, c->final_npp[SNBOX_DEFAULT_BIOME]);
STREAM_UNITVAL(csvFile, c, D_RH, c->final_rh[SNBOX_DEFAULT_BIOME]);
STREAM_UNITVAL(csvFile, c, D_RH_DETRITUS, c->final_rh_detritus[SNBOX_DEFAULT_BIOME]);
STREAM_UNITVAL(csvFile, c, D_RH_SOIL, c->final_rh_soil[SNBOX_DEFAULT_BIOME]);
STREAM_UNITVAL(csvFile, c, D_RH_CH4, c->final_rh[SNBOX_DEFAULT_BIOME]);
STREAM_MESSAGE(csvFile, c, D_NPP);
STREAM_MESSAGE(csvFile, c, D_RH);
STREAM_MESSAGE(csvFile, c, D_RH_DETRITUS);
STREAM_MESSAGE(csvFile, c, D_RH_SOIL);
STREAM_MESSAGE(csvFile, c, D_RH_CH4);
STREAM_MESSAGE_DATE(csvFile, c, D_CO2_CONC, current_date);
STREAM_MESSAGE(csvFile, c, D_ATMOSPHERIC_CO2);
STREAM_MESSAGE(csvFile, c, D_ATMOSPHERIC_C_RESIDUAL);
Expand All @@ -192,28 +179,17 @@ void CSVOutputStreamVisitor::visit(SimpleNbox *c) {
SimpleNbox::fluxpool_stringmap::const_iterator it;
for (auto b : c->veg_c) {
std::string biome = b.first;
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_NPP,
c->final_npp[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_RH,
c->final_rh[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_RH_CH4,
c->RH_ch4[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_VEGC,
c->veg_c[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_DETRITUSC,
c->detritus_c[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_SOILC,
c->soil_c[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_PERMAFROSTC,
c->permafrost_c[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_THAWEDPC,
c->thawed_permafrost_c[biome]);
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_F_FROZEN,
unitval(c->f_frozen[biome], U_UNITLESS));
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_TEMPFERTD,
unitval(c->tempfertd[biome], U_UNITLESS));
STREAM_UNITVAL(csvFile, c, biome + SNBOX_PARSECHAR + D_TEMPFERTS,
unitval(c->tempferts[biome], U_UNITLESS));
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_NPP);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_RH);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_RH_CH4);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_VEGC);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_DETRITUSC);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_SOILC);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_PERMAFROSTC);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_THAWEDPC);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_F_FROZEN);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_TEMPFERTD);
STREAM_MESSAGE(csvFile, c, biome + SNBOX_PARSECHAR + D_TEMPFERTS);
}
}
}
Expand Down
55 changes: 41 additions & 14 deletions src/csv_table_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma clang diagnostic pop

#include <boost/algorithm/string/split.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <errno.h>

Expand All @@ -32,6 +33,8 @@
namespace Hector {

using namespace std;
using CsvTok = boost::tokenizer<boost::escaped_list_separator<char>>;


//------------------------------------------------------------------------------
/*! \brief Constructor
Expand Down Expand Up @@ -91,6 +94,33 @@ string CSVTableReader::csv_getline() {
return s;
}

//------------------------------------------------------------------------------
/*! \brief Helper function
*
* Read in and format the header of a hector input csv table.
*/
std::vector<std::string> Hector::CSVTableReader::read_header() {
using namespace boost;

// Skip all the comments at the start of the hector CSV input table
std::string line = csv_getline();
H_ASSERT(!line.empty(), "Header line is empty");

// Parse variable names from the CSV
std::vector<std::string> headerRow;
CsvTok tok(line);
headerRow.assign(tok.begin(), tok.end());

// Tim any whitespace included in the header
for (auto& colName : headerRow) {
trim(colName);
}

return headerRow;
}



//------------------------------------------------------------------------------
/*! \brief Process the CSV file looking for the given varName and route the data
* into the core.
Expand Down Expand Up @@ -129,21 +159,18 @@ void CSVTableReader::process(Core *core, const string &componentName,

// read the header line and attempt to find varName. The first column is
// not considered because that should be the index column.
line = csv_getline();
H_ASSERT(!line.empty(), "line empty");
split(row, line, is_any_of(","));
// const int headerRowSize = row.size();
for (size_t col = 1; col < row.size() && columnIndex == 0; ++col) {
// ignore white space before comparing variable names
trim(row[col]);
if (row[col] == varName) {
columnIndex = col;
row = read_header();

for (size_t col = 1; col < row.size(); ++col) {
if (row[col] == varName) {
columnIndex = col;
break;
}
}
if (columnIndex == 0) {
H_THROW("Could not find a column for " + varName +
" in " + fileName);
}
}
if (columnIndex == 0) {
H_THROW("Could not find a column for " + varName + " in " + fileName +
" header=" + line);
}

// we are all set to process the table
// note that getline sets the fail bit when it hits eof which is not what
Expand Down
Loading
Loading