<jupyter_start><jupyter_text>Aj tak za to može Čína- **Emise skleníkových plynů pod drobnohledem**  - Jaké jsou skleníkové plyny  - Přepočet na CO2eq -> jak moc do toho zabíhat?  - - **Proč nedává smysl porovnávat emise SR a Číny? A kdy to smysl dává?**  - Obdélníčky Čína vs SR - šířka = počet obyvatel, výška = emise na osobu  - Srovnání s dalšími státy? Například pozice SK v rámci EU, následně srovnání EU s Čínou?  - Doplnit, o kolik by se to změnilo při uvážení obchodu  - Bylo by hezké mít historické emise...- **Jak počítáme emise z jednotlivých sektorů hospodářství?**  - Koláč? O té metodologii toho moc nevím...- **Jak se dají emise snížit a komu se to už podařilo?**  - Jak: Mitigační opatření podle IMF  - Komu se podařilo: ?  Data loading<jupyter_code>import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
mpl.rc_file_defaults()
import world_bank_data as wb
# POPULATION
pop_raw = wb.get_series('SP.POP.TOTL', id_or_value='id')
pop = pop_raw.reset_index().query('Year == "2015"')[['Country', 'SP.POP.TOTL']].rename(columns={'Country': 'code', 'SP.POP.TOTL': 'pop'})
pop = pop[np.isfinite(pop['pop'])]  # there are two countries with no population data
pop['pop'] = np.int_(pop['pop'])
pop = pop.sort_values('code').reset_index(drop=True)
pop.head()
# GDP
gdp_raw = wb.get_series('NY.GDP.MKTP.PP.KD', id_or_value='id')
gdp = gdp_raw.reset_index().query('Year == "2015"')[['Country', 'NY.GDP.MKTP.PP.KD']] \
    .rename(columns={'Country': 'code', 'NY.GDP.MKTP.PP.KD': 'gdp'}) \
    .sort_values('code') \
    .reset_index(drop=True)
gdp.head()
# GREENHOUSE GASES
ghgs = ['CO2', 'CH4', 'N2O']
edgar_files = ['CO2_excl_short-cycle_org_C', 'CH4', 'N2O']
edgar = None

for gas in ghgs:
    ef = 'CO2_excl_short-cycle_org_C' if gas == 'CO2' else gas
    ey = 2018 if gas == 'CO2' else 2015
    filename = f'../data/edgar/v5.0/v50_{ef}_1970_{ey}.xls'
    frame = pd.read_excel(filename, sheet_name='TOTALS BY COUNTRY', header=9)
    frame = frame[['ISO_A3'] + list(range(1970, ey + 1))].rename(columns={'ISO_A3': 'code'}).set_index('code')
    frame.columns = frame.columns.rename('year')
    frame = frame.unstack().rename(gas).reset_index()
    frame = frame[~frame['code'].isin(['SEA', 'AIR'])]
    if edgar is None:
        edgar = frame
    else:
        edgar = pd.merge(edgar, frame, how='outer')

ghg = edgar.query('year == 2015').drop(columns=['year']).sort_values('code').reset_index(drop=True)
ghg['ghg'] = ghg['CO2'] + 28 * ghg['CH4'] + 265 * ghg['N2O']
ghg.head()
regions = pd.read_csv('../data/regions.csv', keep_default_na=False)[['code', 'region_B_en', 'continent_en']] \
    .rename(columns={'region_B_en': 'region', 'continent_en': 'continent'}) \
    .query('region != ""')

countries = pd.merge(regions, pop)
countries = pd.merge(countries, gdp)
countries = pd.merge(countries, ghg[['code', 'ghg']])

