lang = "en"
#lang = "tr"
import numpy as np
import matplotlib.pyplot as plt
import sys
import pandas as pd
import seaborn as sns
# DATA - UPDATE EACH YEAR AND PUT NEW VERSION OF THIS AS CODE ON https://commons.wikimedia.org/wiki/File:Greenhouse_gas_emission_and_absorption_by_Turkey.svg
#Labelling all the years is a bit busy so just label some
numyears=(np.arange(32)) #ADD 1 TO THIS WHEN YOU ADD A YEAR
xyears=['1990','','','','','1995','','','','','2000','','','','','2005','','','','','2010','','','','','2015','','','','','2020','2021']
#Please add population from Turkstat "Population by Years"
#The resulting GhG per person per year graph can be checked against that in Turkstat press releases
population = (53921760, 54840590, 64729501, 55748948, 56653804, 57564204, 58486456, 59423282, 60372568, 61329676, 62287397, 64729502, 64729503, 64729504, 68010215, 68860539, 69729967, 70586256, 71517100, 72561312, 73722988, 74724269, 75627384, 76667864, 77695904, 78741053, 79814871, 80810525, 82003882, 83154997, 83614362, 84680273)
# Data from https://di.unfccc.int/detailed_data_by_party
# Select Turkey, All Years, Totals, Aggregate GHG, Mt CO2 equivalent
# Cut and paste in here: 'Total GHG emissions excluding LULUCF'
# Older figures are sometimes revised so worth recopying them all occasionally - last copied April 2022 but only 2015 onwards
# However new data is likely to be released first in a press release by Turkstat which cannot easily be copied and pasted
year = ('1990','1991','1992','1993','1994','1995','1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021')
CO2 = [151.5, 158.0, 163.9, 171.0, 167.4, 180.9, 199.5, 212.0, 212.0, 207.8, 229.8, 213.5, 221.0, 236.5, 244.5, 264.2, 281.6, 312.7, 309.3, 315.4, 314.4, 339.5, 353.7, 345.2, 361.7, 384.3, 405.3, 430.2, 422.6, 401.7, 413.4, 452.7]
CH4_CO2eq = [ 42.5, 43.4, 43.3, 43.1, 42.8, 42.6, 43.0, 42.2, 42.4, 43.8, 43.7, 42.9, 41.0, 43.0, 43.5, 45.2, 46.6, 49.0, 49.9, 49.6, 51.4, 53.7, 57.1, 55.5, 57.5, 52.8, 55.6, 56.8, 60.3, 63.1, 64.0, 64.0]
N2O_CO2eq = [ 25.0, 24.7, 25.3, 26.0, 23.6, 23.9, 24.5, 24.0, 25.3, 25.6, 24.8, 23.3, 23.3, 24.6, 25.4, 26.2, 28.4, 27.6, 26.2, 28.5, 29.8, 30.9, 32.1, 34.1, 34.6, 32.3, 34.4, 35.6, 35.5, 37.0, 40.5, 40.3]
Fgases_CO2eq = [ 0.6, 0.9, 0.7, 0.4, 0.7, 0.6, 0.6, 0.6, 0.6, 0.6, 0.7, 0.8, 1.0, 1.2, 1.5, 1.7, 1.9, 2.3, 2.4, 2.4, 3.6, 4.0, 4.7, 4.8, 5.3, 5.1, 5.5, 5.7, 5.6, 6.3, 6.0, 7.4]
# Probably will not be in press release. Don't forget minus signs when copying and pasting fron National Inventory Report - probably in Table ES 3 Greenhouse gas emissions by sectors
LULUCF = [-55.7, -56.7, -56.9, -56.1, -57.6, -57.4, -57.6, -61.7, -62.7, -64.1, -61.6, -64.9, -72.6, -74.6, -73.7, -74.5, -74.8, -74.5, -69.5, -73.2, -73.6, -77.5, -74.8, -76.9, -77.9, -97.5, -96.0, -99.8, -94.4, -84.0, -56.9, -47.1]
# CALCULATION
# Could not see how to add more than 2 arrays
GHG_exc_LULUCF = np.add(CO2,CH4_CO2eq).tolist()
GHG_exc_LULUCF = np.add(GHG_exc_LULUCF,N2O_CO2eq).tolist()
GHG_exc_LULUCF = np.add(GHG_exc_LULUCF,Fgases_CO2eq).tolist()
# delete this? GHG_net = [163.4, 169.9, 175.9, 184.1, 176.7, 190.2, 209.5, 216.9, 217.7, 213.7, 237.3, 215.7, 213.6, 231.0, 241.3, 262.5, 283.4, 317.0, 318.4, 322.7, 325.2, 350.5, 372.5, 362.5, 380.5, 375.3, 401.8, 423.9, 426.4, 422.1, ]
# Therefore add don't subtract - alternatively could just copy and paste from NIR
GHG_inc_LULUCF = np.add(GHG_exc_LULUCF, LULUCF).tolist()
# left over from previous code - maybe can use to check GHG_exc_LULUCF_old = [219.20,226.58,232.80,240.15,234.13,247.58,267.23,278.61,280.29,277.76,298.89,280.41,286.07,305.60,314.95,337.21,358.15,391.42,387.59,395.52,398.66,427.57,446.94,438.97,457.96,472.19,498.47,523.8,520.9]
# EMISSION AND ABSORPTION BAR GRAPH
#Dataframe 1 for the bars
df1 = pd.DataFrame({'GHG_exc_LULUCF': GHG_exc_LULUCF, 'LULUCF': LULUCF}, index=year)
#Dataframe 2 for the line
df2 = pd.DataFrame({'GHG_inc_LULUCF': GHG_inc_LULUCF}, index=year)
ax=df1.plot(kind='bar', stacked=True, color = ['grey', 'green'])
df2.plot(ax=ax)
#Avoid chopping off xlabel at bottom
plt.gcf().subplots_adjust(bottom=0.15)
#Label years
plt.xticks(ticks=numyears, labels=xyears)
#Vertical years so we can see which bar is which year
plt.xticks(rotation=90)
#Don't need the frame
sns.despine(bottom = True, left = True)
#Don't need the dash marks
ax.tick_params(left=False, bottom=False)
if lang == "en":
ax.set_title ("Greenhouse gases emitted in Turkey", fontsize = 'xx-large')
ax.set_ylabel("Million metric tons of carbon dioxide equivalent")
# ax.figure.text(0.99, 0.01, 'Source: https://di.unfccc.int/detailed_data_by_party', ha='right', va='bottom', fontsize='small', color='grey')
ax.set_xlabel('Source: https://di.unfccc.int/detailed_data_by_party', fontsize = 'small', color = 'grey')
plt.legend(['Net emissions', 'Emissions: mostly by fossil fuels','Absorption: mostly by forests'])
elif lang == "tr":
ax.set_title ("Türkiye’de sera gazı emisyonu", fontsize = 'xx-large')
ax.set_ylabel("Milyon ton karbon dioksit eşdeğer")
ax.set_xlabel('Kaynak: https://di.unfccc.int/detailed_data_by_party', fontsize = 'small', color = 'grey')
plt.legend(['net emisyonlar', 'emisyonlar: en çok fosil yakıt','emme: en çok orman'])
else:
print("Unknown language " + lang)
sys.exit()
# Save graphic
if lang == "en":
plt.savefig("Greenhouse gas emission and absorption by Turkey.svg")
elif lang == "tr":
plt.savefig("sera_gazlar_Türkiye_emisyon_emme.svg")
else:
print("Unknown language " + lang)
sys.exit()
# Show graphic
plt.show()
# GASES LINE GRAPH
color_CO2 = "black"
color_CH4 = "brown"
color_N2O = "khaki"
color_Fgases = "pink"
plt.plot(year, CO2, color=color_CO2)
plt.plot(year, CH4_CO2eq, color=color_CH4)
plt.plot(year, N2O_CO2eq, color=color_N2O)
plt.plot(year, Fgases_CO2eq, color=color_Fgases)
#Avoid chopping off xlabel at bottom
plt.gcf().subplots_adjust(bottom=0.15)
#Label years
plt.xticks(ticks=numyears, labels=xyears)
#Vertical years as otherwise may overlap
plt.xticks(rotation=90)
#Don't need the left part of frame
sns.despine(left = True)
#Don't need the dash marks
plt.tick_params(left=False, bottom=False)
#Start at zero to show how small f-gas is
plt.ylim(0)
#Chemical formula to label lines are same all languages
label_CO2 = "CO₂"
label_CH4 = "CH₄"
label_N2O = "N₂O"
if lang == "en":
plt.title ("Greenhouse gases emitted in Turkey",fontsize = 'x-large')
plt.ylabel("Million metric tons of carbon dioxide equivalent")
plt.xlabel('Source: https://di.unfccc.int/detailed_data_by_party', fontsize = 'small', color = 'grey')
label_Fgases = "F-gases"
elif lang == "tr":
plt.title ("Türkiye'de atmosfere giden karbondioksit eşdeğer",fontsize = 'x-large')
plt.ylabel("Megatonne")
plt.xlabel('Kaynak: https://di.unfccc.int/detailed_data_by_party', fontsize = 'small', color = 'grey')
label_Fgases = "F-gazlar"
else:
print("Unknown language: " + lang)
sys.exit()
#Position labels manually to make them quicker to read than a legend in a corner - might need slight adjustment as years added
plt.text(32,445,label_CO2, fontsize = 'large')
plt.text(32, 60,label_CH4, fontsize = 'large')
plt.text(32, 30,label_N2O, fontsize = 'large')
plt.text(32, 5,label_Fgases, fontsize = 'large')
# Save graphic
if lang == "en":
plt.savefig("ghg_gases_by_year_Turkey.svg")
elif lang == "tr":
plt.savefig("sera_gazlar_Türkiye.svg")
else:
print("Unknown language " + lang)
sys.exit()
# Show graphic
plt.show()
# PER PERSON LINE GRAPH
pop_millions = np.divide(population,1000000)
GHG_inc_LULUCF_per_person = np.divide(GHG_inc_LULUCF,pop_millions)
GHG_exc_LULUCF_per_person = np.divide(GHG_exc_LULUCF,pop_millions)
plt.plot(year, GHG_inc_LULUCF_per_person)
plt.plot(year, GHG_exc_LULUCF_per_person)
#Label years
plt.xticks(ticks=numyears, labels=xyears)
#Vertical years so we can see which year is which
plt.xticks(rotation=90)
#Don't need the frame
sns.despine(bottom = True, left = True)
#Don't need the dash marks
plt.tick_params(left=False, bottom=False)
#Start at zero to show that eventually country should go to net zero
plt.ylim(0)
if lang == "en":
plt.title ("Greenhouse gases emitted per person in Turkey",fontsize = 'x-large')
plt.ylabel("Tonnes")
plt.xlabel('Source: https://di.unfccc.int/detailed_data_by_party', fontsize = 'small', color = 'grey')
label_inc_LULUCF = "Inc. LULUCF"
label_exc_LULUCF = "Exc. LULUCF"
elif lang == "tr":
plt.title ("Türkiye'de atmosfere giden karbondioksit kişi başı",fontsize = 'x-large')
plt.ylabel("Tonne")
plt.xlabel('Kaynak: https://di.unfccc.int/detailed_data_by_party', fontsize = 'small', color = 'grey')
label_inc_LULUCF = "net"
label_exc_LULUCF = "brut"
else:
print("Unknown language: " + lang)
sys.exit()
#Position labels manually to make them quicker to read than a legend in a corner - might need slight adjustment as years added
plt.text(32, 6.1 ,label_inc_LULUCF, fontsize = 'large')
plt.text(32, 6.5 ,label_exc_LULUCF, fontsize = 'large')
#Avoid chopping off xlabel at bottom
plt.tight_layout()
# Save graphic
if lang == "en":
plt.savefig("ghg_per_person_Turkey.svg")
elif lang == "tr":
plt.savefig("sera_gazlar_Türkiye_kişi_başı.svg")
else:
print("Unknown language " + lang)
sys.exit()
# Show graphic
plt.show()