Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
lrennels authored Nov 12, 2021
1 parent c40d24c commit 3f88602
Show file tree
Hide file tree
Showing 29 changed files with 463 additions and 463 deletions.
6 changes: 3 additions & 3 deletions examples/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ N = 10000
seed = 350

Random.seed!(seed)
MimiIWG.run_scc_mcs(DICE, gas=:CO2, trials = N)
MimiIWG.run_scc_mcs(DICE, gas=:CO2, trials=N)

Random.seed!(seed)
MimiIWG.run_scc_mcs(FUND, gas=:CO2, trials = N)
MimiIWG.run_scc_mcs(FUND, gas=:CO2, trials=N)

Random.seed!(seed)
MimiIWG.run_scc_mcs(PAGE, gas=:CO2, trials = N)
MimiIWG.run_scc_mcs(PAGE, gas=:CO2, trials=N)
20 changes: 10 additions & 10 deletions examples/other_ghg.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using MimiIWG

#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Deterministic single runs of SC-CH4 and SC-N2O
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

# DICE
scch4 = MimiIWG.compute_scc(DICE, USG1, gas=:CH4, year=2020, discount=0.025)
Expand All @@ -16,19 +16,19 @@ scn2o = MimiIWG.compute_scc(FUND, USG1, gas=:N2O, year=2020, discount=0.025)
scch4 = MimiIWG.compute_scc(PAGE, USG1, gas=:CH4, year=2020, discount=0.025)
scn2o = MimiIWG.compute_scc(PAGE, USG1, gas=:N2O, year=2020, discount=0.025)

#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Full Monte Carlo simulations for SC-CH4 and SC-N2O for each model
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

# DICE
# (will run for all 3 IWG discount rates if none are specified)
MimiIWG.run_scc_mcs(DICE, gas=:CH4, trials=10_000, perturbation_years=[2020], output_dir = "output")
MimiIWG.run_scc_mcs(DICE, gas=:N2O, trials=10_000, perturbation_years=[2020], output_dir = "output")
MimiIWG.run_scc_mcs(DICE, gas=:CH4, trials=10_000, perturbation_years=[2020], output_dir="output")
MimiIWG.run_scc_mcs(DICE, gas=:N2O, trials=10_000, perturbation_years=[2020], output_dir="output")

# FUND
MimiIWG.run_scc_mcs(FUND, gas=:CH4, trials=10_000, perturbation_years=[2020], output_dir = "output")
MimiIWG.run_scc_mcs(FUND, gas=:N2O, trials=10_000, perturbation_years=[2020], output_dir = "output")
MimiIWG.run_scc_mcs(FUND, gas=:CH4, trials=10_000, perturbation_years=[2020], output_dir="output")
MimiIWG.run_scc_mcs(FUND, gas=:N2O, trials=10_000, perturbation_years=[2020], output_dir="output")

# PAGE
MimiIWG.run_scc_mcs(PAGE, gas=:CH4, trials=10_000, perturbation_years=[2020], output_dir = "output")
MimiIWG.run_scc_mcs(PAGE, gas=:N2O, trials=10_000, perturbation_years=[2020], output_dir = "output")
MimiIWG.run_scc_mcs(PAGE, gas=:CH4, trials=10_000, perturbation_years=[2020], output_dir="output")
MimiIWG.run_scc_mcs(PAGE, gas=:N2O, trials=10_000, perturbation_years=[2020], output_dir="output")
2 changes: 1 addition & 1 deletion src/MimiIWG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using MimiDICE2010
using MimiFUND # pinned to version 3.8 in package registration Compat.toml
using MimiPAGE2009
using StatsBase
using XLSX: readxlsx
using XLSX:readxlsx
using CSVFiles
using DataFrames
using Query
Expand Down
18 changes: 9 additions & 9 deletions src/components/IWG_DICE_ScenarioChoice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
scenarios = Index()

# Variables (each one has its value set for the chosen scenario in the first timestep)
l = Variable(index = [time]) # Population
E = Variable(index = [time]) # Total CO2 emissions
forcoth = Variable(index = [time]) # other forcing
al = Variable(index = [time]) # total factor productivity
l = Variable(index=[time]) # Population
E = Variable(index=[time]) # Total CO2 emissions
forcoth = Variable(index=[time]) # other forcing
al = Variable(index=[time]) # total factor productivity
k0 = Variable() # initial capital stock

# The number for which scenario to use
scenario_num = Parameter{Integer}()

