Skip to content

Commit

Permalink
very minimal working example
Browse files Browse the repository at this point in the history
  • Loading branch information
jrising committed Jul 17, 2015
1 parent 204c805 commit 9160e49
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 197 deletions.
25 changes: 25 additions & 0 deletions src/minimal/linear.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using IAMF

@defcomp linear begin
regions = Index()

value = Variable(index=[time,regions])

slope = Parameter(index=[regions])
end

function timestep(s::linear, t::Int)
v = s.Variables
p = s.Parameters
d = s.Dimensions

if t==1
for r in d.regions
v.value[t, r] = 1
end
else
for r in d.regions
v.value[t, r] = v.value[t - 1, r] - p.slope[r]
end
end
end
11 changes: 9 additions & 2 deletions src/minimal/main.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# cd("$(homedir())/projects/water/model/src/minimal")
push!(LOAD_PATH, "$(homedir())/projects/water/model")

import IAMF.runmodel

include("model.jl")

m = makemodel()
m = makemodel(parameters={"slope" => [1.0]})

runmodel(m)

run(m)
m.components[:linear].Variables
205 changes: 10 additions & 195 deletions src/minimal/model.jl
Original file line number Diff line number Diff line change
@@ -1,217 +1,28 @@
include("helper.jl")
importall IAMF

include("SocioEconomicComponent.jl")
include("PopulationComponent.jl")
include("EmissionsComponent.jl")
include("GeographyComponent.jl")
include("ScenarioUncertaintyComponent.jl")
include("ClimateCO2CycleComponent.jl")
include("ClimateCH4CycleComponent.jl")
include("ClimateN2OCycleComponent.jl")
include("ClimateSF6CycleComponent.jl")
include("ClimateForcingComponent.jl")
include("ClimateDynamicsComponent.jl")
include("BioDiversityComponent.jl")
include("ClimateRegionalComponent.jl")
include("OceanComponent.jl")
include("ImpactAgricultureComponent.jl")
include("ImpactBioDiversityComponent.jl")
include("ImpactForestsComponent.jl")
include("ImpactWaterResourcesComponent.jl")
include("ImpactSeaLevelRiseComponent.jl")
include("linear.jl")

function constructmodel(;nsteps=150)
m = Model()

setindex(m, :time, [1950:1950+nsteps])
setindex(m, :regions, ["USA", "CAN", "WEU", "JPK", "ANZ", "EEU", "FSU", "MDE", "CAM", "LAM", "SAS", "SEA", "CHI", "MAF", "SSA", "SIS"])
setindex(m, :regions, ["NY"])

# ---------------------------------------------
# Create components
# ---------------------------------------------
addcomponent(m, scenariouncertainty)
addcomponent(m, population)
addcomponent(m, geography)
addcomponent(m, socioeconomic)
addcomponent(m, emissions)
addcomponent(m, climateco2cycle)
addcomponent(m, climatech4cycle)
addcomponent(m, climaten2ocycle)
addcomponent(m, climatesf6cycle)
addcomponent(m, climateforcing)
addcomponent(m, climatedynamics)
addcomponent(m, biodiversity)
addcomponent(m, climateregional)
addcomponent(m, ocean)
addcomponent(m, impactagriculture)
addcomponent(m, impactbiodiversity)
addcomponent(m, impactcardiovascularrespiratory)
addcomponent(m, impactcooling)
addcomponent(m, impactdiarrhoea)
addcomponent(m, impactextratropicalstorms)
addcomponent(m, impactforests)
addcomponent(m, impactheating)
addcomponent(m, impactvectorbornediseases)
addcomponent(m, impacttropicalstorms)
addcomponent(m, vslvmorb)
addcomponent(m, impactdeathmorbidity)
addcomponent(m, impactwaterresources)
addcomponent(m, impactsealevelrise)
addcomponent(m, impactaggregation)
addcomponent(m, linear)

# ---------------------------------------------
# Connect parameters to variables
# ---------------------------------------------

bindparameter(m, :geography, :landloss, :impactsealevelrise)

bindparameter(m, :population, :pgrowth, :scenariouncertainty)
bindparameter(m, :population, :enter, :impactsealevelrise)
bindparameter(m, :population, :leave, :impactsealevelrise)
bindparameter(m, :population, :dead, :impactdeathmorbidity)

