Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Aug 26, 2022
1 parent 02c3947 commit d2f80a2
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 219 deletions.
2 changes: 1 addition & 1 deletion data/SC validation data/create_scc_validation_file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ specs = Dict([
:last_year => [2200, 2305],
])

results = DataFrame(year = [], eta = [], prtp = [], last_year = [], SC = [])
results = DataFrame(year=[], eta=[], prtp=[], last_year=[], SC=[])

for year in specs[:year]
for eta in specs[:eta]
Expand Down
4 changes: 2 additions & 2 deletions src/MimiDICE2013.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ function constructdice(params)

end

function getdiceexcel(;datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE_2013_Excel.xlsm"))
function getdiceexcel(; datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE_2013_Excel.xlsm"))
params = getdice2013excelparameters(datafile)

m = constructdice(params)

return m
end

function getdicegams(;datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE2013_IAMF_Parameters.xlsx"))
function getdicegams(; datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE2013_IAMF_Parameters.xlsx"))
params = getdice2013gamsparameters(datafile)

m = constructdice(params)
Expand Down
18 changes: 9 additions & 9 deletions src/components/climatedynamics_component.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@defcomp climatedynamics begin
TATM = Variable(index=[time]) # Increase in temperature of atmosphere (degrees C from 1900)
TOCEAN = Variable(index=[time]) # Increase in temperature of lower oceans (degrees C from 1900)
TATM = Variable(index=[time]) # Increase in temperature of atmosphere (degrees C from 1900)
TOCEAN = Variable(index=[time]) # Increase in temperature of lower oceans (degrees C from 1900)

FORC = Parameter(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)
t2xco2 = Parameter() # Equilibrium temp impact (oC per doubling CO2)
tatm0 = Parameter() # Initial atmospheric temp change (C from 1900)
FORC = Parameter(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)
t2xco2 = Parameter() # Equilibrium temp impact (oC per doubling CO2)
tatm0 = Parameter() # Initial atmospheric temp change (C from 1900)
tocean0 = Parameter() # Initial lower stratum temp change (C from 1900)

# Transient TSC Correction ("Speed of Adjustment Parameter")
Expand All @@ -18,14 +18,14 @@
if is_first(t)
v.TATM[t] = p.tatm0
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
if is_first(t)
v.TOCEAN[t] = p.tocean0
else
v.TOCEAN[t] = v.TOCEAN[t - 1] + p.c4 * (v.TATM[t - 1] - v.TOCEAN[t - 1])
v.TOCEAN[t] = v.TOCEAN[t-1] + p.c4 * (v.TATM[t-1] - v.TOCEAN[t-1])
end
end
end
end
34 changes: 17 additions & 17 deletions src/components/co2cycle_component.jl
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
@defcomp co2cycle begin
MAT = Variable(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
ML = Variable(index=[time]) # Carbon concentration increase in lower oceans (GtC from 1750)
MU = Variable(index=[time]) # Carbon concentration increase in shallow oceans (GtC from 1750)
MAT = Variable(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
ML = Variable(index=[time]) # Carbon concentration increase in lower oceans (GtC from 1750)
MU = Variable(index=[time]) # Carbon concentration increase in shallow oceans (GtC from 1750)

E = Parameter(index=[time]) # Total CO2 emissions (GtCO2 per year)
mat0 = Parameter() # Initial Concentration in atmosphere 2010 (GtC)
ml0 = Parameter() # Initial Concentration in lower strata 2010 (GtC)
mu0 = Parameter() # Initial Concentration in upper strata 2010 (GtC)
E = Parameter(index=[time]) # Total CO2 emissions (GtCO2 per year)
mat0 = Parameter() # Initial Concentration in atmosphere 2010 (GtC)
ml0 = Parameter() # Initial Concentration in lower strata 2010 (GtC)
mu0 = Parameter() # Initial Concentration in upper strata 2010 (GtC)

# Parameters for long-run consistency of carbon cycle
b11 = Parameter() # Carbon cycle transition matrix atmosphere to atmosphere
b12 = Parameter() # Carbon cycle transition matrix atmosphere to shallow ocean
b21 = Parameter() # Carbon cycle transition matrix biosphere/shallow oceans to atmosphere
b22 = Parameter() # Carbon cycle transition matrix shallow ocean to shallow oceans
b23 = Parameter() # Carbon cycle transition matrix shallow to deep ocean
b32 = Parameter() # Carbon cycle transition matrix deep ocean to shallow ocean
b33 = Parameter() # Carbon cycle transition matrix deep ocean to deep oceans
b11 = Parameter() # Carbon cycle transition matrix atmosphere to atmosphere
b12 = Parameter() # Carbon cycle transition matrix atmosphere to shallow ocean
b21 = Parameter() # Carbon cycle transition matrix biosphere/shallow oceans to atmosphere
b22 = Parameter() # Carbon cycle transition matrix shallow ocean to shallow oceans
b23 = Parameter() # Carbon cycle transition matrix shallow to deep ocean
b32 = Parameter() # Carbon cycle transition matrix deep ocean to shallow ocean
b33 = Parameter() # Carbon cycle transition matrix deep ocean to deep oceans

function run_timestep(p, v, d, t)
# Define function for MAT
if is_first(t)
v.MAT[t] = p.mat0
else
v.MAT[t] = v.MAT[t - 1] * p.b11 + v.MU[t - 1] * p.b21 + (p.E[t - 1] * (5 / 3.666))
v.MAT[t] = v.MAT[t-1] * p.b11 + v.MU[t-1] * p.b21 + (p.E[t-1] * (5 / 3.666))
end

# Define function for MU
if is_first(t)
v.MU[t] = p.mu0
else
v.MU[t] = v.MAT[t - 1] * p.b12 + v.MU[t - 1] * p.b22 + v.ML[t - 1] * p.b32
v.MU[t] = v.MAT[t-1] * p.b12 + v.MU[t-1] * p.b22 + v.ML[t-1] * p.b32
end

# Define function for ML
if is_first(t)
v.ML[t] = p.ml0
else
v.ML[t] = v.ML[t - 1] * p.b33 + v.MU[t - 1] * p.b23
v.ML[t] = v.ML[t-1] * p.b33 + v.MU[t-1] * p.b23
end
end
end
14 changes: 7 additions & 7 deletions src/components/damages_component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
DAMAGES = Variable(index=[time]) # Damages (trillions 2005 USD per year)
DAMFRAC = Variable(index=[time]) # Damages (fraction of gross output)

TATM = Parameter(index=[time]) # Increase temperature of atmosphere (degrees C from 1900)
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
a1 = Parameter() # Damage coefficient
a2 = Parameter() # Damage quadratic term
a3 = Parameter() # Damage exponent
damadj = Parameter() # Adjustment exponent in damage function
TATM = Parameter(index=[time]) # Increase temperature of atmosphere (degrees C from 1900)
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
a1 = Parameter() # Damage coefficient
a2 = Parameter() # Damage quadratic term
a3 = Parameter() # Damage exponent
damadj = Parameter() # Adjustment exponent in damage function
usedamadj = Parameter{Bool}() # Only the Excel version uses the damadj parameter

function run_timestep(p, v, d, t)
# Define function for DAMFRAC
v.DAMFRAC[t] = p.a1 * p.TATM[t] + p.a2 * p.TATM[t]^p.a3

# Define function for DAMAGES
if p.usedamadj
# Excel version
Expand Down
22 changes: 11 additions & 11 deletions src/components/emissions_component.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
@defcomp emissions begin
CCA = Variable(index=[time]) # Cumulative indiustrial emissions
E = Variable(index=[time]) # Total CO2 emissions (GtCO2 per year)
EIND = Variable(index=[time]) # Industrial emissions (GtCO2 per year)
CCA = Variable(index=[time]) # Cumulative indiustrial emissions
E = Variable(index=[time]) # Total CO2 emissions (GtCO2 per year)
EIND = Variable(index=[time]) # Industrial emissions (GtCO2 per year)

etree = Parameter(index=[time]) # Emissions from deforestation
MIU = Parameter(index=[time]) # Emission control rate GHGs
sigma = Parameter(index=[time]) # CO2-equivalent-emissions output ratio
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
cca0 = Parameter() # Initial cumulative industrial emissions
etree = Parameter(index=[time]) # Emissions from deforestation
MIU = Parameter(index=[time]) # Emission control rate GHGs
sigma = Parameter(index=[time]) # CO2-equivalent-emissions output ratio
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
cca0 = Parameter() # Initial cumulative industrial emissions

function run_timestep(p, v, d, t)
# Define function for EIND
v.EIND[t] = p.sigma[t] * p.YGROSS[t] * (1 - p.MIU[t])

# Define function for E
v.E[t] = v.EIND[t] + p.etree[t]

# Define function for CCA
if is_first(t)
v.CCA[t] = p.cca0
else
v.CCA[t] = v.CCA[t - 1] + v.EIND[t - 1] * 5 / 3.666
v.CCA[t] = v.CCA[t-1] + v.EIND[t-1] * 5 / 3.666
end

end
Expand Down
18 changes: 9 additions & 9 deletions src/components/grosseconomy_component.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
@defcomp grosseconomy begin
K = Variable(index=[time]) # Capital stock (trillions 2005 US dollars)
YGROSS = Variable(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
K = Variable(index=[time]) # Capital stock (trillions 2005 US dollars)
YGROSS = Variable(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)

al = Parameter(index=[time]) # Level of total factor productivity
I = Parameter(index=[time]) # Investment (trillions 2005 USD per year)
l = Parameter(index=[time]) # Level of population and labor
dk = Parameter() # Depreciation rate on capital (per year)
gama = Parameter() # Capital elasticity in production function
k0 = Parameter() # Initial capital value (trill 2005 USD)
al = Parameter(index=[time]) # Level of total factor productivity
I = Parameter(index=[time]) # Investment (trillions 2005 USD per year)
l = Parameter(index=[time]) # Level of population and labor
dk = Parameter() # Depreciation rate on capital (per year)
gama = Parameter() # Capital elasticity in production function
k0 = Parameter() # Initial capital value (trill 2005 USD)

function run_timestep(p, v, d, t)
# Define function for K
if is_first(t)
v.K[t] = p.k0
else
v.K[t] = (1 - p.dk)^5 * v.K[t - 1] + 5 * p.I[t - 1]
v.K[t] = (1 - p.dk)^5 * v.K[t-1] + 5 * p.I[t-1]
end

# Define function for YGROSS
Expand Down
50 changes: 25 additions & 25 deletions src/components/neteconomy_component.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
@defcomp neteconomy begin

ABATECOST = Variable(index=[time]) # Cost of emissions reductions (trillions 2005 USD per year)
C = Variable(index=[time]) # Consumption (trillions 2005 US dollars per year)
CPC = Variable(index=[time]) # Per capita consumption (thousands 2005 USD per year)
CPRICE = Variable(index=[time]) # Carbon price (2005$ per ton of CO2)
I = Variable(index=[time]) # Investment (trillions 2005 USD per year)
MCABATE = Variable(index=[time]) # Marginal cost of abatement (2005$ per ton CO2)
Y = Variable(index=[time]) # Gross world product net of abatement and damages (trillions 2005 USD per year)
YNET = Variable(index=[time]) # Output net of damages equation (trillions 2005 USD per year)

cost1 = Parameter(index=[time]) # Abatement cost function coefficient
DAMAGES = Parameter(index=[time]) # Damages (Trillion $)
l = Parameter(index=[time]) # Level of population and labor
MIU = Parameter(index=[time]) # Emission control rate GHGs
partfract = Parameter(index=[time]) # Fraction of emissions in control regime
pbacktime = Parameter(index=[time]) # Backstop price
S = Parameter(index=[time]) # Gross savings rate as fraction of gross world product
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
expcost2 = Parameter() # Exponent of control cost function
ABATECOST = Variable(index=[time]) # Cost of emissions reductions (trillions 2005 USD per year)
C = Variable(index=[time]) # Consumption (trillions 2005 US dollars per year)
CPC = Variable(index=[time]) # Per capita consumption (thousands 2005 USD per year)
CPRICE = Variable(index=[time]) # Carbon price (2005$ per ton of CO2)
I = Variable(index=[time]) # Investment (trillions 2005 USD per year)
MCABATE = Variable(index=[time]) # Marginal cost of abatement (2005$ per ton CO2)
Y = Variable(index=[time]) # Gross world product net of abatement and damages (trillions 2005 USD per year)
YNET = Variable(index=[time]) # Output net of damages equation (trillions 2005 USD per year)

cost1 = Parameter(index=[time]) # Abatement cost function coefficient
DAMAGES = Parameter(index=[time]) # Damages (Trillion $)
l = Parameter(index=[time]) # Level of population and labor
MIU = Parameter(index=[time]) # Emission control rate GHGs
partfract = Parameter(index=[time]) # Fraction of emissions in control regime
pbacktime = Parameter(index=[time]) # Backstop price
S = Parameter(index=[time]) # Gross savings rate as fraction of gross world product
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
expcost2 = Parameter() # Exponent of control cost function

function run_timestep(p, v, d, t)
# Define function for YNET
v.YNET[t] = p.YGROSS[t] - p.DAMAGES[t]

# Define function for ABATECOST
v.ABATECOST[t] = p.YGROSS[t] * p.cost1[t] * (p.MIU[t]^p.expcost2) * (p.partfract[t]^(1 - p.expcost2))

# Define function for MCABATE (equation from GAMS version)
v.MCABATE[t] = p.pbacktime[t] * p.MIU[t]^(p.expcost2 - 1)

# Define function for Y
v.Y[t] = v.YNET[t] - v.ABATECOST[t]

# Define function for I
v.I[t] = p.S[t] * v.Y[t]

# Define function for C
v.C[t] = v.Y[t] - v.I[t]

# Define function for CPC
v.CPC[t] = 1000 * v.C[t] / p.l[t]

# Define function for CPRICE (equation from GAMS version of DICE2013)
v.CPRICE[t] = p.pbacktime[t] * (p.MIU[t] / p.partfract[t])^(p.expcost2 - 1)
end
Expand Down
10 changes: 5 additions & 5 deletions src/components/radiativeforcing_component.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@defcomp radiativeforcing begin
FORC = Variable(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)
FORC = Variable(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)

forcoth = Parameter(index=[time]) # Exogenous forcing for other greenhouse gases
MAT = Parameter(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
eqmat = Parameter() # Equilibrium concentration of CO2 in atmosphere (GTC)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)
forcoth = Parameter(index=[time]) # Exogenous forcing for other greenhouse gases
MAT = Parameter(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
eqmat = Parameter() # Equilibrium concentration of CO2 in atmosphere (GTC)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)

function run_timestep(p, v, d, t)
# Define function for FORC
Expand Down
22 changes: 11 additions & 11 deletions src/components/welfare_component.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@defcomp welfare begin
CEMUTOTPER = Variable(index=[time]) # Period utility
CUMCEMUTOTPER = Variable(index=[time]) # Cumulative period utility
PERIODU = Variable(index=[time]) # One period utility function
UTILITY = Variable() # Welfare Function
CEMUTOTPER = Variable(index=[time]) # Period utility
CUMCEMUTOTPER = Variable(index=[time]) # Cumulative period utility
PERIODU = Variable(index=[time]) # One period utility function
UTILITY = Variable() # Welfare Function

CPC = Parameter(index=[time]) # Per capita consumption (thousands 2005 USD per year)
l = Parameter(index=[time]) # Level of population and labor
rr = Parameter(index=[time]) # Average utility social discount rate
elasmu = Parameter() # Elasticity of marginal utility of consumption
scale1 = Parameter() # Multiplicative scaling coefficient
scale2 = Parameter() # Additive scaling coefficient
CPC = Parameter(index=[time]) # Per capita consumption (thousands 2005 USD per year)
l = Parameter(index=[time]) # Level of population and labor
rr = Parameter(index=[time]) # Average utility social discount rate
elasmu = Parameter() # Elasticity of marginal utility of consumption
scale1 = Parameter() # Multiplicative scaling coefficient
scale2 = Parameter() # Additive scaling coefficient

function run_timestep(p, v, d, t)
# Define function for PERIODU
Expand All @@ -19,7 +19,7 @@
v.CEMUTOTPER[t] = v.PERIODU[t] * p.l[t] * p.rr[t]

# Define function for CUMCEMUTOTPER
v.CUMCEMUTOTPER[t] = v.CEMUTOTPER[t] + (!is_first(t) ? v.CUMCEMUTOTPER[t - 1] : 0)
v.CUMCEMUTOTPER[t] = v.CEMUTOTPER[t] + (!is_first(t) ? v.CUMCEMUTOTPER[t-1] : 0)

# Define function for UTILITY
if t == TimestepIndex(60)
Expand Down
12 changes: 6 additions & 6 deletions src/marginaldamage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function compute_scc_mm(m::Model=get_model(); year::Union{Int,Nothing}=nothing,

mm = get_marginal_model(m; year=year)
scc = _compute_scc(mm; year=year, last_year=last_year, prtp=prtp, eta=eta)
return (scc = scc, mm = mm)

return (scc=scc, mm=mm)
end

# helper function for computing SCC from a MarginalModel, not to be exported or advertised to users
Expand Down Expand Up @@ -76,7 +76,7 @@ end
Adds a marginal emission component to year m which adds 1Gt of additional CO2 emissions per year for five years starting in the specified `year`.
"""
function add_marginal_emissions!(m::Model, year::Int)
function add_marginal_emissions!(m::Model, year::Int)
add_comp!(m, Mimi.adder, :marginalemission, before=:co2cycle)

time = Mimi.dimension(m, :time)
Expand All @@ -91,11 +91,11 @@ end


# Old available marginal model function
function getmarginal_dice_models(;emissionyear=2010)
function getmarginal_dice_models(; emissionyear=2010)

DICE = constructdice()
run(DICE)

mm = MarginalModel(DICE)
m1 = mm.base
m2 = mm.modified
Expand All @@ -114,4 +114,4 @@ function getmarginal_dice_models(;emissionyear=2010)
run(m2)

return m1, m2
end
end
Loading

0 comments on commit d2f80a2

Please sign in to comment.