Skip to content

Commit 7e32ff1

Browse files
authored
Format files using DocumentFormat
1 parent 4ca4e0f commit 7e32ff1

8 files changed

+214
-202
lines changed

src/MimiRFFSPs.jl

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ function get_model()
3131

3232
set_dimension!(m, :time, 1750:2300)
3333

34-
add_comp!(m, SPs, :rffsp, first = 2020, last = 2300)
34+
add_comp!(m, SPs, :rffsp, first=2020, last=2300)
3535

36-
all_countries = CSVFiles.load(joinpath(@__DIR__, "..", "data", "keys", "MimiRFFSPs_ISO3.csv")) |> DataFrame
36+
all_countries = CSVFiles.load(joinpath(@__DIR__, "..", "data", "keys", "MimiRFFSPs_ISO3.csv")) |> DataFrame
3737

3838
set_dimension!(m, :country, all_countries.ISO3)
3939

@@ -42,10 +42,9 @@ function get_model()
4242
return m
4343
end
4444

45-
function get_mcs(sampling_ids::Union{Vector{Int}, Nothing} = nothing)
45+
function get_mcs(sampling_ids::Union{Vector{Int},Nothing}=nothing)
4646
# define the Monte Carlo Simulation and add some simple random variables
47-
mcs = @defsim begin
48-
end
47+
mcs = @defsim begin end
4948

5049
distrib = isnothing(sampling_ids) ? Mimi.EmpiricalDistribution(collect(1:10_000)) : Mimi.SampleStore(sampling_ids)
5150
Mimi.add_RV!(mcs, :socio_id_rv, distrib)

src/components/RegionAggregatorSum.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@defcomp RegionAggregatorSum begin
2-
2+
33
inputregions = Index()
44
outputregions = Index()
55

@@ -12,17 +12,17 @@
1212
input = Parameter(index=[time, inputregions])
1313
output = Variable(index=[time, outputregions])
1414

15-
function init(p,v,d)
15+
function init(p, v, d)
1616
idxs = indexin(p.input_output_mapping, p.output_region_names)
1717
!isnothing(findfirst(i -> isnothing(i), idxs)) ? error("All provided region names in the RegionAggregatorSum's input_output_mapping Parameter must exist in the output_region_names Parameter.") : nothing
1818
v.input_output_mapping_int[:] = idxs
1919
end
2020

21-
function run_timestep(p,v,d,t)
21+
function run_timestep(p, v, d, t)
2222
v.output[t, :] .= 0.
2323

2424
for i in d.inputregions
25-
v.output[t, v.input_output_mapping_int[i]] += p.input[t,i]
25+
v.output[t, v.input_output_mapping_int[i]] += p.input[t, i]
2626
end
2727
end
2828
end

src/components/SPs.jl

+55-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# (10/25/2021) BEA Table 1.1.9, line 1 GDP annual values as linked here: https://apps.bea.gov/iTable/iTable.cfm?reqid=19&step=3&isuri=1&select_all_years=0&nipa_table_list=13&series=a&first_year=2005&last_year=2020&scale=-99&categories=survey&thetable=
2-
const pricelevel_2011_to_2005 = 87.504/98.164
2+
const pricelevel_2011_to_2005 = 87.504 / 98.164
33