# Parameters (each one holds all five scenarios)
l_all = Parameter(index = [time, scenarios])
E_all = Parameter(index = [time, scenarios])
forcoth_all = Parameter(index = [time, scenarios])
al_all = Parameter(index = [time, scenarios])
k0_all = Parameter(index = [scenarios])
l_all = Parameter(index=[time, scenarios])
E_all = Parameter(index=[time, scenarios])
forcoth_all = Parameter(index=[time, scenarios])
al_all = Parameter(index=[time, scenarios])
k0_all = Parameter(index=[scenarios])

function run_timestep(p, v, d, t)
if is_first(t)
Expand Down
2 changes: 1 addition & 1 deletion src/components/IWG_DICE_climatedynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
elseif p.t2xco2 < 0.5
v.TATM[t] = v.TA_eq[t]
else
v.TATM[t] = v.TATM[t - 1] + p.c1 * ((p.FORC[t] - (p.fco22x/p.t2xco2) * v.TATM[t - 1]) - (p.c3 * (v.TATM[t - 1] - v.TOCEAN[t - 1])))
v.TATM[t] = v.TATM[t - 1] + p.c1 * ((p.FORC[t] - (p.fco22x / p.t2xco2) * v.TATM[t - 1]) - (p.c3 * (v.TATM[t - 1] - v.TOCEAN[t - 1])))
end

# Define function for TOCEAN
Expand Down
4 changes: 2 additions & 2 deletions src/components/IWG_DICE_neteconomy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
v.CPC[t] = 1000 * v.C[t] / p.l[t]

# Define function for CPRICE
if t.t==26
if t.t == 26
v.CPRICE[t] = v.CPRICE[t - 1]
else
v.CPRICE[t] = p.pbacktime[t] * 1000 * p.MIU[t] ^ (p.expcost2 - 1)
v.CPRICE[t] = p.pbacktime[t] * 1000 * p.MIU[t]^(p.expcost2 - 1)
end

end
Expand Down
2 changes: 1 addition & 1 deletion src/components/IWG_DICE_radiativeforcing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
MAT_avg = 0.9796 * (p.MAT[t - 1] + p.MAT[t]) / 2
end

v.FORC[t] = p.fco22x * (log((MAT_avg + 0.000001) / 596.4 ) / log(2)) + p.forcoth[t]
v.FORC[t] = p.fco22x * (log((MAT_avg + 0.000001) / 596.4) / log(2)) + p.forcoth[t]

end

Expand Down
44 changes: 22 additions & 22 deletions src/components/IWG_DICE_simple_gas_cycle.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
@defcomp IWG_DICE_simple_gas_cycle begin

# Output: forcing
F_CH4 = Variable(index = [decades]) # Path of CH4 forcing [W/m^2] - decadal time step
F_N2O = Variable(index = [decades]) # Path of N2O forcing [W/m^2] - decadal time step
F_CH4 = Variable(index=[decades]) # Path of CH4 forcing [W/m^2] - decadal time step
F_N2O = Variable(index=[decades]) # Path of N2O forcing [W/m^2] - decadal time step

# Input: emissions
E_CH4A = Parameter(index = [time]) # Annual CH4 emissions
E_N2OA = Parameter(index = [time]) # Annual N2O emissions
E_CH4A = Parameter(index=[time]) # Annual CH4 emissions
E_N2OA = Parameter(index=[time]) # Annual N2O emissions

# Atmospheric concentration dynamics coefficients
delta_ch4 = Parameter(default = 1/12) # Annual rate of decay of CH4 (IPCC FAR)
gamma_ch4 = Parameter(default = 0.3597) # Mass to volume conversion factor [ppb CH4/Mt CH4]
alpha_ch4 = Parameter(default = 0.036) # Radiative forcing parameter (TAR page 358)
delta_n2o = Parameter(default = 1/114) # Rate of decay of N2O (IPCC FAR)
gamma_n2o = Parameter(default = 0.2079) # Mass to volume conversion factor [ppb N2O/Mt N]
alpha_n2o = Parameter(default = 0.12) # Radiative forcing parameter
ipcc_adj = Parameter(default = 1.4) # IPCC AR4 adjustment for tropospheric ozone effect (25%) and stratospheric water vapor effect (15%)

