<jupyter_start><jupyter_text>Westeros Tutorial Part 2a.i - Introducing emissionsIn the first part, the model chose not base the power system on wind power as electricity from  wind turbines was more expensive than electricity produced from coal. However, now we introduce emissions to investigate the impact of climate policy. Let's see what happens then.**Pre-requisites**- You have the *MESSAGEix* framework installed and working- You have run Westeros baseline scenario (``westeros_baseline.ipynb``) and solved it successfully<jupyter_code>import pandas as pd
import ixmp
import message_ix

from message_ix.utils import make_df

%matplotlib inline
mp = ixmp.Platform()
model = 'Westeros Electrified'

base = message_ix.Scenario(mp, model=model, scenario='baseline')
scen = base.clone(model, 'emission_bound','introducing an upper bound on emissions',
                  keep_solution=False)
scen.check_out()
year_df = scen.vintage_and_active_years()
vintage_years, act_years = year_df['year_vtg'], year_df['year_act']
model_horizon = scen.set('year')
country = 'Westeros'<jupyter_output><empty_output><jupyter_text>Introducing Emissions<jupyter_code># first we introduce the emission of CO2 and the emission category GHG
scen.add_set('emission', 'CO2')
scen.add_cat('emission', 'GHG', 'CO2')

# we now add CO2 emissions to the coal powerplant
base_emission_factor = {
    'node_loc': country,
    'year_vtg': vintage_years,
    'year_act': act_years,
    'mode': 'standard',
    'unit': 'tCO2/kWa',
}

# adding new units to the model library (needed only once)
mp.add_unit('tCO2/kWa')
mp.add_unit('MtCO2')

emission_factor = make_df(base_emission_factor, technology= 'coal_ppl', emission= 'CO2', value = 7.4)
scen.add_par('emission_factor', emission_factor)<jupyter_output><empty_output><jupyter_text>Define a Bound on EmissionsThe `type_year: cumulative` assigns an upper bound on the *weighted average of emissions* over the entire time horizon.<jupyter_code>scen.add_par('bound_emission', [country, 'GHG', 'all', 'cumulative'],
             value=500., unit='MtCO2')<jupyter_output><empty_output><jupyter_text>Time to Solve the Model<jupyter_code>scen.commit(comment='introducing emissions and setting an upper bound')
scen.set_as_default()
scen.solve()
scen.var('OBJ')['lvl']<jupyter_output><empty_output><jupyter_text>Plotting Results<jupyter_code>from tools import Plots
p = Plots(scen, country, firstyear=700)<jupyter_output><empty_output><jupyter_text>ActivityHow much energy is generated in each time period from the different potential sources?<jupyter_code>p.plot_activity(baseyear=True, subset=['coal_ppl', 'wind_ppl'])<jupyter_output><empty_output><jupyter_text>CapacityHow much capacity of each plant is installed in each period?<jupyter_code>p.plot_capacity(baseyear=True, subset=['coal_ppl', 'wind_ppl'])<jupyter_output><empty_output><jupyter_text>Electricity PriceAnd how much does the electricity cost? These prices are in fact **shadow prices** taken from the **dual variables** of the model solution. They reflect the marginal cost of electricity generation (i.e., the additional cost of the system for supplying one more unit of electricity), which is in fact the marginal cost of the most expensive generator.  Note the price drop when the most expensive technology is no longer in the system.<jupyter_code>p.plot_prices(subset=['light'], baseyear=True)<jupyter_output><empty_output><jupyter_text>Close the connection to the database<jupyter_code>mp.close_db()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1010244735344337, 'fraction_numerical': 0.005122367672168469, 'mean_word_length': 6.988636363636363, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '98166', 'license': 'Apache-2.0', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1092, 'n_words': 324, 'path': 'tutorial/westeros/westeros_emissions_bounds.ipynb', 'repo_name': 'ardasha93/message_ix', 'size': '3514'}