scripts/rcmipII/4.create-rcmip_model_reported_metrics.R

## Create the rcmip_model_reported_metrics_test.csv for the RCMIP II submission. 
## See "Model Reported Metrics" on https://pyrcmip.readthedocs.io/en/latest/submitting_results.html. 

devtools::load_all()
renv::restore()
library(hector)

# Define directories. 
BASE_DIR <- here::here()
OUT_DIR  <- file.path(BASE_DIR, 'output', 'rcmipII')
dir.create(OUT_DIR, showWarnings = FALSE)

# Download the posterior results provided from UI collaborators for the zenodo link. 
posterior <- read.csv(url('https://zenodo.org/record/3990501/files/forcing_10k_noSLR_posteriorSamples.csv?download=1'), stringsAsFactors = FALSE)
names(posterior) <- c('S', 'diff', 'alpha')

# Download the example data submission from RCMIPII this will be used to set up 
# the data that will be submitted.
pyrcmip_template <- read.csv(url('https://gitlab.com/rcmip/pyrcmip/-/raw/master/tests/data/rcmip_model_reported_metrics_test.csv?inline=false'), stringsAsFactors = FALSE)

# Create a data frame with the dimensions of the ensemble. 
hector_pyrcmip  <- matrix(nrow = nrow(posterior), ncol = ncol(pyrcmip_template))
hector_pyrcmip <- as.data.frame(hector_pyrcmip) 
names(hector_pyrcmip) <- names(pyrcmip_template)

# Replace the RCMIP name 
names(hector_pyrcmip)[names(hector_pyrcmip) == 'RCMIP.name'] <- 'RCMIP name'

# Fill out the pyrcmip metrics data table. 
hector_pyrcmip$unit <- 'K'
hector_pyrcmip$value <- posterior$S
hector_pyrcmip$ensemble_member <- 0:(nrow(hector_pyrcmip) - 1)
hector_pyrcmip$climate_model <- 'hector'
hector_pyrcmip$`RCMIP name` <- 'Equilibrium Climate Sensitivity'

# Save the csv file. 
write.csv(x = hector_pyrcmip, file = file.path(OUT_DIR, 'rcmip_model_reported_metrics_test.csv'), row.names = FALSE)
ashiklom/hector-rcmip documentation built on Sept. 23, 2020, 11:30 a.m.