M_pre = Parameter(default = 700) # Pre-industrial CH4 concentrations [ppb](TAR page 358)
N_pre = Parameter(default = 270) # Pre-industrial N2O concentrations [ppb](TAR page 358)
delta_ch4 = Parameter(default=1 / 12) # Annual rate of decay of CH4 (IPCC FAR)
gamma_ch4 = Parameter(default=0.3597) # Mass to volume conversion factor [ppb CH4/Mt CH4]
alpha_ch4 = Parameter(default=0.036) # Radiative forcing parameter (TAR page 358)
delta_n2o = Parameter(default=1 / 114) # Rate of decay of N2O (IPCC FAR)
gamma_n2o = Parameter(default=0.2079) # Mass to volume conversion factor [ppb N2O/Mt N]
alpha_n2o = Parameter(default=0.12) # Radiative forcing parameter
ipcc_adj = Parameter(default=1.4) # IPCC AR4 adjustment for tropospheric ozone effect (25%) and stratospheric water vapor effect (15%)

M_pre = Parameter(default=700) # Pre-industrial CH4 concentrations [ppb](TAR page 358)
N_pre = Parameter(default=270) # Pre-industrial N2O concentrations [ppb](TAR page 358)

M_AA_2005 = Parameter(default = 1774) # 2005 concentration of CH4
N_AA_2005 = Parameter(default = 319) # 2005 concentration of N2O
M_AA_2005 = Parameter(default=1774) # 2005 concentration of CH4
N_AA_2005 = Parameter(default=319) # 2005 concentration of N2O

# Other intermediate variables to calculate
M_AA = Variable(index = [time]) # Atmospheric CH4 concentration (annual)
F_CH4A = Variable(index = [time]) # Contribution of atmospheric CH4 to radiative forcing (annual)
N_AA = Variable(index = [time]) # Atmospheric N2O concentration (annual)
F_N2OA = Variable(index = [time]) # Contribution of atmospheric N2O to radiative forcing (annual)
M_AA = Variable(index=[time]) # Atmospheric CH4 concentration (annual)
F_CH4A = Variable(index=[time]) # Contribution of atmospheric CH4 to radiative forcing (annual)
N_AA = Variable(index=[time]) # Atmospheric N2O concentration (annual)
F_N2OA = Variable(index=[time]) # Contribution of atmospheric N2O to radiative forcing (annual)
pre_f = Variable() # pre-industrial interaction effect

function run_timestep(p, v, d, t)

function f(M_A, N_A)
# calculate the interaction effect on radiative forcing
return 0.47 * log(1 + 2.01 * 10 ^ -5 * (M_A * N_A) ^ 0.75 + 5.31 * 10^-15 * M_A * (M_A * N_A) ^ 1.52)
return 0.47 * log(1 + 2.01 * 10^-5 * (M_A * N_A)^0.75 + 5.31 * 10^-15 * M_A * (M_A * N_A)^1.52)
end

# Calculate the annual atmospheric concentrations
Expand All @@ -45,7 +45,7 @@
v.pre_f = f(p.M_pre, p.N_pre) # only need to calculate this once; used in each timestep below
else
v.M_AA[t] = (1 - p.delta_ch4) * v.M_AA[t - 1] + p.delta_ch4 * p.M_pre + p.gamma_ch4 * p.E_CH4A[t - 1]
v.N_AA[t] = (1 - p.delta_n2o) * v.N_AA[t - 1] + p.delta_n2o * p.N_pre + p.gamma_n2o * (28/44) * p.E_N2OA[t - 1]
v.N_AA[t] = (1 - p.delta_n2o) * v.N_AA[t - 1] + p.delta_n2o * p.N_pre + p.gamma_n2o * (28 / 44) * p.E_N2OA[t - 1]
end

# Calculate the annual forcing
Expand Down
24 changes: 12 additions & 12 deletions src/components/IWG_FUND_ScenarioChoice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
scenarios = Index()

# Variables (each one has its value set for the chosen scenario in the first timestep)
globch4 = Variable(index = [time])
globn2o = Variable(index = [time])
pgrowth = Variable(index = [time, regions])
ypcgrowth = Variable(index = [time, regions])
aeei = Variable(index = [time, regions])
acei = Variable(index = [time, regions])
globch4 = Variable(index=[time])
globn2o = Variable(index=[time])
pgrowth = Variable(index=[time, regions])
ypcgrowth = Variable(index=[time, regions])
aeei = Variable(index=[time, regions])
acei = Variable(index=[time, regions])

# The number for which scenario to use
scenario_num = Parameter{Integer}()

# Parameters (each one holds all five scenarios)
globch4_all = Parameter(index = [time, scenarios])
globn2o_all = Parameter(index = [time, scenarios])
pgrowth_all = Parameter(index = [time, regions, scenarios])
ypcgrowth_all = Parameter(index = [time, regions, scenarios])
aeei_all = Parameter(index = [time, regions, scenarios])
acei_all = Parameter(index = [time, regions, scenarios])
globch4_all = Parameter(index=[time, scenarios])
globn2o_all = Parameter(index=[time, scenarios])
pgrowth_all = Parameter(index=[time, regions, scenarios])
ypcgrowth_all = Parameter(index=[time, regions, scenarios])
aeei_all = Parameter(index=[time, regions, scenarios])
acei_all = Parameter(index=[time, regions, scenarios])

