Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored May 5, 2021
1 parent 2012c47 commit 864b243
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 93 deletions.
8 changes: 4 additions & 4 deletions src/MimiMAGICC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ function get_model(;rcp_scenario::String="RCP85", start_year::Int=1765, end_year
# ---------------------------------------------

# Load RCP emissions and concentration scenario values (RCP options = "RCP26" or "RCP85").
rcp_emissions = DataFrame(load(joinpath(@__DIR__, "..", "data", rcp_scenario*"_EMISSIONS.csv"), skiplines_begin=36))
rcp_concentrations = DataFrame(load(joinpath(@__DIR__, "..", "data", rcp_scenario*"_CONCENTRATIONS.csv"), skiplines_begin=37))
rcp_emissions = DataFrame(load(joinpath(@__DIR__, "..", "data", rcp_scenario * "_EMISSIONS.csv"), skiplines_begin=36))
rcp_concentrations = DataFrame(load(joinpath(@__DIR__, "..", "data", rcp_scenario * "_CONCENTRATIONS.csv"), skiplines_begin=37))

# Load temperature scenario (mean response from SNEASY across 100,000 posterior parameter samples).
rcp_temperature = DataFrame(load(joinpath(@__DIR__, "..", "data", rcp_scenario*"_temperature_sneasy_1765_2300.csv")))
rcp_temperature = DataFrame(load(joinpath(@__DIR__, "..", "data", rcp_scenario * "_temperature_sneasy_1765_2300.csv")))

# Load fossil CO₂ emissions scenario to calculate historic tropospheric O₃ forcing (this scenario is specific to how MAGICC calculates this forcing).
foss_hist_for_O₃ = DataFrame(load(joinpath(@__DIR__, "..", "data", "FOSS_HIST_magicc.csv")))
Expand Down Expand Up @@ -104,4 +104,4 @@ function get_model(;rcp_scenario::String="RCP85", start_year::Int=1765, end_year
return(m)
end

end #module
end # module
120 changes: 60 additions & 60 deletions src/components/ch4_cycle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,100 +32,100 @@
# Set initial conditions. NOTE: The CH₄ cycle equations require temperature values from the previous two timesteps (t-1 and t-2), so the cycle switches
# on starting in timestep 3. Further, timestep 1 CH₄ concentrations do not affect the results below (but timestep 2 CH₄ concentrations do). We
# therefore treat period 2 CH₄ concentrations as an initial (and uncertain) condition.
if t <= TimestepIndex(2)
v.CH₄[TimestepIndex(2)] = p.CH₄_0
v.emeth[t] = 0.0
else
if t <= TimestepIndex(2)
v.CH₄[TimestepIndex(2)] = p.CH₄_0
v.emeth[t] = 0.0
else

# Calculate changes for temperature sensitivity equation (maintain MAGICC's original scaling relative to increase above 2000).
if t < TimestepValue(2000)
D_Temp = 0.0
else
DELT00 = 2.0 * p.temperature[TimestepValue(2000)-1] - p.temperature[TimestepValue(2000)-2]
TX = 2.0 * p.temperature[t-1] - p.temperature[t-2]
D_Temp = TX - DELT00
end
if t < TimestepValue(2000)
D_Temp = 0.0
else
DELT00 = 2.0 * p.temperature[TimestepValue(2000) - 1] - p.temperature[TimestepValue(2000) - 2]
TX = 2.0 * p.temperature[t - 1] - p.temperature[t - 2]
D_Temp = TX - DELT00
end

# Calculate change in emissions for NOx, CO, and NMVOC (relative to period 3 when CH₄ cycle model engages due to t-1 and t-2 terms above).
DENOX = p.NOx_emissions[t] - p.NOx_emissions[TimestepIndex(3)]
DECO = p.CO_emissions[t] - p.CO_emissions[TimestepIndex(3)]
DEVOC = p.NMVOC_emissions[t] - p.NMVOC_emissions[TimestepIndex(3)]
DENOX = p.NOx_emissions[t] - p.NOx_emissions[TimestepIndex(3)]
DECO = p.CO_emissions[t] - p.CO_emissions[TimestepIndex(3)]
DEVOC = p.NMVOC_emissions[t] - p.NMVOC_emissions[TimestepIndex(3)]

# Add natural CH₄ emissions to anthropogenic CH₄ emissions.
Total_CH4emissions = p.CH4_emissions[t] + p.CH4_natural
Total_CH4emissions = p.CH4_emissions[t] + p.CH4_natural

# Calcualte TAUOTHER term (based on stratospheric and soil sink lifetimes).
TAUOTHER = 1.0 / (1.0/p.TAUSOIL + 1.0/p.TAUSTRAT)
TAUOTHER = 1.0 / (1.0 / p.TAUSOIL + 1.0 / p.TAUSTRAT)

##########################################################
# Iterate to Calculate OH lifetime and CH₄ concentration.
# See equations A30-A32 in Meinsshausen et al.(2011).
##########################################################

# Convert previous timestep concentration to mass.
B = v.CH₄[t-1] * p.BBCH4
B = v.CH₄[t - 1] * p.BBCH4

# Convert historical concentration to mass.
B00 = p.CH₄_0 * p.BBCH4
B00 = p.CH₄_0 * p.BBCH4

# Account for other gases on OH abundance and tropospheric methane lifetime.
AAA = exp(p.GAM * (p.ANOX*DENOX + p.ACO*DECO + p.AVOC*DEVOC))
AAA = exp(p.GAM * (p.ANOX * DENOX + p.ACO * DECO + p.AVOC * DEVOC))

# Multiply two parameters together.
X = p.GAM * p.SCH4
X = p.GAM * p.SCH4

# Multiply initial tropospheric lifetime by AAA.
U = p.TAUINIT * AAA
U = p.TAUINIT * AAA

# Iterate to calculate a final CH₄ tropospheric lifetime (accounting for a temperature feedback).

#----------------------------------------
# ----------------------------------------
# FIRST ITERATION
#----------------------------------------
BBAR = B
TAUBAR = U * (BBAR/B00) ^ X
TAUBAR = p.TAUINIT / (p.TAUINIT/TAUBAR + 0.0316 * D_Temp)
DB1 = Total_CH4emissions - (BBAR/TAUBAR) - (BBAR/TAUOTHER)
B1 = B + DB1

#----------------------------------------
# ----------------------------------------
BBAR = B
TAUBAR = U * (BBAR / B00)^X
TAUBAR = p.TAUINIT / (p.TAUINIT / TAUBAR + 0.0316 * D_Temp)
DB1 = Total_CH4emissions - (BBAR / TAUBAR) - (BBAR / TAUOTHER)
B1 = B + DB1

# ----------------------------------------
# SECOND ITERATION
#----------------------------------------
BBAR = (B + B1) / 2.0
TAUBAR = U * (BBAR/B00) ^ X
TAUBAR = TAUBAR * (1.0 - 0.5 * X * DB1/B)
TAUBAR = p.TAUINIT / (p.TAUINIT/TAUBAR + 0.0316 * D_Temp)
DB2 = Total_CH4emissions - (BBAR/TAUBAR) - (BBAR/TAUOTHER)
B2 = B + DB2

#----------------------------------------
# ----------------------------------------
BBAR = (B + B1) / 2.0
TAUBAR = U * (BBAR / B00)^X
TAUBAR = TAUBAR * (1.0 - 0.5 * X * DB1 / B)
TAUBAR = p.TAUINIT / (p.TAUINIT / TAUBAR + 0.0316 * D_Temp)
DB2 = Total_CH4emissions - (BBAR / TAUBAR) - (BBAR / TAUOTHER)
B2 = B + DB2

# ----------------------------------------
# THIRD ITERATION
#----------------------------------------
BBAR = (B + B2) / 2.0
TAUBAR = U * (BBAR/B00) ^ X
TAUBAR = TAUBAR * (1.0 - 0.5 * X * DB2/B)
TAUBAR = p.TAUINIT / (p.TAUINIT/TAUBAR + 0.0316 * D_Temp)
DB3 = Total_CH4emissions - (BBAR/TAUBAR) - (BBAR/TAUOTHER)
B3 = B + DB3

#----------------------------------------
# ----------------------------------------
BBAR = (B + B2) / 2.0
TAUBAR = U * (BBAR / B00)^X
TAUBAR = TAUBAR * (1.0 - 0.5 * X * DB2 / B)
TAUBAR = p.TAUINIT / (p.TAUINIT / TAUBAR + 0.0316 * D_Temp)
DB3 = Total_CH4emissions - (BBAR / TAUBAR) - (BBAR / TAUOTHER)
B3 = B + DB3

# ----------------------------------------
# FOURTH ITERATION
#----------------------------------------
BBAR = (B + B3) / 2.0
TAUBAR = U * (BBAR/B00) ^ X
TAUBAR = TAUBAR * (1.0 - 0.5 * X * DB3/B)
TAUBAR = p.TAUINIT / (p.TAUINIT/TAUBAR + 0.0316 * D_Temp)
DB4 = Total_CH4emissions - (BBAR/TAUBAR) - (BBAR/TAUOTHER)
B4 = B + DB4
# ----------------------------------------
BBAR = (B + B3) / 2.0
TAUBAR = U * (BBAR / B00)^X
TAUBAR = TAUBAR * (1.0 - 0.5 * X * DB3 / B)
TAUBAR = p.TAUINIT / (p.TAUINIT / TAUBAR + 0.0316 * D_Temp)
DB4 = Total_CH4emissions - (BBAR / TAUBAR) - (BBAR / TAUOTHER)
B4 = B + DB4

# Calculate CH₄ tropospheric lifetime.
v.TAU_OH[t] = TAUBAR
v.TAU_OH[t] = TAUBAR

# Calculate CH₄ concentration.
v.CH₄[t] = B4 / p.BBCH4
v.CH₄[t] = B4 / p.BBCH4

#Calculate additional CO₂ emissions due to CH₄ oxidation.
v.emeth[t] = p.fffrac * 0.0020625 * (v.CH₄[t] - 700.0) / p.TAUINIT
end
# Calculate additional CO₂ emissions due to CH₄ oxidation.
v.emeth[t] = p.fffrac * 0.0020625 * (v.CH₄[t] - 700.0) / p.TAUINIT
end
end
end
12 changes: 6 additions & 6 deletions src/components/rf_ch4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Create a function 'interact' to account for the overlap in methane and nitrous oxide in their radiative absoprtion bands.
function interact(M, N)
d = 1.0 + 0.636 * ((M * N)/(10^6))^0.75 + 0.007 * (M/(10^3)) * ((M * N)/(10^6))^1.52
d = 1.0 + 0.636 * ((M * N) / (10^6))^0.75 + 0.007 * (M / (10^3)) * ((M * N) / (10^6))^1.52
return 0.47 * log(d)
end

Expand All @@ -19,12 +19,12 @@ end

function run_timestep(p, v, d, t)

if is_first(t)
if is_first(t)
# Set initial forcings to 0.
v.QMeth[t] = 0.0
else
v.QMeth[t] = 0.0
else
# Direct radiative forcing from atmospheric CH₄ concentrations.
v.QMeth[t] = (0.036 * (sqrt(p.CH₄[t]) - sqrt(p.CH₄_0)) - (interact(p.CH₄[t], p.N₂O_0) - interact(p.CH₄_0, p.N₂O_0))) * p.scale_CH₄
end
v.QMeth[t] = (0.036 * (sqrt(p.CH₄[t]) - sqrt(p.CH₄_0)) - (interact(p.CH₄[t], p.N₂O_0) - interact(p.CH₄_0, p.N₂O_0))) * p.scale_CH₄
end
end
end
10 changes: 5 additions & 5 deletions src/components/rf_ch4h2o.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

function run_timestep(p, v, d, t)

if is_first(t)
if is_first(t)
# Set initial forcing to 0.
v.QCH4H2O[t] = 0.0
else
v.QCH4H2O[t] = 0.0
else
# Calculate indirect CH₄ forcing due to stratoshperic water vapor production from CH₄ oxidation.
v.QCH4H2O[t] = p.STRATH2O * (0.036 * (sqrt(p.CH₄[t]) - sqrt(p.CH₄_0)))
end
v.QCH4H2O[t] = p.STRATH2O * (0.036 * (sqrt(p.CH₄[t]) - sqrt(p.CH₄_0)))
end
end
end
32 changes: 16 additions & 16 deletions src/components/rf_o3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@

function run_timestep(p, v, d, t)

if is_first(t)
if is_first(t)
# Set initial values for O₃ forcing to 0.0.
v.QCH4OZ[t] = 0.0
v.QOZ[t] = 0.0
v.rf_O₃[t] = 0.0
v.QCH4OZ[t] = 0.0
v.QOZ[t] = 0.0
v.rf_O₃[t] = 0.0

else
else

# The CH₄ emission cycle was converted to run on emissions for all time periods (to be able to use CH₄ concentration observations during calibration).
# The non-methane component of the O₃ cycle follows the original version of MAGICC by switching on the primary emissions equations after year 2000.
if gettime(t) < 2000
if gettime(t) < 2000
# Calculate historic non-CH₄ tropospheric O₃ forcing.
v.QOZ[t] = (0.33 - p.OZ00CH4) * (p.FOSSHIST[t] - p.FOSSHIST[TimestepIndex(1)]) / (p.FOSSHIST[TimestepValue(2000)-1] - p.FOSSHIST[TimestepIndex(1)])
v.QOZ[t] = (0.33 - p.OZ00CH4) * (p.FOSSHIST[t] - p.FOSSHIST[TimestepIndex(1)]) / (p.FOSSHIST[TimestepValue(2000) - 1] - p.FOSSHIST[TimestepIndex(1)])

else
else
# Calculate change in emissions for NOX, CO, and NMVOC relative to 2000.
DENOX = p.NOx_emissions[t] - p.NOx_emissions[TimestepValue(2000)]
DECO = p.CO_emissions[t] - p.CO_emissions[TimestepValue(2000)]
DEVOC = p.NMVOC_emissions[t] - p.NMVOC_emissions[TimestepValue(2000)]
DENOX = p.NOx_emissions[t] - p.NOx_emissions[TimestepValue(2000)]
DECO = p.CO_emissions[t] - p.CO_emissions[TimestepValue(2000)]
DEVOC = p.NMVOC_emissions[t] - p.NMVOC_emissions[TimestepValue(2000)]

# Calculate tropospheric O₃ radiative forcing not attributed to CH₄.
v.QOZ[t] = (0.33 - p.OZ00CH4) + (v.QOZ[TimestepValue(2000)-1] - v.QOZ[TimestepValue(2000)-2]) + p.TROZSENS*(p.OZNOX*DENOX + p.OZCO*DECO + p.OZVOC*DEVOC)
end
v.QOZ[t] = (0.33 - p.OZ00CH4) + (v.QOZ[TimestepValue(2000) - 1] - v.QOZ[TimestepValue(2000) - 2]) + p.TROZSENS * (p.OZNOX * DENOX + p.OZCO * DECO + p.OZVOC * DEVOC)
end

# Calculate indirect CH₄ forcing due to CH₄-induced O₃ production (based on pure emissions version of CH₄ cycle).
v.QCH4OZ[t] = p.TROZSENS * p.OZCH4 * log(p.CH₄[t]/p.CH₄_0)
v.QCH4OZ[t] = p.TROZSENS * p.OZCH4 * log(p.CH₄[t] / p.CH₄_0)

# Calculate total tropospheric O₃ radiative forcing (from direct O₃ and indirect CH₄ effects).
v.rf_O₃[t] = v.QOZ[t] + v.QCH4OZ[t]
end
v.rf_O₃[t] = v.QOZ[t] + v.QCH4OZ[t]
end
end
end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ using MimiMAGICC

@testset "MAGICC" begin

#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# 1. Carry out test to check that the model runs.
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

@testset "MAGICC-model" begin

Expand Down

0 comments on commit 864b243

Please sign in to comment.