44
function fill_socioeconomics!(source_Year, source_Country, source_Pop, source_GDP, population, gdp, country_lookup, start_year, end_year)
55
for i in 1:length(source_Year)
@@ -27,8 +27,9 @@ function fill_deathrates!(source_Year, source_ISO3, source_DeathRate, deathrate,
2727
end
2828

2929
function fill_emissions!(source_year, source_value, emissions_var, start_year, end_year)
30-
for (t,v) in zip(source_year, source_value)
31-
if start_year <= t end_year
30+
for (t, v) in zip(source_year, source_value)
31+
if start_year <= t
32+
end_year
3233
year_index = TimestepIndex(t - start_year + 1)
3334
emissions_var[year_index] = v
3435
end
@@ -58,50 +59,50 @@ end
5859
end_year = Parameter{Int}(default=Int(2300)) # year (annual) data should end
5960
country_names = Parameter{String}(index=[country]) # need the names of the countries from the dimension
6061
id = Parameter{Int64}(default=Int(6546)) # the sample (out of 10,000) to be used
61-
62-
population = Variable(index=[time, country], unit="million")
63-
population_global = Variable(index=[time], unit="million")
64-
deathrate = Variable(index=[time, country], unit="deaths/1000 persons/yr")
65-
gdp = Variable(index=[time, country], unit="billion US\$2005/yr")
66-
gdp_global = Variable(index=[time], unit="billion US\$2005/yr")
67-
68-
population1990 = Variable(index=[country], unit = "million")
69-
gdp1990 = Variable(index=[country], unit = unit="billion US\$2005/yr")
70-
71-
co2_emissions = Variable(index=[time], unit="GtC/yr")
72-
ch4_emissions = Variable(index=[time], unit="MtCH4/yr")
73-
n2o_emissions = Variable(index=[time], unit="MtN2/yr")
74-
75-
function init(p,v,d)
62+
63+
population = Variable(index=[time, country], unit="million")
64+
population_global = Variable(index=[time], unit="million")
65+
deathrate = Variable(index=[time, country], unit="deaths/1000 persons/yr")
66+
gdp = Variable(index=[time, country], unit="billion US\$2005/yr")
67+
gdp_global = Variable(index=[time], unit="billion US\$2005/yr")
68+
69+
population1990 = Variable(index=[country], unit="million")
70+
gdp1990 = Variable(index=[country], unit=unit = "billion US\$2005/yr")
71+
72+
co2_emissions = Variable(index=[time], unit="GtC/yr")
73+
ch4_emissions = Variable(index=[time], unit="MtCH4/yr")
74+
n2o_emissions = Variable(index=[time], unit="MtN2/yr")
75+
76+
function init(p, v, d)
7677

7778
# add countrys to a dictionary where each country key has a value holding it's
7879
# index in country_names
79-
country_lookup = Dict{String,Int}(name=>i for (i,name) in enumerate(p.country_names))
80+
country_lookup = Dict{String,Int}(name => i for (i, name) in enumerate(p.country_names))
8081
country_indices = d.country::Vector{Int} # helper for type stable country indices
8182

8283
# ----------------------------------------------------------------------
8384
# Socioeconomic Data
8485
# population in millions of individuals
8586
# GDP in billions of $2005 USD
86-
87+
8788
# Load Feather File
8889
t = Arrow.Table(joinpath(datadep"rffsps_v5", "pop_income", "rffsp_pop_income_run_$(p.id).feather"))
8990
fill_socioeconomics!(t.Year, t.Country, t.Pop, t.GDP, v.population, v.gdp, country_lookup, p.start_year, p.end_year)
9091

9192
for year in p.start_year:5:p.end_year-5, country in country_indices
9293
year_as_timestep = TimestepIndex(year - p.start_year + 1)
93-
pop_interpolator = LinearInterpolation(Float64[year, year+5], [log(v.population[year_as_timestep,country]), log(v.population[year_as_timestep+5,country])])
94-
gdp_interpolator = LinearInterpolation(Float64[year, year+5], [log(v.gdp[year_as_timestep,country]), log(v.gdp[year_as_timestep+5,country])])
94+
pop_interpolator = LinearInterpolation(Float64[year, year+5], [log(v.population[year_as_timestep, country]), log(v.population[year_as_timestep+5, country])])
95+
gdp_interpolator = LinearInterpolation(Float64[year, year+5], [log(v.gdp[year_as_timestep, country]), log(v.gdp[year_as_timestep+5, country])])
9596
for year2 in year+1:year+4
9697
year2_as_timestep = TimestepIndex(year2 - p.start_year + 1)
97-
v.population[year2_as_timestep,country] = exp(pop_interpolator[year2])
98-
v.gdp[year2_as_timestep,country] = exp(gdp_interpolator[year2])
98+
v.population[year2_as_timestep, country] = exp(pop_interpolator[year2])
99+
v.gdp[year2_as_timestep, country] = exp(gdp_interpolator[year2])
99100
end
100101
end
101-
102+
102103
# add global data for future accessibility and quality control
103-
v.gdp_global[:,:] = sum(v.gdp[:,:], dims = 2) # sum across countries, which are the second dimension
104-
v.population_global[:,:] = sum(v.population[:,:], dims = 2) # sum across countries, which are the second dimension
104+
v.gdp_global[:, :] = sum(v.gdp[:, :], dims=2) # sum across countries, which are the second dimension
105+
v.population_global[:, :] = sum(v.population[:, :], dims=2) # sum across countries, which are the second dimension
105106

106107
# ----------------------------------------------------------------------
107108
# Death Rate Data
@@ -113,7 +114,7 @@ end
113114
g_datasets[:pop_trajectory_key] = (load(joinpath(datadep"rffsps_v5", "sample_numbers", "sampled_pop_trajectory_numbers.csv")) |> DataFrame).x
114115
end
115116
deathrate_trajectory_id = convert(Int64, g_datasets[:pop_trajectory_key][p.id])
116-
117+
117118
# Load Feather File
118119
t = Arrow.Table(joinpath(datadep"rffsps_v5", "death_rates", "rffsp_death_rates_run_$(deathrate_trajectory_id).feather"))
119120
fill_deathrates!(t.Year, t.ISO3, t.DeathRate, v.deathrate, country_lookup, p.start_year, p.end_year)
@@ -124,28 +125,28 @@ end
124125
# carbon dioxide emissions in GtC
125126
# nitrous oxide emissions in MtN2
126127
# methane emissions in MtCH4
127-
128+
128129
# add data to the global dataset if it's not there
129130
if !haskey(g_datasets, :ch4)
130-
g_datasets[:ch4] = load(joinpath(datadep"rffsps_v5", "emissions", "rffsp_ch4_emissions.csv")) |>
131-
@groupby(_.sample) |>
132-
@orderby(key(_)) |>
133-
@map(DataFrame(year=_.year, value=_.value)) |>
134-
collect
131+
g_datasets[:ch4] = load(joinpath(datadep"rffsps_v5", "emissions", "rffsp_ch4_emissions.csv")) |>
132+
@groupby(_.sample) |>
133+
@orderby(key(_)) |>
134+
@map(DataFrame(year=_.year, value=_.value)) |>
135+
collect
135136
end
136137
if !haskey(g_datasets, :n2o)
137-
g_datasets[:n2o] = load(joinpath(datadep"rffsps_v5", "emissions", "rffsp_n2o_emissions.csv")) |>
138-
@groupby(_.sample) |>
139-
@orderby(key(_)) |>
140-
@map(DataFrame(year=_.year, value=_.value)) |>
141-
collect
138+
g_datasets[:n2o] = load(joinpath(datadep"rffsps_v5", "emissions", "rffsp_n2o_emissions.csv")) |>
139+
@groupby(_.sample) |>
140+
@orderby(key(_)) |>
141+
@map(DataFrame(year=_.year, value=_.value)) |>
142+
collect
142143
end
143144
if !haskey(g_datasets, :co2)
144-
g_datasets[:co2] = load(joinpath(datadep"rffsps_v5", "emissions", "rffsp_co2_emissions.csv")) |>
145-
@groupby(_.sample) |>
146-
@orderby(key(_)) |>
147-
@map(DataFrame(year=_.year, value=_.value)) |>
148-
collect
145+
g_datasets[:co2] = load(joinpath(datadep"rffsps_v5", "emissions", "rffsp_co2_emissions.csv")) |>
146+
@groupby(_.sample) |>
147+
@orderby(key(_)) |>
148+
@map(DataFrame(year=_.year, value=_.value)) |>
149+
collect
149150
end
150151

151152
# fill in the variales
@@ -160,15 +161,15 @@ end
160161
# Population and GDP 1990 Values
161162

162163
if !haskey(g_datasets, :ypc1990)
163-
g_datasets[:ypc1990] = load(joinpath(datadep"rffsps_v5", "ypc1990", "rffsp_ypc1990.csv")) |>
164-
DataFrame |>
165-
i -> insertcols!(i, :sample => 1:10_000) |>
166-
i -> DataFrames.stack(i, Not(:sample)) |>
167-
i -> rename!(i, [:sample, :country, :value]) |>
168-
@groupby(_.sample) |>
169-
@orderby(key(_)) |>
170-
@map(DataFrame(country=_.country, value=_.value)) |>
171-
collect
164+
g_datasets[:ypc1990] = load(joinpath(datadep"rffsps_v5", "ypc1990", "rffsp_ypc1990.csv")) |>
165+
DataFrame |>
166+
i -> insertcols!(i, :sample => 1:10_000) |>
167+
i -> DataFrames.stack(i, Not(:sample)) |>
168+
i -> rename!(i, [:sample, :country, :value]) |>
169+
@groupby(_.sample) |>
170+
@orderby(key(_)) |>
171+
@map(DataFrame(country=_.country, value=_.value)) |>
172+
collect
172173
end
173174
if !haskey(g_datasets, :pop1990)
174175
g_datasets[:pop1990] = load(joinpath(@__DIR__, "..", "..", "data/population1990.csv")) |> DataFrame
@@ -182,7 +183,7 @@ end
182183

183184
end
184185

185-
function run_timestep(p,v,d,t)
186+
function run_timestep(p, v, d, t)
186187

187188
if !(gettime(t) in p.start_year:p.end_year)
188189
error("Cannot run SP component in year $(gettime(t)), SP data is not available for this model and year.")

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ end
1515

1616
@testset "API" begin
1717
include("test_API.jl")
18-
end
18+
end

0 commit comments

Comments
 (0)