bindparameter(m, :socioeconomic, :area, :geography)
bindparameter(m, :socioeconomic, :globalpopulation, :population)
bindparameter(m, :socioeconomic, :populationin1, :population)
bindparameter(m, :socioeconomic, :population, :population)
bindparameter(m, :socioeconomic, :pgrowth, :scenariouncertainty)
bindparameter(m, :socioeconomic, :ypcgrowth, :scenariouncertainty)

bindparameter(m, :socioeconomic, :eloss, :impactaggregation)
bindparameter(m, :socioeconomic, :sloss, :impactaggregation)
bindparameter(m, :socioeconomic, :mitigationcost, :emissions)

bindparameter(m, :emissions, :income, :socioeconomic)
bindparameter(m, :emissions, :population, :population)
bindparameter(m, :emissions, :forestemm, :scenariouncertainty)
bindparameter(m, :emissions, :aeei, :scenariouncertainty)
bindparameter(m, :emissions, :acei, :scenariouncertainty)
bindparameter(m, :emissions, :ypcgrowth, :scenariouncertainty)

bindparameter(m, :climateco2cycle, :mco2, :emissions)

bindparameter(m, :climatech4cycle, :globch4, :emissions)

bindparameter(m, :climaten2ocycle, :globn2o, :emissions)
bindparameter(m, :climateco2cycle, :temp, :climatedynamics)

bindparameter(m, :climatesf6cycle, :globsf6, :emissions)

bindparameter(m, :climateforcing, :acco2, :climateco2cycle)
bindparameter(m, :climateforcing, :acch4, :climatech4cycle)
bindparameter(m, :climateforcing, :acn2o, :climaten2ocycle)
bindparameter(m, :climateforcing, :acsf6, :climatesf6cycle)

bindparameter(m, :climatedynamics, :radforc, :climateforcing)

bindparameter(m, :climateregional, :inputtemp, :climatedynamics, :temp)

bindparameter(m, :biodiversity, :temp, :climatedynamics)

bindparameter(m, :ocean, :temp, :climatedynamics)

bindparameter(m, :impactagriculture, :population, :population)
bindparameter(m, :impactagriculture, :income, :socioeconomic)
bindparameter(m, :impactagriculture, :temp, :climateregional)
bindparameter(m, :impactagriculture, :acco2, :climateco2cycle)

bindparameter(m, :impactbiodiversity, :temp, :climateregional)
bindparameter(m, :impactbiodiversity, :nospecies, :biodiversity)
bindparameter(m, :impactbiodiversity, :income, :socioeconomic)
bindparameter(m, :impactbiodiversity, :population, :population)

bindparameter(m, :impactcardiovascularrespiratory, :population, :population)
bindparameter(m, :impactcardiovascularrespiratory, :temp, :climateregional)
bindparameter(m, :impactcardiovascularrespiratory, :plus, :socioeconomic)
bindparameter(m, :impactcardiovascularrespiratory, :urbpop, :socioeconomic)

bindparameter(m, :impactcooling, :population, :population)
bindparameter(m, :impactcooling, :income, :socioeconomic)
bindparameter(m, :impactcooling, :temp, :climateregional)
bindparameter(m, :impactcooling, :cumaeei, :emissions)

bindparameter(m, :impactdiarrhoea, :population, :population)
bindparameter(m, :impactdiarrhoea, :income, :socioeconomic)
bindparameter(m, :impactdiarrhoea, :regtmp, :climateregional)

bindparameter(m, :impactextratropicalstorms, :population, :population)
bindparameter(m, :impactextratropicalstorms, :income, :socioeconomic)
bindparameter(m, :impactextratropicalstorms, :acco2, :climateco2cycle)

bindparameter(m, :impactforests, :population, :population)
bindparameter(m, :impactforests, :income, :socioeconomic)
bindparameter(m, :impactforests, :temp, :climateregional)
bindparameter(m, :impactforests, :acco2, :climateco2cycle)

bindparameter(m, :impactheating, :population, :population)
bindparameter(m, :impactheating, :income, :socioeconomic)
bindparameter(m, :impactheating, :temp, :climateregional)
bindparameter(m, :impactheating, :cumaeei, :emissions)

