<jupyter_start><jupyter_text>Set carbon emission targetsIn this notebook a target for the emission is set and the required tax rate is calculated. This involves inverting the model, and takes some time.  The target growth of emission is the same for all country. In another notebook the target growth match a given reduction relative to "business as usual". That notebook can be accessed through the overview notebook. This notebook can be run by \ \ in the menu. This shows the raw Jupyuter notebook. The other notebooks are initialy displayed as slideshows.<jupyter_code># Import modelflow

%load_ext autoreload
%autoreload 2
%matplotlib inline

import matplotlib.pyplot as plt

from ipywidgets import interact,Dropdown,Checkbox
from IPython.display import display, clear_output,Latex, Markdown
import pandas as pd

import modelmf
import modeljupyter as mj
from modelvis import waterplot

from modelinvert import targets_instruments
from modelclass import model
model.widescreen()

model.scroll_off()
# Load model and data, and run 

masia,baseline = model.modelload('Asia_8nov.pcim',run=1,silent=1,ljit=0,stringjit=False)
from inject import inject
inject(masia)  
masia.lastdf = masia.basedf.copy()<jupyter_output><empty_output><jupyter_text>Parameters in this experiment<jupyter_code>countries_of_interest = [country for country in masia.countries_ASEAN if country not in ['BRN','SGP']]
                         
instruments = [[f'{country}_GCARBR_A'] for country in countries_of_interest]
target_var  = [f'{country}_CO2' for country in countries_of_interest]
delay = 3
target_growth = 1.01<jupyter_output><empty_output><jupyter_text>The instrument variables<jupyter_code>print(instruments)<jupyter_output>[['KHM_GCARBR_A'], ['IDN_GCARBR_A'], ['LAO_GCARBR_A'], ['MYS_GCARBR_A'], ['MMR_GCARBR_A'], ['PHL_GCARBR_A'], ['THA_GCARBR_A'], ['VNM_GCARBR_A']]<jupyter_text>The target variables<jupyter_code>print(target_var)<jupyter_output>['KHM_CO2', 'IDN_CO2', 'LAO_CO2', 'MYS_CO2', 'MMR_CO2', 'PHL_CO2', 'THA_CO2', 'VNM_CO2']<jupyter_text>Emission in Business as usual scenario<jupyter_code>model.plot_basis('target_var',df = masia.basedf.loc[2010:,target_var].rename(columns=masia.var_description),legend=1);<jupyter_output><empty_output><jupyter_text>Carbon tax in Business as usual scenario<jupyter_code>model.plot_basis('instruments',df = masia.basedf.loc[2010:,[i[0][:-2] for i in instruments]].rename(columns=masia.var_description),legend=1);<jupyter_output><empty_output><jupyter_text>Lets look at the impact of increasing the tax with 10 in 2022<jupyter_code>experiment = baseline.copy()
experiment.loc[2022,instrumentlist]= experiment.loc[2022,(instrumentlist := [i[0] for i in instruments])] + 10 
result = masia(experiment,progressbar = 0,silent=1)
masia[target_var].difpctlevel.mul100.rename().plot(
    colrow  = 1,title = 'Impact of tax increase of \$10/tonne in percent of "Business as usual"  ',top=0.96,sharey=0,dec=2);
masia[target_var].dif.df;<jupyter_output><empty_output><jupyter_text>Define a dataframe with with target growth rates in $CO^2$<jupyter_code>target_before = baseline[target_var].loc[2022+delay-1:,:]
calclines = '\n'.join(f'{t} = {t}(-1) * (1+{target_growth}/100)' for t in target_var)
target = target_before.mfcalc(calclines).loc[2022:,:]<jupyter_output><empty_output><jupyter_text>Show the target developement in emision<jupyter_code>if 1:
    t = pd.concat([target_before.rename(columns={c: 'BaU '+c for c in target_before.columns}),
                   target.rename(columns={c: 'Target '+c for c in target_before.columns})],axis=1)
    t.plot()<jupyter_output><empty_output><jupyter_text>Setup the Target/instrument device<jupyter_code>t_i_baseline = baseline.copy()
t_i = targets_instruments(databank=t_i_baseline,targets=target,instruments=instruments,
                          model=masia,DefaultImpuls=10,defaultconv=0.5,varimpulse=True,nonlin=4,silent=0)<jupyter_output><empty_output><jupyter_text>Run the device. And fetch a cup of coffee. Serious calculations are to be performed<jupyter_code>t_i.debug=0
res = t_i(delay=delay,shortfall=0)
masia.smpl(2022,2022)
t_i.jaco
masia.MMR_GCARBR<jupyter_output><empty_output><jupyter_text>The target is nearly meet. The delay causes a slight difference to the target<jupyter_code>with masia.set_smpl(2024,2050):

    masia['LAO_co2 idn_co2'].pct.mul100.rename().plot(
        title=f'Reaching emision target growth rate {target_growth:,.2f}',colrow=1,top=0.8,sharey=0);<jupyter_output><empty_output><jupyter_text>Emission and tax after inverting the model<jupyter_code>with masia.set_smpl(2010,2050):
    for country in countries_of_interest:
        masia[f'{country}_co2' ].plot_alt(title=f'{masia.iso_dict[country]} ',top=0.88);        
        masia[f'{country}_GCARBR' ].plot_alt(title=f' ',top=0.90);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11857379767827529, 'fraction_numerical': 0.026119402985074626, 'mean_word_length': 6.935855263157895, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '284767', 'license': 'MIT', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1717, 'n_words': 360, 'path': 'Asia/Set carbon emission targets.ipynb', 'repo_name': 'IbHansen/UNESCAP-Asia', 'size': '4824'}