Skip to content

Commit

Permalink
Tried optimizing for MVSSE
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrscll committed Jun 25, 2024
1 parent a684a46 commit 1ae22d4
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
48 changes: 48 additions & 0 deletions results/13_alpha_ecs_ohc_mvsse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
parameters values
beta 0.526231809997589
q10_rh 2.31055396561195
diff 1.042
S 2.82788331898928
alpha 1.40507672116753

Objective Function Value: 91.3
Counts: 104
Counts: 104
Convergence: 0
Messages: CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH

CO2 MSE: 3.4
T MSE: 0.102
RMSE: 1.84
CO2 MVSSE: 236
T MVSSE: 37.3
OHC MVSSE: 0.385

***Key Metrics***
TCRE: 1.62
TCR: 1.92

***Historical Warming and ERF***
GSAT Warming: 0.502
Ocean Heat Content Change: 291
Total Aerosol ERF: -1.24
WMGHG ERF: 3.88
Methane ERF: 0.536

***Future Warming***
scenario start end GSAT
ssp119 2021 2040 0.904
ssp119 2041 2060 1.13
ssp119 2081 2100 0.968
ssp126 2021 2040 0.907
ssp126 2041 2060 1.33
ssp126 2081 2100 1.36
ssp245 2021 2040 0.872
ssp245 2041 2060 1.49
ssp245 2081 2100 2.3
ssp370 2021 2040 0.854
ssp370 2041 2060 1.57
ssp370 2081 2100 3.23
ssp585 2021 2040 1.05
ssp585 2041 2060 2.04
ssp585 2081 2100 4.3
96 changes: 96 additions & 0 deletions scripts/alpha_ohc_mvsse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Script for experiment 13
# Script to optimize over T, OHC and CO2 MVSSEs
# Also includes ECS and alpha as params to optimize over
# Uses OHC range from Matilda table rather than manuscript script
# Author: Peter Scully
# Date: 6/25/24

### Constants and Imports ###

# Importing libraries
library(hector)

# Setting up file paths
COMP_DATA_DIR <- file.path(here::here(), "comparison_data")
SCRIPTS_DIR <- file.path(here::here(), "scripts")
RESULTS_DIR <- file.path(here::here(), "results")

CO2_PATH <- file.path(COMP_DATA_DIR,
"Supplementary_Table_UoM_GHGConcentrations-1-1-0_annualmeans_v23March2017.csv")
TEMP_PATH <-
file.path(COMP_DATA_DIR,
"HadCRUT.5.0.2.0.analysis.summary_series.global.annual.csv")

OHC_PATH <- file.path(COMP_DATA_DIR, "OHC_ensemble_Kuhlbrodt_etal_2022.csv")


INI_FILE <- system.file("input/hector_ssp245.ini", package = "hector")
PARAMS <- c(BETA(), Q10_RH(), DIFFUSIVITY(), ECS(), AERO_SCALE())

OUTPUT <- file.path(RESULTS_DIR, "13_alpha_ecs_ohc_mvsse.txt")


source(file.path(SCRIPTS_DIR, "major_functions.R"))

### Getting observational data ###
co2_data <- get_co2_data(CO2_PATH, include_unc = TRUE)
temp_data <- get_temp_data(TEMP_PATH, include_unc = TRUE)
ohc_data <- get_ohc_data(OHC_PATH, include_unc = T)
obs_data <- rbind(co2_data, temp_data, ohc_data)

### Calling optim ###
best_pars <- run_optim(obs_data = obs_data,
ini_file = INI_FILE,
params = PARAMS,
lower = c(0.5 - 0.232, 2.2 - 0.44, 1.16 - 0.118, 2, 0),
upper = c(0.5 + 0.232, 2.2 + 0.44, 1.16 + 0.118, 5, 3),
yrs = 1750:2014,
vars = c(GMST(), CONCENTRATIONS_CO2(), HEAT_FLUX()),
error_fn = mean_T_CO2_OHC_mvsse,
include_unc = T,
method = "L-BFGS-B",
output_file = OUTPUT)

### Outputting individual MSEs ###
hector_data <- run_hector(ini_file = INI_FILE,
params = PARAMS,
vals = best_pars,
yrs = 1750:2014,
vars = c(GMST(), CONCENTRATIONS_CO2(), HEAT_FLUX()))

T_mse <- get_var_mse(obs_data = obs_data,
hector_data = hector_data,
var = GMST(),
yrs = 1850:2014)
CO2_mse <- get_var_mse(obs_data = obs_data,
hector_data = hector_data,
var = CONCENTRATIONS_CO2(),
yrs = c(1750, 1850:2014))

# Getting MVSSEs
T_mvsse <- get_var_mvsse(obs_data = obs_data,
hector_data = hector_data,
var = GMST(),
yrs = 1850:2014,
mse_fn = mvsse)
CO2_mvsse <- get_var_mvsse(obs_data = obs_data,
hector_data = hector_data,
var = CONCENTRATIONS_CO2(),
yrs = c(1750, 1850:2014),
mse_fn = mvsse)
OHC_mvsse <- get_var_mvsse(obs_data = obs_data,
hector_data = hector_data,
var = "OHC",
yrs = 1957:2014,
mse_fn = mvsse)

write_metric("CO2 MSE:", CO2_mse, OUTPUT)
write_metric("T MSE: ", T_mse, OUTPUT)
write_metric("RMSE: ", sqrt(mean(CO2_mse, T_mse)), OUTPUT) # not 100% sure this is how we want to calculate this
write_metric("CO2 MVSSE:", CO2_mvsse, OUTPUT)
write_metric("T MVSSE: ", T_mvsse, OUTPUT)
write_metric("OHC MVSSE:", OHC_mvsse, OUTPUT)
write("", OUTPUT, append = TRUE)

### Outputting table metrics ###
calc_table_metrics(PARAMS, best_pars, OUTPUT)

0 comments on commit 1ae22d4

Please sign in to comment.