Sorsogon. Step 2.b Non-Residential Model

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

Notebook abstract

This notebook shows the main sampling and reweighting algorithm for the non-residential sector.

Import libraries

In [2]:
from smum.microsim.util_plot import plot_data_projection
from smum.microsim.run import run_calibrated_model
from smum.microsim.table import TableModel

Global variables

In [3]:
iterations = 1000
benchmark_year = 2016
census_file = 'data/benchmarks_nonresidential.csv'
typ = 'resampled'
model_name = 'Sorsogon_NonResidentialElectricity_wbias_projected_dynamic_{}'.format(typ)
verbose = False
drop_col_survey = ['n_BuildingKwh']

Define model

In [4]:
table_model_name = 'data/table_elec_nr.csv'
estimate_var = 'NonRElectricity'
tm = TableModel(census_file = census_file, verbose=verbose)
tm.add_model(table_model_name, estimate_var, static = True)
#tm.update_dynamic_model(estimate_var, specific_col = 'BuildingKwh', static=True)
In [5]:
tm.models[estimate_var].loc[2020]
Out[5]:
co_mu co_sd p dis lb ub
n_BuildingSqm 719.5871280224214,312.5947515174914,1165.99458... 45.93150475011659,27.88881729659839,510.591052... 0.06084986413783436,0.09160606304100238,0.0106... Deterministic;n;Categorical NaN NaN
n_BuildingKwh 262,631,592,316,293,233,296,137,243 135.8105297832241,649.5509987676103,344.818792... 0.06084986413783436,0.09160606304100238,0.0106... Deterministic;BuildingSqm;Categorical NaN NaN
In [6]:
formula_nrb = " + ".join(["c_{0} * c_{0}".format(i) for i in tm.models[estimate_var].loc[2010].index])
tm.add_formula(formula_nrb, estimate_var)
table_model = tm.make_model()
tm.to_excel()
creating data/tableModel_NonRElectricity.xlsx
In [7]:
formula_nrb
Out[7]:
'c_n_BuildingSqm * c_n_BuildingSqm + c_n_BuildingKwh * c_n_BuildingKwh'

Run model

In [ ]:
fw = run_calibrated_model(
    table_model,
    verbose = verbose,
    project = typ,
    census_file = census_file,
    year = benchmark_year,
    population_size = False,
    name = '{}_{}'.format(model_name, iterations),
    iterations = iterations,
    align_census = False
    #drop_col_survey = drop_col_survey
)

Plot results

In [9]:
reweighted_survey = 'data/survey_{}_{}'.format(model_name, iterations)
In [10]:
data = plot_data_projection(
    reweighted_survey, [estimate_var], "{}, {}".format(iterations, typ),
    benchmark_year = benchmark_year, unit = "building")
../../_images/example_ph_Bb_GREGWT_NonResidential_16_0.png