function run_timestep(p, v, d, t)
if is_first(t)
Expand Down
22 changes: 11 additions & 11 deletions src/components/IWG_FUND_impactsealevelrise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@

imigrate = Variable(index=[regions,regions])

incdens = Parameter(default = 0.000635) # Normalization income density
emcst = Parameter(default = 3) # emigration loss benchmark value
immcst = Parameter(default = 0.4) # immigration loss benchmark
dvydl = Parameter(default = 1) # income density elasticity of dryland value
wvel = Parameter(default = 1.16) # wetland value income elasticity
wvbm = Parameter(default = 0.00588) # wetland value benchmark value
slrwvpopdens0 = Parameter(default = 27.5937717888728) # wetland value income normalization value
wvpdl = Parameter(default = 0.47)
wvsl = Parameter(default = -0.11)
dvbm = Parameter(default = 0.004) # dryland value benchmark value
slrwvypc0 = Parameter(default = 25000)
incdens = Parameter(default=0.000635) # Normalization income density
emcst = Parameter(default=3) # emigration loss benchmark value
immcst = Parameter(default=0.4) # immigration loss benchmark
dvydl = Parameter(default=1) # income density elasticity of dryland value
wvel = Parameter(default=1.16) # wetland value income elasticity
wvbm = Parameter(default=0.00588) # wetland value benchmark value
slrwvpopdens0 = Parameter(default=27.5937717888728) # wetland value income normalization value
wvpdl = Parameter(default=0.47)
wvsl = Parameter(default=-0.11)
dvbm = Parameter(default=0.004) # dryland value benchmark value
slrwvypc0 = Parameter(default=25000)

pc = Parameter(index=[regions])
slrprtp = Parameter(index=[regions])
Expand Down
10 changes: 5 additions & 5 deletions src/components/IWG_PAGE_ClimateTemperature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
rtl_g_landtemperature = Variable(index=[time], unit="degreeC")
rto_g_oceantemperature = Variable(index=[time], unit="degreeC")
rt_g_globaltemperature = Variable(index=[time], unit="degreeC")
rt_g0_baseglobaltemp=Variable(unit="degreeC") #needed for feedback in CO2 cycle component
rtl_g0_baselandtemp=Variable(unit="degreeC") #needed for feedback in CH4 and N2O cycles
rt_g0_baseglobaltemp = Variable(unit="degreeC") # needed for feedback in CO2 cycle component
rtl_g0_baselandtemp = Variable(unit="degreeC") # needed for feedback in CH4 and N2O cycles


function init(p, v, d)
#calculate global baseline temperature from initial regional temperatures
# calculate global baseline temperature from initial regional temperatures

ocean_prop_ortion = 1. - sum(p.area) / 510000000.

# Equation 21 from Hope (2006): initial global land temperature
v.rtl_g0_baselandtemp = sum(p.rtl_0_realizedtemperature' .* p.area') / sum(p.area)

# initial ocean and global temperatures
rto_g0_baseoceantemp = v.rtl_g0_baselandtemp/ p.rlo_ratiolandocean
rto_g0_baseoceantemp = v.rtl_g0_baselandtemp / p.rlo_ratiolandocean
v.rt_g0_baseglobaltemp = ocean_prop_ortion * rto_g0_baseoceantemp + (1. - ocean_prop_ortion) * v.rtl_g0_baselandtemp
end

Expand Down Expand Up @@ -84,7 +84,7 @@
end
else
for rr in d.region
v.rt_realizedtemperature[tt, rr] = v.rt_realizedtemperature[tt-1, rr] + (1 - exp(-(p.y_year[tt] - p.y_year[tt-1]) / p.frt_warminghalflife)) * (v.et_equilibriumtemperature[tt, rr] - v.rt_realizedtemperature[tt-1, rr])
v.rt_realizedtemperature[tt, rr] = v.rt_realizedtemperature[tt - 1, rr] + (1 - exp(-(p.y_year[tt] - p.y_year[tt - 1]) / p.frt_warminghalflife)) * (v.et_equilibriumtemperature[tt, rr] - v.rt_realizedtemperature[tt - 1, rr])
end
end

Expand Down
Loading

0 comments on commit 3f88602

Please sign in to comment.