countries.head()<jupyter_output><empty_output><jupyter_text>This is enough<jupyter_code>df = pd.read_csv('../data/world-emissions-2015.csv')
# make the units more sane - and create per capita and per gdp columns
df['ghg'] = df['ghg'] / 1e3  # in million tonnes (rather than in gigagrams, i.e. thousand tonnes)
df['gdp_per_capita'] = df['gdp'] / df['pop']
df['ghg_per_capita'] = 1e6 * df['ghg'] / df['pop']  # in tonnes per capita
df['ghg_per_gdp'] = 1e12 * df['ghg'] / df['gdp']  # in grams per dollar
regions = pd.read_csv('../data/regions.csv', keep_default_na=False)[['code', 'name_en', 'name_cz']]
df = pd.merge(df, regions)
df.head()<jupyter_output><empty_output><jupyter_text>Charts<jupyter_code># zakladni srovnani SK vs China (SVK, CHN)
df = df.set_index('code')
svk = df.loc['SVK']
chn = df.loc['CHN']

svk_color = '#4591CE'
# chn_color = '#C32B2A'
chn_color = '#DF2407' # this is the Chinese flag color, but it's too bright
df.loc['SVK']
fig, ax = plt.subplots()

xgap = 5e6
# plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['country'], rotation=45, fontsize=9)
rec_svk = mpl.patches.Rectangle((xgap, 0), svk['pop'], svk['ghg_per_capita'], ec=None, fc=svk_color)
rec_chn = mpl.patches.Rectangle((2 * xgap + svk['pop'], 0), chn['pop'], chn['ghg_per_capita'], ec=None, fc=chn_color)
ax.add_patch(rec_svk)
ax.add_patch(rec_chn)

ax.set(xlim=(0, 1.5e9), ylim=(0, 10))
ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='CO2eq emissions per capita (2018)')

plt.show()<jupyter_output><empty_output><jupyter_text>China![China](https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Flag_of_the_People's_Republic_of_China.svg/1280px-Flag_of_the_People's_Republic_of_China.svg.png)<jupyter_code>fig, ax = plt.subplots()

xgap = 5e6
# plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['country'], rotation=45, fontsize=9)
rec_chn = mpl.patches.Rectangle((0, 0), chn['pop'], chn['ghg_per_capita'], ec=None, fc=chn_color)
ax.add_patch(rec_chn)

svk_ghg = svk['pop'] * svk['ghg_per_capita']
svk_fake_pop = 7e7
rec_svk = mpl.patches.Rectangle((0, 0), svk_fake_pop, svk_ghg / svk_fake_pop, ec=None, fc=svk_color)
ax.add_patch(rec_svk)

ax.set(xlim=(0, 1.5e9), ylim=(0, 10))
ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='CO2eq emissions per capita (2015)')
plt.axis('off')

plt.show()
fig, ax = plt.subplots()

xgap = 5e6
# plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['country'], rotation=45, fontsize=9)
rec_chn = mpl.patches.Rectangle((0, 0), chn['pop'], chn['ghg_per_capita'], ec=None, fc=chn_color)
ax.add_patch(rec_chn)

svk_ghg = svk['pop'] * svk['ghg_per_capita']
svk_fake_pop = 7e7
rec_svk = mpl.patches.Rectangle((0, 0), svk['pop'], svk['ghg_per_capita'], ec=None, fc=svk_color)
ax.add_patch(rec_svk)

ax.set(xlim=(0, 1.5e9), ylim=(0, 10))
#ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='CO2eq emissions per capita (2015)')
plt.axis('off')

plt.show()
fig, ax = plt.subplots()

xgap = 5e6
# plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['country'], rotation=45, fontsize=9)
rec_chn = mpl.patches.Rectangle((0, 0), chn['pop'], chn['ghg_per_capita'], ec=None, fc=chn_color, alpha=1)
ax.add_patch(rec_chn)

svk_ghg = svk['pop'] * svk['ghg_per_capita']
svk_fake_pop = 7e7
rec_svk = mpl.patches.Rectangle((0, 0), svk['pop'], svk['ghg_per_capita'], ec=None, fc=svk_color)
ax.add_patch(rec_svk)

ax.set(xlim=(0, 1.5e9), ylim=(0, 10))
ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='CO2eq emissions per capita (2015)')
#plt.axis('off')

plt.show()
svk
chn
# SVK in EU context
# - I need EU countries in alpha3 iso codes
eu_codes = ['AUT', 'BEL', 'BGR', 'HRV', 'CYP', 'CZE', 'DNK', 'EST', 'FIN', 'FRA', 'DEU', 'GRC', 'HUN', 'IRL',
      'ITA', 'LVA', 'LTU', 'LUX', 'MLT', 'NLD', 'POL', 'PRT', 'ROU', 'SVK', 'SVN', 'ESP', 'SWE']
