Sorsogon. Step 3.a Defining simple transition scenarios

In [1]:
import datetime; print(datetime.datetime.now())
2018-03-26 01:59:08.226709

Notebook Abstract:

The following notebook describes the process to construct simple transition scenarios.

The transition scenarios are define as efficiency rates induced by technology development or behavioral changes. These rates can be used as proxies for all types of efficiency improvements.

In order to define transition scenarios the model need the following information:

  1. A technology penetration rate. This defines the share of the population adopting the technology. The model uses sampling rules for the selection of the population adopting this technology.
  2. Development of efficiency rates. This define the actual technology development rate.

Import libraries

In [2]:
from smum.microsim.run import transition_rate
from smum.microsim.util_plot import plot_transition_rate
from smum.microsim.run import reduce_consumption
/usr/lib/python3.6/site-packages/h5py-2.7.1-py3.6-linux-x86_64.egg/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

In order to compute the transition scenarios we make use of three modules of the urbanmetabolism library:

  1. growth_rate. This module will return a vector with linear growth rates given a starting and end rate.
  2. plot_growth_rate. This a simple function to visualize the defined growth rates.
  3. reduce_consumption. This function creates new samples with reduced consumption levels for the selected selection of the population.

Define simple population selection rules

In [3]:
sampling_rules = {
    #"i_Education == 'Education_Elementary_School'": 100,
    "i_Education == 'Education_Post_Secondary'": 20,
    "i_Education == 'Education_College'":        20,
    "i_Education == 'Education_Post_Graduate'":  20,
    "i_Urbanity == 'Urbanity_Urban'":            30,
    "Income >= 180000":                          30
}

Part of the scenario development is to identified which section of the population will adopt the new technology. The model defined this by a sampling probability. This probability is initially define as a uniform distribution (i.e. each individual on the sample has equal probability of being selected). A scenario is defined by allocating new sampling probabilities to a section of the population, by defining sampling rules. The sampling rules are passes to the query function of a pandas DataFrame.

On the example above, all individuals with a Income larger of equal to 180 000 Philippine Pesos are 30 times more likely to adopt the technology that the rest of the population. The sampling probabilities will sum up. This means that an individual with Income >= 180000 and living on an urban area e_Urban == 'Urbanity_Urban' is 60 times more likely to be selected (i.e. adopt a new technology) that other individuals.

Initial sample data

In [4]:
import pandas as pd
file_name = "data/survey_Sorsogon_Electricity_Water_wbias_projected_dynamic_resampled_1000_{}.csv"
sample_survey = pd.read_csv(file_name.format(2010), index_col=0)
sample_survey.head()
Out[4]:
index i_Sex i_Urbanity i_FamilySize i_Age i_Education e_Lighting e_TV e_Cooking e_Refrigeration e_AC Income Electricity Water w wf
0 0 sex_male Urbanity_Rural Size_5 age_19_25 Education_Elementary_School Lighting_yes TV_yes Cooking_no Refrigeration_no AC_no 60354.807334 17.356259 36.414496 33.739938 37.150195
1 1 sex_male Urbanity_Rural Size_2 age_56_65 Education_College Lighting_yes TV_no Cooking_no Refrigeration_no AC_no 324476.009011 88.241617 217.607975 33.739938 36.127915
2 2 sex_male Urbanity_Rural Size_7 age_26_35 Education_Elementary_School Lighting_yes TV_yes Cooking_no Refrigeration_no AC_no 80395.582383 24.303869 52.374996 33.739938 51.494575
3 3 sex_male Urbanity_Urban Size_4 age_26_35 Education_College Lighting_yes TV_no Cooking_no Refrigeration_no AC_no 359650.342076 112.707133 247.005030 33.739938 46.852140
4 4 sex_male Urbanity_Rural Size_2 age_66_75 Education_Post_Secondary Lighting_yes TV_no Cooking_no Refrigeration_yes AC_no 178130.514100 58.126489 126.879872 33.739938 27.914082

The reduce_consumption module will use as input the samples created by the MCMC algorithm and select specific sections of the population to reduce their consumption levels.

The input data is the constructed proxy sample data. Depending on the simulation type (reweight/resample) the input data is a single file containing the weights for each simulation year (reweight) or individual samples for each simulation year (resample).

Most of the variables of the sample data is formatted as categorical data. The sample data shown above presents individual records with the predefine simulation variables as well as the computed Income, Electricity and Water consumption levels. The sample also contains two sets of weights: w and wf. The w weights correspond to the weights assign by the MCMC algorithm (uniform distributed) while the wf (final weights) are the weights computed by the GREGWT algorithm. The reduce_consumption function will use the wf weights for the selection of individuals.

