@@ -2,7 +2,7 @@ using Mimi, CSVFiles, DataFrames, Query, Interpolations, Arrow, CategoricalArray
2
2
import IteratorInterfaceExtensions, Tables
3
3
4
4
# (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=
5
- const pricelevel_2011_to_2005 = 87.504 / 98.164
5
+ const pricelevel_2011_to_2005 = 87.504 / 98.164
6
6
7
7
function fill_socioeconomics! (source_Year, source_Country, source_Pop, source_GDP, population, gdp, country_lookup, start_year, end_year)
8
8
for i in 1 : length (source_Year)
63
63
end_year = Parameter {Int} (default= Int (2300 )) # year (annual) data should end
64
64
country_names = Parameter {String} (index= [country]) # need the names of the countries from the dimension
65
65
id = Parameter {Int64} (default= Int (6546 )) # the sample (out of 10,000) to be used
66
-
67
- population = Variable (index= [time, country], unit= " million" )
68
- population_global = Variable (index= [time], unit= " million" )
69
- deathrate = Variable (index= [time, country], unit= " deaths/1000 persons/yr" )
70
- gdp = Variable (index= [time, country], unit= " billion US\$ 2005/yr" )
71
- gdp_global = Variable (index= [time], unit= " billion US\$ 2005/yr" )
72
-
73
- population1990 = Variable (index= [country], unit = " million" )
74
- gdp1990 = Variable (index= [country], unit = unit= " billion US\$ 2005/yr" )
75
-
76
- co2_emissions = Variable (index= [time], unit= " GtC/yr" )
77
- ch4_emissions = Variable (index= [time], unit= " MtCH4/yr" )
78
- n2o_emissions = Variable (index= [time], unit= " MtN2/yr" )
79
-
80
- function init (p,v, d)
66
+
67
+ population = Variable (index= [time, country], unit= " million" )
68
+ population_global = Variable (index= [time], unit= " million" )
69
+ deathrate = Variable (index= [time, country], unit= " deaths/1000 persons/yr" )
70
+ gdp = Variable (index= [time, country], unit= " billion US\$ 2005/yr" )
71
+ gdp_global = Variable (index= [time], unit= " billion US\$ 2005/yr" )
72
+
73
+ population1990 = Variable (index= [country], unit= " million" )
74
+ gdp1990 = Variable (index= [country], unit= unit = " billion US\$ 2005/yr" )
75
+
76
+ co2_emissions = Variable (index= [time], unit= " GtC/yr" )
77
+ ch4_emissions = Variable (index= [time], unit= " MtCH4/yr" )
78
+ n2o_emissions = Variable (index= [time], unit= " MtN2/yr" )
79
+
80
+ function init (p, v, d)
81
81
82
82
# add countrys to a dictionary where each country key has a value holding it's
83
83
# index in country_names
84
- country_lookup = Dict {String,Int} (name=> i for (i,name) in enumerate (p. country_names))
84
+ country_lookup = Dict {String,Int} (name => i for (i, name) in enumerate (p. country_names))
85
85
country_indices = d. country:: Vector{Int} # helper for type stable country indices
86
86
87
87
# ----------------------------------------------------------------------
88
88
# Socioeconomic Data
89
89
# population in millions of individuals
90
90
# GDP in billions of $2005 USD
91
-
91
+
92
92
# Load Feather File
93
93
t = Arrow. Table (joinpath (datadep " rffsps_v5" , " pop_income" , " rffsp_pop_income_run_$(p. id) .feather" ))
94
94
fill_socioeconomics! (t. Year, t. Country, t. Pop, t. GDP, v. population, v. gdp, country_lookup, p. start_year, p. end_year)
95
95
96
96
for year in p. start_year: 5 : p. end_year- 5 , country in country_indices
97
97
year_as_timestep = TimestepIndex (year - p. start_year + 1 )
98
- pop_interpolator = LinearInterpolation (Float64[year, year+ 5 ], [log (v. population[year_as_timestep,country]), log (v. population[year_as_timestep+ 5 ,country])])
99
- gdp_interpolator = LinearInterpolation (Float64[year, year+ 5 ], [log (v. gdp[year_as_timestep,country]), log (v. gdp[year_as_timestep+ 5 ,country])])
98
+ pop_interpolator = LinearInterpolation (Float64[year, year+ 5 ], [log (v. population[year_as_timestep, country]), log (v. population[year_as_timestep+ 5 , country])])
99
+ gdp_interpolator = LinearInterpolation (Float64[year, year+ 5 ], [log (v. gdp[year_as_timestep, country]), log (v. gdp[year_as_timestep+ 5 , country])])
100
100
for year2 in year+ 1 : year+ 4
101
101
year2_as_timestep = TimestepIndex (year2 - p. start_year + 1 )
102
- v. population[year2_as_timestep,country] = exp (pop_interpolator[year2])
103
- v. gdp[year2_as_timestep,country] = exp (gdp_interpolator[year2])
102
+ v. population[year2_as_timestep, country] = exp (pop_interpolator[year2])
103
+ v. gdp[year2_as_timestep, country] = exp (gdp_interpolator[year2])
104
104
end
105
105
end
106
-
106
+
107
107
# add global data for future accessibility and quality control
108
- v. gdp_global[:,:] = sum (v. gdp[:,:], dims = 2 ) # sum across countries, which are the second dimension
109
- v. population_global[:,:] = sum (v. population[:,:], dims = 2 ) # sum across countries, which are the second dimension
108
+ v. gdp_global[:, :] = sum (v. gdp[:, :], dims= 2 ) # sum across countries, which are the second dimension
109
+ v. population_global[:, :] = sum (v. population[:, :], dims= 2 ) # sum across countries, which are the second dimension
110
110
111
111
# ----------------------------------------------------------------------
112
112
# Death Rate Data
118
118
g_datasets[:pop_trajectory_key ] = (load (joinpath (datadep " rffsps_v5" , " sample_numbers" , " sampled_pop_trajectory_numbers.csv" )) |> DataFrame). x
119
119
end
120
120
deathrate_trajectory_id = convert (Int64, g_datasets[:pop_trajectory_key ][p. id])
121
-
121
+
122
122
# Load Feather File
123
123
t = Arrow. Table (joinpath (datadep " rffsps_v5" , " death_rates" , " rffsp_death_rates_run_$(deathrate_trajectory_id) .feather" ))
124
124
fill_deathrates! (t. Year, t. ISO3, t. DeathRate, v. deathrate, country_lookup, p. start_year, p. end_year)
129
129
# carbon dioxide emissions in GtC
130
130
# nitrous oxide emissions in MtN2
131
131
# methane emissions in MtCH4
132
-
132
+
133
133
# add data to the global dataset if it's not there
134
134
if ! haskey (g_datasets, :ch4 )
135
135
g_datasets[:ch4 ] = load (joinpath (datadep " rffsps_v5" , " emissions" , " rffsp_ch4_emissions.csv" )) |> DataFrame
@@ -150,13 +150,13 @@ end
150
150
# Population and GDP 1990 Values
151
151
152
152
if ! haskey (g_datasets, :ypc1990 )
153
- g_datasets[:ypc1990 ] = load (joinpath (datadep " rffsps_v5" , " ypc1990" , " rffsp_ypc1990.csv" )) |>
154
- DataFrame |>
155
- i -> insertcols! (i, :sample => 1 : 10_000 ) |>
156
- i -> stack (i, Not (:sample )) |>
157
- DataFrame |>
158
- i -> rename! (i, [:sample , :country , :value ]) |>
159
- DataFrame
153
+ g_datasets[:ypc1990 ] = load (joinpath (datadep " rffsps_v5" , " ypc1990" , " rffsp_ypc1990.csv" )) |>
154
+ DataFrame |>
155
+ i -> insertcols! (i, :sample => 1 : 10_000 ) |>
156
+ i -> stack (i, Not (:sample )) |>
157
+ DataFrame |>
158
+ i -> rename! (i, [:sample , :country , :value ]) |>
159
+ DataFrame
160
160
end
161
161
if ! haskey (g_datasets, :pop1990 )
162
162
g_datasets[:pop1990 ] = load (joinpath (@__DIR__ , " .." , " .." , " data/population1990.csv" )) |> DataFrame
167
167
168
168
end
169
169
170
- function run_timestep (p,v,d, t)
170
+ function run_timestep (p, v, d, t)
171
171
172
172
if ! (gettime (t) in p. start_year: p. end_year)
173
173
error (" Cannot run SP component in year $(gettime (t)) , SP data is not available for this model and year." )
0 commit comments