bindparameter(m, :impactvectorbornediseases, :population, :population)
bindparameter(m, :impactvectorbornediseases, :income, :socioeconomic)
bindparameter(m, :impactvectorbornediseases, :temp, :climateregional)

bindparameter(m, :impacttropicalstorms, :population, :population)
bindparameter(m, :impacttropicalstorms, :income, :socioeconomic)
bindparameter(m, :impacttropicalstorms, :regstmp, :climateregional)

bindparameter(m, :vslvmorb, :population, :population)
bindparameter(m, :vslvmorb, :income, :socioeconomic)

bindparameter(m, :impactdeathmorbidity, :vsl, :vslvmorb)
bindparameter(m, :impactdeathmorbidity, :vmorb, :vslvmorb)
bindparameter(m, :impactdeathmorbidity, :population, :population)
bindparameter(m, :impactdeathmorbidity, :dengue, :impactvectorbornediseases)
bindparameter(m, :impactdeathmorbidity, :schisto, :impactvectorbornediseases)
bindparameter(m, :impactdeathmorbidity, :malaria, :impactvectorbornediseases)
bindparameter(m, :impactdeathmorbidity, :cardheat, :impactcardiovascularrespiratory)
bindparameter(m, :impactdeathmorbidity, :cardcold, :impactcardiovascularrespiratory)
bindparameter(m, :impactdeathmorbidity, :resp, :impactcardiovascularrespiratory)
bindparameter(m, :impactdeathmorbidity, :diadead, :impactdiarrhoea)
bindparameter(m, :impactdeathmorbidity, :hurrdead, :impacttropicalstorms)
bindparameter(m, :impactdeathmorbidity, :extratropicalstormsdead, :impactextratropicalstorms)
bindparameter(m, :impactdeathmorbidity, :diasick, :impactdiarrhoea)

bindparameter(m, :impactwaterresources, :population, :population)
bindparameter(m, :impactwaterresources, :income, :socioeconomic)
bindparameter(m, :impactwaterresources, :temp, :climateregional)

bindparameter(m, :impactsealevelrise, :population, :population)
bindparameter(m, :impactsealevelrise, :income, :socioeconomic)
bindparameter(m, :impactsealevelrise, :sea, :ocean)
bindparameter(m, :impactsealevelrise, :area, :geography)

bindparameter(m, :impactaggregation, :income, :socioeconomic)
bindparameter(m, :impactaggregation, :heating, :impactheating)
bindparameter(m, :impactaggregation, :cooling, :impactcooling)
bindparameter(m, :impactaggregation, :agcost, :impactagriculture)
bindparameter(m, :impactaggregation, :species, :impactbiodiversity)
bindparameter(m, :impactaggregation, :water, :impactwaterresources)
bindparameter(m, :impactaggregation, :hurrdam, :impacttropicalstorms)
bindparameter(m, :impactaggregation, :extratropicalstormsdam, :impactextratropicalstorms)
bindparameter(m, :impactaggregation, :forests, :impactforests)
bindparameter(m, :impactaggregation, :drycost, :impactsealevelrise)
bindparameter(m, :impactaggregation, :protcost, :impactsealevelrise)
bindparameter(m, :impactaggregation, :entercost, :impactsealevelrise)
bindparameter(m, :impactaggregation, :deadcost, :impactdeathmorbidity)
bindparameter(m, :impactaggregation, :morbcost, :impactdeathmorbidity)
bindparameter(m, :impactaggregation, :wetcost, :impactsealevelrise)
bindparameter(m, :impactaggregation, :leavecost, :impactsealevelrise)
#bindparameter(m, :geography, :landloss, :impactsealevelrise)

return m
end

function makemodel(;nsteps=150, datadir="../data", params=nothing)
# ---------------------------------------------
# Load parameters
# ---------------------------------------------
if params==nothing
parameters = loadparameters(datadir)
else
parameters = params
end

function makemodel(;nsteps=150, parameters=nothing)
# ---------------------------------------------
# Construct model
# ---------------------------------------------
Expand All @@ -220,6 +31,10 @@ function makemodel(;nsteps=150, datadir="../data", params=nothing)
# ---------------------------------------------
# Load remaining parameters from file
# ---------------------------------------------
if parameters == nothing
parameters = {}
end

setleftoverparameters(m, parameters)

# ---------------------------------------------
Expand Down

0 comments on commit 9160e49

Please sign in to comment.