fig, ax = plt.subplots()

x = 0
# xgap = 2e6
xgap = 0
ygap = 0.4
eu_color = '#666666'

for i, row in df.loc[eu_codes].sort_values('ghg_per_capita', ascending=False).iterrows():
    x = x + xgap
    plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['name_en'], rotation=45, fontsize=9, alpha=0.3)
    if i == 'SVK':
        plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['name_en'], rotation=45, fontsize=9)
    rec = mpl.patches.Rectangle((x, 0), row['pop'], row['ghg_per_capita'], ec=None, fc=svk_color if i == 'SVK' else eu_color)
    ax.add_patch(rec)
    x = x + row['pop']

ax.set(xlim=(0, 4.5e8), ylim=(0, 20))
ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='EU CO2eq emissions per capita (2015)')

plt.show()
eu = df.loc[eu_codes][['pop', 'ghg', 'gdp']].sum()
eu['gdp_per_capita'] = eu['gdp'] / eu['pop']
eu['ghg_per_capita'] = 1e6 * eu['ghg'] / eu['pop']  # in tonnes per capita
eu['ghg_per_gdp'] = 1e12 * eu['ghg'] / eu['gdp']  # in grams per dollar
fig, ax = plt.subplots()

# plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['country'], rotation=45, fontsize=9)
rec_eu = mpl.patches.Rectangle((0, 0), eu['pop'], eu['ghg_per_capita'], ec=None, fc=eu_color, alpha=1)
ax.add_patch(rec_eu)
rec_svk = mpl.patches.Rectangle((0, 0), svk['pop'], svk['ghg_per_capita'], ec=None, fc=svk_color)
ax.add_patch(rec_svk)

ax.set(xlim=(0, 4.5e8), ylim=(0, 10))
ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='CO2eq emissions per capita (2015)')
#plt.axis('off')

plt.show()
fig, ax = plt.subplots()

# plt.text(x + 0.5 * row['pop'] - 4 * xgap, row['ghg_per_capita'] + ygap, row['country'], rotation=45, fontsize=9)
rec_chn = mpl.patches.Rectangle((0, 0), chn['pop'], chn['ghg_per_capita'], ec=None, fc=chn_color, alpha=1)
ax.add_patch(rec_chn)
rec_eu = mpl.patches.Rectangle((0, 0), eu['pop'], eu['ghg_per_capita'], ec=None, fc=eu_color, alpha=1)
ax.add_patch(rec_eu)
rec_svk = mpl.patches.Rectangle((0, 0), svk['pop'], svk['ghg_per_capita'], ec=None, fc=svk_color)
ax.add_patch(rec_svk)

ax.set(xlim=(0, 1.5e9), ylim=(0, 10))
ax.set(xlabel='Population', ylabel='t CO2eq per capita', title='CO2eq emissions per capita (2015)')
#plt.axis('off')

plt.show()
df.loc[eu_codes].sort_values('ghg_per_capita', ascending=False).head()
# SVK vs CHN GDP per capita
fig, ax = plt.subplots(figsize=(9, 3))
sns.barplot(x='gdp_per_capita', y='name_en', data=df.loc[['SVK', 'CHN']], palette=[svk_color, chn_color], ax=ax)
ax.set(xlabel='GDP per capita (PPP, constant 2017 international $)', ylabel='')
ax.set_title('GDP per capita, Slovakia vs China')
plt.show()
# SVK emissions embedded in trade (and comparison with China)
# - check what data is available and<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19714047171780422, 'fraction_numerical': 0.030160718012940933, 'mean_word_length': 5.414323962516733, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '37199', 'license': 'MIT', 'n_tokens_mistral': 4391, 'n_tokens_neox': 4156, 'n_words': 856, 'path': 'misc/2021-03-06_SK-emissions.ipynb', 'repo_name': 'protivinsky/fakta-o-klimatu', 'size': '9582'}