In [5]:
sample_survey.loc[:, 'i_Education'].unique()
Out[5]:
array(['Education_Elementary_School', 'Education_College',
       'Education_Post_Secondary', 'Education_High_School',
       'Education_Post_Graduate'], dtype=object)
In [6]:
sample_survey.loc[:, ['i_Education', 'wf']].groupby('i_Education').sum().plot.bar();
../../_images/example_ph_Ca_DefineTransitions_14_0.png

Define growth rates

In [7]:
Elec  = transition_rate(0, 0.4, start=2016)
Water = transition_rate(0, 0.2, start=2016)
pr    = transition_rate(0, 0.3, start=2016)

With help of the growth_rate() function we define the efficiency growth rate and the technology penetration rate. For the technology penetration rate we define the start year to be equal to the benchmark year (2016). The function will automatically include the necessary zeros at the beginning of the growth rate vector. The function plot_growth_rate() allow us to visualize the predefined efficiency growth rates and the technology growth rates.

In [8]:
plot_transition_rate(
    {"Technology penetration rate": pr,
     "Electricity efficiency increase rate": Elec,
     "Water efficiency increase rate": Water},
     "scenario 1")
../../_images/example_ph_Ca_DefineTransitions_18_0.png

Reduce consumption

The actual modifications on the sample is performed by the reduce_consumption() function. The function requires as input the following parameters:

  1. A base file name for the samples (in case of implementing the resample method).
  2. The sample year (in this case generated within the loop via range(2010, 2031).
  3. The penetration rate for the sample year (iterated from vector pr).
  4. The predefined sampling_rules.
  5. A dictionary containing the efficiency rates for specific variables. (in this case for Electricity and Water).
  6. A name for the scenario.
In [9]:
for y, p, elec, water in zip(range(2010, 2031), pr, Elec, Water):
    _ = reduce_consumption(
        file_name,
        y, p, sampling_rules,
        {'Electricity':elec, 'Water':water},
        scenario_name = "scenario 1")
00.00%      both       reduction; efficiency rate 00.00%;              year 2010 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2011 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2012 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2013 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2014 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2015 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2016 and penetration rate 00.00
00.08%   Electricity   reduction; efficiency rate 02.86%;              year 2017 and penetration rate 00.02
00.04%      Water      reduction; efficiency rate 01.43%;              year 2017 and penetration rate 00.02
00.30%   Electricity   reduction; efficiency rate 05.71%;              year 2018 and penetration rate 00.04
00.16%      Water      reduction; efficiency rate 02.86%;              year 2018 and penetration rate 00.04
00.66%   Electricity   reduction; efficiency rate 08.57%;              year 2019 and penetration rate 00.06
00.36%      Water      reduction; efficiency rate 04.29%;              year 2019 and penetration rate 00.06
01.15%   Electricity   reduction; efficiency rate 11.43%;              year 2020 and penetration rate 00.09
00.63%      Water      reduction; efficiency rate 05.71%;              year 2020 and penetration rate 00.09
01.80%   Electricity   reduction; efficiency rate 14.29%;              year 2021 and penetration rate 00.11
00.97%      Water      reduction; efficiency rate 07.14%;              year 2021 and penetration rate 00.11
02.51%   Electricity   reduction; efficiency rate 17.14%;              year 2022 and penetration rate 00.13
01.38%      Water      reduction; efficiency rate 08.57%;              year 2022 and penetration rate 00.13
03.38%   Electricity   reduction; efficiency rate 20.00%;              year 2023 and penetration rate 00.15
01.87%      Water      reduction; efficiency rate 10.00%;              year 2023 and penetration rate 00.15
04.37%   Electricity   reduction; efficiency rate 22.86%;              year 2024 and penetration rate 00.17
02.37%      Water      reduction; efficiency rate 11.43%;              year 2024 and penetration rate 00.17
05.50%   Electricity   reduction; efficiency rate 25.71%;              year 2025 and penetration rate 00.19
03.00%      Water      reduction; efficiency rate 12.86%;              year 2025 and penetration rate 00.19
06.74%   Electricity   reduction; efficiency rate 28.57%;              year 2026 and penetration rate 00.21
03.64%      Water      reduction; efficiency rate 14.29%;              year 2026 and penetration rate 00.21
08.10%   Electricity   reduction; efficiency rate 31.43%;              year 2027 and penetration rate 00.24
04.36%      Water      reduction; efficiency rate 15.71%;              year 2027 and penetration rate 00.24
09.55%   Electricity   reduction; efficiency rate 34.29%;              year 2028 and penetration rate 00.26
05.09%      Water      reduction; efficiency rate 17.14%;              year 2028 and penetration rate 00.26
11.14%   Electricity   reduction; efficiency rate 37.14%;              year 2029 and penetration rate 00.28
05.92%      Water      reduction; efficiency rate 18.57%;              year 2029 and penetration rate 00.28
12.81%   Electricity   reduction; efficiency rate 40.00%;              year 2030 and penetration rate 00.30
06.76%      Water      reduction; efficiency rate 20.00%;              year 2030 and penetration rate 00.30
In [10]:
Elec  = transition_rate(0.0, 0.5, start=2016)
Water = transition_rate(0.0, 0.3, start=2016)
pr    = transition_rate(0.0, 0.6, start=2016)

By modifying the growht rates we can create different scenarios.

In [11]:
plot_transition_rate(
    {"Technology penetration rate": pr,
     "Electricity efficiency increase rate": Elec,
     "Water efficiency increase rate": Water},
     "scenario 2")
../../_images/example_ph_Ca_DefineTransitions_24_0.png
In [12]:
for y, p, elec, water in zip(range(2010, 2031), pr, Elec, Water):
    _ = reduce_consumption(
        file_name,
        y, p, sampling_rules,
        {'Electricity':elec, 'Water':water},
        scenario_name = "scenario 2")
00.00%      both       reduction; efficiency rate 00.00%;              year 2010 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2011 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2012 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2013 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2014 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2015 and penetration rate 00.00
00.00%      both       reduction; efficiency rate 00.00%;              year 2016 and penetration rate 00.00
00.19%   Electricity   reduction; efficiency rate 03.57%;              year 2017 and penetration rate 00.04
00.13%      Water      reduction; efficiency rate 02.14%;              year 2017 and penetration rate 00.04
00.74%   Electricity   reduction; efficiency rate 07.14%;              year 2018 and penetration rate 00.09
00.48%      Water      reduction; efficiency rate 04.29%;              year 2018 and penetration rate 00.09
01.63%   Electricity   reduction; efficiency rate 10.71%;              year 2019 and penetration rate 00.13
01.07%      Water      reduction; efficiency rate 06.43%;              year 2019 and penetration rate 00.13
02.87%   Electricity   reduction; efficiency rate 14.29%;              year 2020 and penetration rate 00.17
01.87%      Water      reduction; efficiency rate 08.57%;              year 2020 and penetration rate 00.17
04.44%   Electricity   reduction; efficiency rate 17.86%;              year 2021 and penetration rate 00.21
02.88%      Water      reduction; efficiency rate 10.71%;              year 2021 and penetration rate 00.21
06.22%   Electricity   reduction; efficiency rate 21.43%;              year 2022 and penetration rate 00.26
04.06%      Water      reduction; efficiency rate 12.86%;              year 2022 and penetration rate 00.26
08.43%   Electricity   reduction; efficiency rate 25.00%;              year 2023 and penetration rate 00.30
05.55%      Water      reduction; efficiency rate 15.00%;              year 2023 and penetration rate 00.30
10.90%   Electricity   reduction; efficiency rate 28.57%;              year 2024 and penetration rate 00.34
07.08%      Water      reduction; efficiency rate 17.14%;              year 2024 and penetration rate 00.34
13.65%   Electricity   reduction; efficiency rate 32.14%;              year 2025 and penetration rate 00.39
08.88%      Water      reduction; efficiency rate 19.29%;              year 2025 and penetration rate 00.39
16.66%   Electricity   reduction; efficiency rate 35.71%;              year 2026 and penetration rate 00.43
10.71%      Water      reduction; efficiency rate 21.43%;              year 2026 and penetration rate 00.43
20.00%   Electricity   reduction; efficiency rate 39.29%;              year 2027 and penetration rate 00.47
12.80%      Water      reduction; efficiency rate 23.57%;              year 2027 and penetration rate 00.47
23.72%   Electricity   reduction; efficiency rate 42.86%;              year 2028 and penetration rate 00.51
15.10%      Water      reduction; efficiency rate 25.71%;              year 2028 and penetration rate 00.51
27.54%   Electricity   reduction; efficiency rate 46.43%;              year 2029 and penetration rate 00.56
17.42%      Water      reduction; efficiency rate 27.86%;              year 2029 and penetration rate 00.56
31.73%   Electricity   reduction; efficiency rate 50.00%;              year 2030 and penetration rate 00.60
19.95%      Water      reduction; efficiency rate 30.00%;              year 2030 and penetration rate 00.60