%run ~/STILT_modules_v2.5.ipynb
%run ~/ICOS_atmObs_modules_v2.5.ipynb
%run ~/for_thesis.ipynb
stations = create_STILT_dictionary()
import matplotlib
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import math
import numpy as np
from matplotlib.legend import Legend
list_stations_for_analysis=select_stations()
It is also possible to write the name of one, or several, more stations to base the analysis on
only_selection_stations=list_stations_for_analysis.value
all_stations=[]
for value in only_selection_stations:
all_stations.append(value)
additional_station=input('Write additional station(s) here, otherwise leave blank. If several, seperate by whitespace: ')
list_additional_station = additional_station.split()
for item in list_additional_station:
all_stations.append(str(item))
print('Your selection is: ', all_stations)
dictionary_whole_notebook={}
for station in all_stations:
dictionary_whole_notebook[station]={}
icos_stations = [ist[0:3] for ist in all_stations]
ICOS_files = get_ICOS_filename(icos_stations,download=True)
date_range, timeselect, start_date, end_date = date_range_date_hour()
date_index_number = (len(date_range) - 1)
The different source- and fuel categories are the same as the breakdown displayed at ICOS-CP's webpage
#only one dictionary needs info about start date, end date etc...
anthro_bio_sensitivity={}
anthro_bio_sensitivity['info']={}
anthro_bio_sensitivity['info']['date_min']=(str(date_range[0].year) + '-' + str(date_range[0].month) + '-' + str(date_range[0].day))
anthro_bio_sensitivity['info']['date_max']=(str(date_range[date_index_number].year) + '-' + str(date_range[date_index_number].month) + '-' + str(date_range[date_index_number].day))
anthro_bio_sensitivity['info']['hours']=(str(timeselect))
anthro_bio_sensitivity['info']['stations']=all_stations
fuel_category_sensitivity={}
source_category_sensitivity={}
station_iterator=iter(all_stations)
for station in station_iterator:
anthro_bio_sensitivity[station]={}
source_category_sensitivity[station]={}
fuel_category_sensitivity[station]={}
df = read_stilt_timeseries(station, date_range)
#averages --> default skip nan
df_mean=df.mean()
anthro_bio_sensitivity[station]['bio']=df_mean['co2.bio']
anthro_bio_sensitivity[station]['anthro']=(df_mean['co2.industry']+df_mean['co2.energy']+ df_mean['co2.transport']+ df_mean['co2.others'])
source_category_sensitivity[station]['energy']=df_mean['co2.industry']
source_category_sensitivity[station]['industry']=df_mean['co2.energy']
source_category_sensitivity[station]['transport']=df_mean['co2.transport']
source_category_sensitivity[station]['other']=df_mean['co2.others']
fuel_category_sensitivity[station]['oil']=df_mean['co2.fuel.oil']
fuel_category_sensitivity[station]['coal']=df_mean['co2.fuel.coal']
fuel_category_sensitivity[station]['gas']=df_mean['co2.fuel.gas']
fuel_category_sensitivity[station]['bio']=df_mean['co2.fuel.bio']
#standard deviation --> default skip nan
#not used currently
df_std=df.std()
matplotlib.rcParams.update({'font.size': 17})
y_pos = np.arange(1)
figure(num=None, figsize=(12, 8), dpi=80, facecolor='w', edgecolor='k')
ax = plt.subplot(111)
ax.yaxis.grid(True)
#stacked on top of each other for bar graph.
for_transport=df_mean['co2.industry']+df_mean['co2.energy']
for_others = for_transport + df_mean['co2.transport']
for_gas= df_mean['co2.fuel.oil'] + df_mean['co2.fuel.coal']
for_bio = for_gas + df_mean['co2.fuel.gas']
for_cement_production= for_bio + df_mean['co2.fuel.bio']
for_waste_burning=for_cement_production + df_mean['co2.cement']
#the remaining contribution comes from emissions from waste burning
waste_burning = (df_mean['co2.energy']+df_mean['co2.industry']+df_mean['co2.transport'] +df_mean['co2.others']) - for_waste_burning
p1 = ax.bar(y_pos-0.75, df_mean['co2.bio'],width=0.2,color='g',align='center')
#total anthropgenic = sum of the source categories
p2 = ax.bar(y_pos-0.25, (df_mean['co2.energy']+df_mean['co2.industry']+df_mean['co2.transport'] +df_mean['co2.others']),width=0.2,color='r',align='center')
#source categories
p3 = ax.bar(y_pos+0.25, df_mean['co2.industry'],width=0.2,color='dimgrey',align='center')
p4 = ax.bar(y_pos+0.25, df_mean['co2.energy'], bottom=df_mean['co2.industry'], width=0.2,color='orange', hatch="/")
p5 = ax.bar(y_pos+0.25, df_mean['co2.transport'],bottom=for_transport,width=0.2,color='maroon',align='center')
p6 = ax.bar(y_pos+0.25, df_mean['co2.others'],bottom=for_others,width=0.2,color='peru',align='center')
#fuel + cement + waste burning
p7 = ax.bar(y_pos+0.75, df_mean['co2.fuel.oil'] ,width=0.2,color='lightcoral',align='center')
p8 = ax.bar(y_pos+0.75, df_mean['co2.fuel.coal'] , bottom=df_mean['co2.fuel.oil'], width=0.2,color='lightskyblue',align='center')
p9 = ax.bar(y_pos+0.75, df_mean['co2.fuel.gas'] ,bottom=for_gas, width=0.2,color='brown',align='center')
p10 = ax.bar(y_pos+0.75, df_mean['co2.fuel.bio'] ,bottom=for_bio,width=0.2,color='green',align='center')
p11 = ax.bar(y_pos+0.75, df_mean['co2.cement'], bottom=for_cement_production,width=0.2,color='grey',align='center', hatch="/")
p12 = ax.bar(y_pos+0.75, waste_burning, bottom=for_waste_burning,width=0.2,color='blue',align='center')
#ax.legend((p1[0], p2[0],p3[0],p4[0],p5[0],p6[0],p7[0],p8[0],p9[0],p10[0], p11[0]), ('Biogenic contribution','Anthropogenic contribution', 'Industry', 'Energy', 'Transport', 'Other', 'Oil', 'Coal', 'Gas', 'Bio', 'Cement production'))
ax.legend((p1[0], p2[0]), ('Biogenic contribution','Anthropogenic contribution'), loc='upper left')
leg = Legend(ax, (p6[0],p5[0],p4[0],p3[0]), ('Others', 'Transport', 'Industry', 'Energy'), loc='lower center')
ax.add_artist(leg)
leg2 = Legend(ax, (p12[0],p11[0],p10[0],p9[0],p8[0],p7[0]), ('Waste burning','Cement production', 'Bio fuel', 'Gas', 'Coal', 'Oil'), loc='lower right')
ax.add_artist(leg2)
plt.ylabel('ppm')
plt.axhline(0, color='black', lw=2)
#list_labels=['Anthropogenic', 'Biogenic', 'Source categories', 'Fuel categories']
plt.xticks(y_pos)
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False)
date_index_number = (len(date_range) - 1)
title= ('Biogenic vs. anthropogenic contribution at ' + str(station) + '\n' + str(date_range[0].year) + '-' + str(date_range[0].month) + '-' + str(date_range[0].day) + ' to ' + str(date_range[date_index_number].year) +\
'-' + str(date_range[date_index_number].month) + '-' + str(date_range[date_index_number].day)+ '\n' + 'Hour(s): ' + str(timeselect))
plt.title(title)
plt.show()
The data can be displayed in bar- or pie charts for each footprint in the date range (beware of a possibly a lot of output figures!)
station_iterator=iter(all_stations)
emis_type=input("Select emission category to display: source_categories, fuel_categories or anthro_bio: ")
if emis_type=='source_categories' or emis_type=='fuel_categories':
display_type=input("Choose how to display the data: bar or pie: ")
for station in station_iterator:
df = read_stilt_timeseries(station, date_range)
for date in date_range:
if df.empty:
print ('no STILT data for defined date range for '), station
else:
for_title = (station + ' at ' + str(date)+ '\n'+ 'Modelled CO2 concentration: ' + str("%.2f" % df['co2.stilt'][date]))
if emis_type=='fuel_categories':
colors = ['lightcoral', 'lightskyblue', 'brown', 'green']
if display_type=='pie':
figure(num=None, figsize=(7, 4), dpi=80, facecolor='w', edgecolor='k')
oil_label = ('Oil: ' + str("%.2f" % df['co2.fuel.oil'][date])+ ' ppm')
coal_label = ('Coal: ' + str("%.2f" % df['co2.fuel.coal'][date])+ ' ppm')
gas_label = ('Gas: ' + str("%.2f" % df['co2.fuel.gas'][date])+ ' ppm')
bio_label = ('Fuel bio: ' + str("%.2f" %df['co2.fuel.bio'][date])+ ' ppm')
labels = oil_label, coal_label, gas_label,bio_label
sizes = [(df['co2.fuel.oil'][date]*1000) , (df['co2.fuel.coal'][date]*1000), (df['co2.fuel.gas'][date]*1000), (df['co2.fuel.bio'][date]*1000)]
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.2f%%', radius = 4)
plt.axis('equal')
plt.title(for_title, loc='center')
ax = plt.subplot(111)
ax.yaxis.grid(True)
plt.show()
if display_type == 'bar':
figure(num=None, figsize=(7, 4), dpi=80, facecolor='w', edgecolor='k')
objects = ('Oil', 'Coal', 'Gas', 'Bio')
y_pos = np.arange(len(objects))
sizes = [df['co2.fuel.oil'][date], df['co2.fuel.coal'][date], df['co2.fuel.gas'][date], df['co2.fuel.bio'][date]]
plt.bar(y_pos,
sizes,
color=colors,
align='center')
plt.xticks(y_pos, objects)
plt.ylabel('ppm')
plt.title(for_title, loc='center')
ax = plt.subplot(111)
ax.yaxis.grid(True)
plt.show()
if emis_type=='source_categories':
colors = ['dimgrey', 'orange', 'maroon', 'peru']
if display_type=='pie':
figure(num=None, figsize=(7, 4), dpi=80, facecolor='w', edgecolor='k')
industry_label = ('Industry: ' + str("%.2f" % df['co2.industry'][date])+ ' ppm')
energy_label = ('Energy: ' + str("%.2f" % df['co2.energy'][date])+ ' ppm')
transport_label = ('Transport: ' + str("%.2f" % df['co2.transport'][date])+ ' ppm')
others_label = ('Others: ' + str("%.2f" %df['co2.others'][date])+ ' ppm')
labels = industry_label, energy_label, transport_label,others_label
sizes = [(df['co2.industry'][date]*1000) , (df['co2.energy'][date]*1000), (df['co2.transport'][date]*1000), (df['co2.others'][date]*1000)]
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.2f%%', radius = 8)
plt.axis('equal')
plt.title(for_title, loc='center')
ax = plt.subplot(111)
ax.yaxis.grid(True)
plt.show()
if display_type == 'bar':
figure(num=None, figsize=(7, 4), dpi=80, facecolor='w', edgecolor='k')
objects = ('Industry', 'Energy', 'Transport', 'Others')
y_pos = np.arange(len(objects))
sizes = [df['co2.industry'][date], df['co2.energy'][date], df['co2.transport'][date], df['co2.others'][date]]
plt.bar(y_pos,
sizes,
color=colors,
align='center')
plt.xticks(y_pos, objects)
plt.ylabel('ppm')
plt.title(for_title, loc='center')
ax = plt.subplot(111)
ax.yaxis.grid(True)
plt.show()
if emis_type=='anthro_bio':
colors=['red','green']
figure(num=None, figsize=(7, 4), dpi=80, facecolor='w', edgecolor='k')
objects = ('Anthro', 'Bio')
y_pos = np.arange(len(objects))
sizes = [(df['co2.industry'][date]+df['co2.energy'][date]+ df['co2.transport'][date]+ df['co2.others'][date]), df['co2.bio'][date]]
plt.bar(y_pos,
sizes,
color=colors,
align='center')
plt.xticks(y_pos, objects)
plt.ylabel('ppm')
plt.title(for_title, loc='center')
ax = plt.subplot(111)
ax.yaxis.grid(True)
plt.show()
A bar graph displaying average anthropogenic and biogenic contribution will always be an output when running this cell
The second bar graph contains a breakdown of the anthropogenic emission where the user can choose between source and fuel categories
source_category_input=input("Select emission category to display: source_categories or fuel_categories ")
#one for each station --> just update the names of the lists.
bio_list= []
anthro_list =[]
station_list = []
anthro_bio_list =[]
if source_category_input == 'source_categories':
industry_list =[]
energy_list=[]
transport_list= []
others_list = []
if source_category_input == 'fuel_categories':
oil_list =[]
coal_list = []
gas_list = []
biofuel_list = []
station_iterator=iter(all_stations)
for station in station_iterator:
df = read_stilt_timeseries(station, date_range)
df_mean=df.mean()
if df.empty:
print('no STILT data for defined date range for ', station)
else:
station_list.append(station)
bio_list.append(df_mean['co2.bio'])
anthro_list.append(df_mean['co2.industry']+df_mean['co2.energy']+ df_mean['co2.transport']+ df_mean['co2.others'])
anthro_bio_list.append(df_mean['co2.bio']+ df_mean['co2.industry']+df_mean['co2.energy']+ df_mean['co2.transport']+ df_mean['co2.others'])
#this function runs once for each station and returns the averages that are calculated within the function.
if source_category_input == 'source_categories':
industry_list.append(df_mean['co2.industry'])
energy_list.append(df_mean['co2.energy'])
transport_list.append(df_mean['co2.transport'])
others_list.append(df_mean['co2.others'])
if source_category_input == 'fuel_categories':
oil_list.append(df_mean['co2.fuel.oil'])
coal_list.append(df_mean['co2.fuel.coal'])
gas_list.append(df_mean['co2.fuel.gas'])
biofuel_list.append(df_mean['co2.fuel.bio'])
matplotlib.rcParams.update({'font.size': 19})
sorted_bio_list = [x for _,x in sorted(zip(anthro_list,bio_list))]
sorted_station_list = [x for _,x in sorted(zip(anthro_list,station_list))]
sorted_anthro_list= [x for _,x in sorted(zip(anthro_list,anthro_list))]
sorted_anthro_bio_list =[x for _,x in sorted(zip(anthro_list,anthro_bio_list))]
y_pos = np.arange(len(sorted_station_list))
figure(num=None, figsize=(22, 10), dpi=80, facecolor='w', edgecolor='k')
ax = plt.subplot(111)
p1 = ax.bar(y_pos-0.2, sorted_anthro_bio_list ,width=0.19,color='b',align='center')
p2 = ax.bar(y_pos+0, sorted_anthro_list ,width=0.19,color='r',align='center')
p3 = ax.bar(y_pos+0.2, sorted_bio_list,width=0.19,color='g',align='center', hatch="/")
ax.legend((p1[0], p2[0],p3[0]), ('Total (Anthro+bio)','Anthropogenic', 'Bio') )
plt.ylabel('ppm')
plt.xticks(y_pos, sorted_station_list, rotation='vertical')
plt.axhline(0, color='black', lw=2)
ax.yaxis.grid(True)
#get the index of the last date (start at 0) to access it in the titles
date_index_number = (len(date_range) - 1)
plt.title('Average contribution/uptake of CO2: anthropogenic vs bio by station (ppm)' + '\n' + 'Filtered by smallest to largest anthropogenic contribution' + '\n' + str(date_range[0].year) + '-' + str(date_range[0].month) + '-' + str(date_range[0].day)\
+ ' to ' + str(date_range[date_index_number].year) + '-' + str(date_range[date_index_number].month) + '-' + str(date_range[date_index_number].day)+ '\n' +\
'Hour(s): ' + timeselect)
plt.show()
if source_category_input == 'source_categories':
sorted_industry_list = [x for _,x in sorted(zip(anthro_list,industry_list))]
sorted_energy_list = [x for _,x in sorted(zip(anthro_list,energy_list))]
sorted_transport_list = [x for _,x in sorted(zip(anthro_list,transport_list))]
sorted_others_list = [x for _,x in sorted(zip(anthro_list,others_list))]
y_pos = np.arange(len(sorted_station_list))
figure(num=None, figsize=(20, 10), dpi=80, facecolor='w', edgecolor='k')
ax = plt.subplot(111)
ax.yaxis.grid(True)
for_transport=[x + y for x, y in zip(sorted_industry_list,sorted_energy_list)]
for_others =[x + y + z for x, y, z in zip(sorted_industry_list,sorted_energy_list,sorted_transport_list)]
p1 = ax.bar(y_pos, sorted_industry_list ,width=0.2,color='dimgrey',align='center')
p2 = ax.bar(y_pos, sorted_energy_list, bottom=sorted_industry_list, width=0.2,color='orange',align='center', hatch="/")
p3 = ax.bar(y_pos, sorted_transport_list,bottom=for_transport, width=0.2,color='maroon',align='center')
p4 = ax.bar(y_pos, sorted_others_list, bottom=for_others, width=0.2,color='peru',align='center')
ax.legend((p4[0], p3[0], p2[0], p1[0]), ('Others', 'Transport','Energy','Industry'))
plt.xticks(y_pos, sorted_station_list, rotation='vertical')
plt.ylabel('ppm')
ax.yaxis.grid(True)
plt.title('Average contribution (ppm) by source categories for selected stations' + '\n' + 'Filtered smallest to largest anthropogenic contribution' + '\n' + str(date_range[0].year) + '-' + str(date_range[0].month) + '-' + str(date_range[0].day)\
+ ' to ' + str(date_range[date_index_number].year) + '-' + str(date_range[date_index_number].month) + '-' + str(date_range[date_index_number].day)+ '\n' +\
'Hour(s): ' + timeselect)
plt.show()
if source_category_input == 'fuel_categories':
sorted_oil_list = [x for _,x in sorted(zip(anthro_list,oil_list))]
sorted_coal_list = [x for _,x in sorted(zip(anthro_list,coal_list))]
sorted_gas_list = [x for _,x in sorted(zip(anthro_list,gas_list))]
sorted_biofuel_list = [x for _,x in sorted(zip(anthro_list,biofuel_list))]
y_pos = np.arange(len(sorted_station_list))
figure(num=None, figsize=(25, 10), dpi=80, facecolor='w', edgecolor='k')
ax = plt.subplot(111)
ax.yaxis.grid(True)
for_gas=[x + y for x, y in zip(sorted_oil_list,sorted_coal_list)]
for_biofuel =[x + y + z for x, y, z in zip(sorted_oil_list,sorted_coal_list,sorted_gas_list)]
p1 = ax.bar(y_pos, sorted_oil_list,width=0.2,color='lightcoral',align='center')
p2 = ax.bar(y_pos, sorted_coal_list,bottom=sorted_oil_list,width=0.2,color='lightskyblue',align='center')
p3 = ax.bar(y_pos, sorted_gas_list,bottom=for_gas,width=0.2,color='brown',align='center')
p4 = ax.bar(y_pos, sorted_biofuel_list,bottom=for_biofuel,width=0.2,color='green',align='center')
ax.legend((p4[0], p3[0], p2[0], p1[0]), ('Biofuel', 'Gas', 'Coal', 'Oil'))
ax.yaxis.grid(True)
plt.xticks(y_pos, sorted_station_list)
plt.ylabel('ppm')
#get the index of the last date (start at 0) to access it in the titles
date_index_number = (len(date_range) - 1)
plt.title('Average contribution (ppm) by fuel categories for selected stations' + '\n' + 'Filtered smallest to largest anthropogenic contribution' + '\n' + str(date_range[0].year) + '-' + str(date_range[0].month) + '-' + str(date_range[0].day)\
+ ' to ' + str(date_range[date_index_number].year) + '-' + str(date_range[date_index_number].month) + '-' + str(date_range[date_index_number].day)+ '\n' +\
'Hour(s): ' + timeselect)
plt.show()
Two new date ranges will be defined in this cell
The date ranges anthropogenic and biogenic contributions are output into the same bar graph
In a second bar graph, the defined date ranges are compared in terms of th anthropogenic contribution either
split fuel or source categories
date_range1, timeselect1, start_date1, end_date1=date_range_date_hour()
date_range2, timeselect2, start_date2, end_date2=date_range_date_hour()
source_category_input=input("Select emission category to display: source_categories or fuel_categories ")
list_date_range = [date_range1, date_range2]
matplotlib.rcParams.update({'font.size': 17})
bio_list_both = []
station_list_both = []
anthro_list_both =[]
industry_both = []
energy_both= []
transport_both=[]
others_both = []
oil_both = []
coal_both = []
gas_both = []
biofuel_both = []
stations_missing_data_both=[]
index_first=0
for each_date_range in list_date_range:
bio_list= []
anthro_list =[]
station_list = []
anthro_bio_list =[]
stations_missing_data=[]
if source_category_input == 'source_categories':
industry_list =[]
energy_list=[]
transport_list= []
others_list = []
if source_category_input == 'fuel_categories':
oil_list =[]
coal_list = []
gas_list = []
biofuel_list = []
station_iterator=iter(all_stations)
for station in station_iterator:
if index_first==0:
df = read_stilt_timeseries(station, date_range1)
else:
df = read_stilt_timeseries(station, date_range2)
df_mean=df.mean()
if df.empty:
print ('no STILT data for defined date range ', date_range, 'for station ', station)
stations_missing_data.append(station)
else:
station_list.append(station)
bio_list.append(df_mean['co2.bio'])
anthro_list.append(df_mean['co2.industry']+df_mean['co2.energy']+ df_mean['co2.transport']+ df_mean['co2.others'])
#this function runs once for each station and returns the averages that are calculated within the function.
if source_category_input == 'source_categories':
industry_list.append(df_mean['co2.industry'])
energy_list.append(df_mean['co2.energy'])
transport_list.append(df_mean['co2.transport'])
others_list.append(df_mean['co2.others'])
if source_category_input == 'fuel_categories':
oil_list.append(df_mean['co2.fuel.oil'])
coal_list.append(df_mean['co2.fuel.coal'])
gas_list.append(df_mean['co2.fuel.gas'])
biofuel_list.append(df_mean['co2.fuel.bio'])
#looping over the date_ranges, adding one list from each for each category
station_list_both.append(station_list)
stations_missing_data_both.append(stations_missing_data)
bio_list_both.append(bio_list)
anthro_list_both.append(anthro_list)
if source_category_input == 'source_categories':
industry_both.append(industry_list)
energy_both.append(energy_list)
transport_both.append(transport_list)
others_both.append(others_list)
if source_category_input == 'fuel_categories':
oil_both.append(oil_list)
coal_both.append(coal_list)
gas_both.append(gas_list)
biofuel_both.append(biofuel_list)
index_first=index_first+1
if len(stations_missing_data_both[0])>0 or len(stations_missing_data_both[1])>0:
for each_station in stations_missing_data_both[0]:
print (each_station, ' misses data in the first specified date range. Exclude station from this analysis or run the STILT footprint tool')
for each_station in stations_missing_data_both[1]:
print (each_station, ' misses data in the first specified date range. Exclude station from this analysis or run the STILT footprint tool')
#plot if have all data:
else:
anthro_list_one =anthro_list_both[0]
bio_list_one = bio_list_both[0]
anthro_list_two =anthro_list_both[1]
bio_list_two = bio_list_both[1]
#will be the same for both --> no missing stations
station_list = station_list_both[0]
#sorting by lowest anthropogenic contribution in date range one.
sorted_anthro_list_one = [x for _,x in sorted(zip(anthro_list_one,anthro_list_one))]
sorted_bio_list_one = [x for _,x in sorted(zip(anthro_list_one,bio_list_one))]
sorted_anthro_list_two = [x for _,x in sorted(zip(anthro_list_one,anthro_list_two))]
sorted_bio_list_two = [x for _,x in sorted(zip(anthro_list_one,bio_list_two))]
sorted_station_list = [x for _,x in sorted(zip(anthro_list_one,station_list))]
figure(num=None, figsize=(22, 11), dpi=80, facecolor='w', edgecolor='k')
y_pos = np.arange(len(sorted_station_list))
ax = plt.subplot(111)
p1 = ax.bar(y_pos-0.3, sorted_bio_list_one,width=0.19,color='g',align='center', hatch="/")
p2 = ax.bar(y_pos-0.1, sorted_anthro_list_one, width=0.19,color='r',align='center')
p3 = ax.bar(y_pos+0.1, sorted_bio_list_two ,width=0.19,color='yellowgreen',align='center',hatch="/")
p4 = ax.bar(y_pos+0.3, sorted_anthro_list_two,width=0.19,color='darkorange',align='center')
ax.legend((p1[0], p2[0], p3[0], p4[0]), ('Biogenic component date range one', 'Anthropogenic contribution date range one','Biogenic component date range two', 'Anthropogenic component date range two'))
ax.yaxis.grid(True)
plt.xticks(y_pos, sorted_station_list, rotation='vertical')
plt.axhline(0, color='black', lw=2)
#get the index of the last date (start at 0) to access it in the titles
date_index_number1 = (len(date_range1) - 1)
date_index_number2 = (len(date_range2) - 1)
plt.title('Comparing andthropogenic contribution and the biogenic component' + '\n' + 'Date range one: ' + str(date_range1[0].year) + '-' + str(date_range1[0].month) + '-' + str(date_range1[0].day)\
+ ' to ' + str(date_range1[date_index_number1].year) + '-' + str(date_range1[date_index_number1].month) + '-' + str(date_range1[date_index_number1].day)+ ' Hour(s): ' + timeselect1\
+ '\n' + 'Date range two: ' + str(date_range2[0].year) + '-' + str(date_range2[0].month) + '-' + str(date_range2[0].day)\
+ ' to ' + str(date_range2[date_index_number2].year) + '-' + str(date_range2[date_index_number2].month) + '-' + str(date_range2[date_index_number2].day)+ ' Hour(s): ' + timeselect2)
plt.ylabel('ppm')
plt.show()
if source_category_input == 'source_categories':
industry_list_one =industry_both[0]
energy_list_one = energy_both[0]
transport_list_one =transport_both[0]
others_list_one =others_both[0]
industry_list_two =industry_both[1]
energy_list_two = energy_both[1]
transport_list_two =transport_both[1]
others_list_two =others_both[1]
#sorting lowest anthropogenic contribution in date range one.
sorted_industry_list_one = [x for _,x in sorted(zip(anthro_list_one,industry_list_one))]
sorted_energy_list_one = [x for _,x in sorted(zip(anthro_list_one,energy_list_one))]
sorted_transport_list_one = [x for _,x in sorted(zip(anthro_list_one,transport_list_one))]
sorted_others_list_one = [x for _,x in sorted(zip(anthro_list_one,others_list_one))]
sorted_industry_list_two = [x for _,x in sorted(zip(anthro_list_one,industry_list_two))]
sorted_energy_list_two = [x for _,x in sorted(zip(anthro_list_one,energy_list_two))]
sorted_transport_list_two = [x for _,x in sorted(zip(anthro_list_one,transport_list_two))]
sorted_others_list_two = [x for _,x in sorted(zip(anthro_list_one,others_list_two))]
figure(num=None, figsize=(22, 10), dpi=80, facecolor='w', edgecolor='k')
y_pos = np.arange(len(sorted_station_list))
ax = plt.subplot(111)
p1 = ax.bar(y_pos-0.4, sorted_industry_list_one,width=0.09,color='dimgrey',align='center')
p1 = ax.bar(y_pos-0.3, sorted_industry_list_two ,width=0.09,color='dimgrey',align='center')
p3 = ax.bar(y_pos-0.2, sorted_energy_list_one,width=0.09,color='orange',align='center',hatch="/")
p4 = ax.bar(y_pos-0.1, sorted_energy_list_two,width=0.09,color='orange',align='center',hatch="/")
p5 = ax.bar(y_pos+0.0, sorted_transport_list_one,width=0.09,color='maroon',align='center')
p6 = ax.bar(y_pos+0.1, sorted_transport_list_two,width=0.09,color='maroon',align='center')
p7 = ax.bar(y_pos+0.2, sorted_others_list_one,width=0.09,color='peru',align='center')
p8 = ax.bar(y_pos+0.3, sorted_others_list_two,width=0.09,color='peru',align='center')
ax.legend((p1[0], p3[0],p5[0], p7[0]), ('Industry contribution', 'Energy contribution', 'Transport contribution', 'Other contribution') )
ax.yaxis.grid(True)
plt.xticks(y_pos, sorted_station_list, rotation='vertical')
#add graph for source categories/fuel categories. maybe need to make figure even bigger.
plt.title('Comparing contribution of the different source categories, over two date ranges' + '\n' + 'Date range one (left): ' + str(date_range1[0].year) + '-' + str(date_range1[0].month) + '-' + str(date_range1[0].day)\
+ ' to ' + str(date_range1[date_index_number1].year) + '-' + str(date_range1[date_index_number1].month) + '-' + str(date_range1[date_index_number1].day)+ ' Hour(s): ' + timeselect1\
+ '\n' + 'Date range two (right): ' + str(date_range2[0].year) + '-' + str(date_range2[0].month) + '-' + str(date_range2[0].day)\
+ ' to ' + str(date_range2[date_index_number2].year) + '-' + str(date_range2[date_index_number2].month) + '-' + str(date_range2[date_index_number2].day)+ ' Hour(s): ' + timeselect2)
plt.ylabel('ppm')
plt.show()
if source_category_input == 'fuel_categories':
oil_list_one=oil_both[0]
coal_list_one=coal_both[0]
gas_list_one=gas_both[0]
biofuel_list_one=biofuel_both[0]
oil_list_two =oil_both[1]
coal_list_two = coal_both[1]
gas_list_two =gas_both[1]
biofuel_list_two =biofuel_both[1]
#sorting lowest anthropogenic contribution in date range one.
sorted_oil_list_one = [x for _,x in sorted(zip(anthro_list_one,oil_list_one))]
sorted_coal_list_one = [x for _,x in sorted(zip(anthro_list_one,coal_list_one))]
sorted_gas_list_one = [x for _,x in sorted(zip(anthro_list_one,gas_list_one))]
sorted_biofuel_list_one = [x for _,x in sorted(zip(anthro_list_one,biofuel_list_one))]
sorted_oil_list_two = [x for _,x in sorted(zip(anthro_list_one,oil_list_two))]
sorted_coal_list_two = [x for _,x in sorted(zip(anthro_list_one,coal_list_two))]
sorted_gas_list_two = [x for _,x in sorted(zip(anthro_list_one,gas_list_two))]
sorted_biofuel_list_two = [x for _,x in sorted(zip(anthro_list_one,biofuel_list_two))]
figure(num=None, figsize=(22, 10), dpi=80, facecolor='w', edgecolor='k')
y_pos = np.arange(len(sorted_station_list))
ax = plt.subplot(111)
p1 = ax.bar(y_pos-0.4, sorted_oil_list_one,width=0.09,color='lightcoral',align='center')
p1 = ax.bar(y_pos-0.3, sorted_oil_list_two ,width=0.09,color='lightcoral',align='center')
p3 = ax.bar(y_pos-0.2, sorted_coal_list_one,width=0.09,color='lightskyblue',align='center',hatch="/")
p4 = ax.bar(y_pos-0.1, sorted_coal_list_two,width=0.09,color='lightskyblue',align='center',hatch="/")
p5 = ax.bar(y_pos+0.0, sorted_gas_list_one,width=0.09,color='brown',align='center')
p6 = ax.bar(y_pos+0.1, sorted_gas_list_two,width=0.09,color='brown',align='center')
p7 = ax.bar(y_pos+0.2, sorted_biofuel_list_one,width=0.09,color='green',align='center')
p8 = ax.bar(y_pos+0.3, sorted_biofuel_list_two,width=0.09,color='green',align='center')
ax.legend((p1[0], p3[0],p5[0], p7[0]), ('Oil contribution', 'Coal contribution', 'Gas contribution', 'Biofuel contribution') )
ax.yaxis.grid(True)
plt.xticks(y_pos, sorted_station_list, rotation='vertical')
#add graph for source categories/fuel categories. maybe need to make figure even bigger.
plt.title('Comparing contribution of the different fuel categories, over two date ranges' + '\n' + 'Date range one (left): ' + str(date_range1[0].year) + '-' + str(date_range1[0].month) + '-' + str(date_range1[0].day)\
+ ' to ' + str(date_range1[date_index_number1].year) + '-' + str(date_range1[date_index_number1].month) + '-' + str(date_range1[date_index_number1].day)+ ' Hour(s): ' + timeselect1\
+ '\n' + 'Date range two (right): ' + str(date_range2[0].year) + '-' + str(date_range2[0].month) + '-' + str(date_range2[0].day)\
+ ' to ' + str(date_range2[date_index_number2].year) + '-' + str(date_range2[date_index_number2].month) + '-' + str(date_range2[date_index_number2].day)+ ' Hour(s): ' + timeselect2)
plt.ylabel('ppm')
plt.show()
Two new date ranges will be defined in this cell
The date ranges anthropogenic and biogenic contributions are output into the same bar graph
In a second bar graph, the defined date ranges are compared in terms of the anthropogenic contribution either
split fuel- or source categories
date_range1, timeselect, start_date, end_date = date_range_date_hour()
date_range2, timeselect2, start_date, end_date = date_range_date_hour()
station_iterator=iter(all_stations)
for station in station_iterator:
df_1 = read_stilt_timeseries(station, date_range1)
df_1_mean=df_1.mean()
df_2 = read_stilt_timeseries(station, date_range2)
df_2_mean=df_2.mean()
matplotlib.rcParams.update({'font.size': 17})
y_pos = np.arange(1)
figure(num=None, figsize=(20, 10), dpi=80, facecolor='w', edgecolor='k')
ax = plt.subplot(111)
ax.yaxis.grid(True)
for_transport1=df_1_mean['co2.industry']+df_1_mean['co2.energy']
for_others1 = for_transport1 + df_1_mean['co2.transport']
for_gas1= df_1_mean['co2.fuel.oil'] + df_1_mean['co2.fuel.coal']
for_bio1 = for_gas1 + df_1_mean['co2.fuel.gas']
for_cement_production1= for_bio1 + df_1_mean['co2.fuel.bio']
for_waste_burning1=for_cement_production1 + df_1_mean['co2.cement']
#the remaining contribution comes from emissions from waste burning
waste_burning1 = (df_1_mean['co2.energy']+df_1_mean['co2.industry']+df_1_mean['co2.transport'] +df_1_mean['co2.others']) - for_waste_burning1
for_transport2=df_2_mean['co2.industry']+df_2_mean['co2.energy']
for_others2 = for_transport2 + df_2_mean['co2.transport']
for_gas2= df_2_mean['co2.fuel.oil'] + df_2_mean['co2.fuel.coal']
for_bio2 = for_gas2 + df_2_mean['co2.fuel.gas']
for_cement_production2= for_bio2 + df_2_mean['co2.fuel.bio']
for_waste_burning2=for_cement_production2 + df_2_mean['co2.cement']
#the remaining contribution comes from emissions from waste burning
waste_burning2 = (df_2_mean['co2.energy']+df_2_mean['co2.industry']+df_2_mean['co2.transport'] +df_2_mean['co2.others']) - for_waste_burning2
p1 = ax.bar(y_pos-0.75, df_1_mean['co2.bio'],width=0.15,color='g',align='center')
p1 = ax.bar(y_pos-0.55, df_2_mean['co2.bio'],width=0.15,color='g',align='center')
p2 = ax.bar(y_pos-0.25, (df_1_mean['co2.energy']+df_1_mean['co2.industry']+df_1_mean['co2.transport'] +df_1_mean['co2.others']),width=0.15,color='r',align='center')
p2 = ax.bar(y_pos-0.05, (df_2_mean['co2.energy']+df_2_mean['co2.industry']+df_2_mean['co2.transport'] +df_2_mean['co2.others']), width=0.15,color='r',align='center')
p3 = ax.bar(y_pos+0.25, df_1_mean['co2.industry'],width=0.15,color='dimgrey',align='center')
p3 = ax.bar(y_pos+0.45, df_2_mean['co2.industry'],width=0.15,color='dimgrey',align='center')
p4 = ax.bar(y_pos+0.25, df_1_mean['co2.energy'], bottom=df_1_mean['co2.industry'], width=0.15,color='orange', hatch="/")
p4 = ax.bar(y_pos+0.45, df_2_mean['co2.energy'], bottom=df_2_mean['co2.industry'], width=0.15,color='orange', hatch="/")
p5 = ax.bar(y_pos+0.25, df_1_mean['co2.transport'],bottom=for_transport1,width=0.15,color='maroon',align='center')
p5 = ax.bar(y_pos+0.45, df_2_mean['co2.transport'],bottom=for_transport2,width=0.15,color='maroon',align='center')
p6 = ax.bar(y_pos+0.25, df_1_mean['co2.others'],bottom=for_others1,width=0.15,color='peru',align='center')
p6 = ax.bar(y_pos+0.45, df_2_mean['co2.others'],bottom=for_others2,width=0.15,color='peru',align='center')
p7 = ax.bar(y_pos+0.75, df_1_mean['co2.fuel.oil'],width=0.15,color='lightcoral',align='center')
p7 = ax.bar(y_pos+0.95, df_2_mean['co2.fuel.oil'],width=0.15,color='lightcoral',align='center')
p8 = ax.bar(y_pos+0.75, df_1_mean['co2.fuel.coal'], bottom=df_1_mean['co2.fuel.oil'], width=0.15,color='lightskyblue',align='center')
p8 = ax.bar(y_pos+0.95, df_2_mean['co2.fuel.coal'], bottom=df_2_mean['co2.fuel.oil'], width=0.15,color='lightskyblue',align='center')
p9 = ax.bar(y_pos+0.75, df_1_mean['co2.fuel.gas'],bottom=for_gas1, width=0.15,color='brown',align='center')
p9 = ax.bar(y_pos+0.95, df_2_mean['co2.fuel.gas'],bottom=for_gas2, width=0.15,color='brown',align='center')
p10 = ax.bar(y_pos+0.75, df_1_mean['co2.fuel.bio'],bottom=for_bio1,width=0.15,color='green',align='center')
p10 = ax.bar(y_pos+0.95, df_2_mean['co2.fuel.bio'],bottom=for_bio2,width=0.15,color='green',align='center')
p11 = ax.bar(y_pos+0.75, df_1_mean['co2.cement'], bottom=for_cement_production1,width=0.15,color='grey',align='center', hatch="/")
p11 = ax.bar(y_pos+0.95, df_2_mean['co2.cement'], bottom=for_cement_production2,width=0.15,color='grey',align='center', hatch="/")
p11 = ax.bar(y_pos+0.75, waste_burning1, bottom=for_waste_burning1,width=0.15,color='grey',align='center', hatch="/")
p11 = ax.bar(y_pos+0.95, waste_burning2, bottom=for_waste_burning2,width=0.15,color='grey',align='center', hatch="/")
ax.legend((p1[0], p2[0]), ('Biogenic contribution','Anthropogenic contribution'), loc='upper left')
leg = Legend(ax, (p6[0],p5[0],p4[0],p3[0]), ('Others', 'Transport', 'Industry', 'Energy'), loc='lower center')
ax.add_artist(leg)
leg2 = Legend(ax, (p12[0],p11[0],p10[0],p9[0],p8[0],p7[0]), ('Waste burning','Cement production', 'Biofuel', 'Gas', 'Coal', 'Oil'), loc='lower right')
ax.add_artist(leg2)
plt.ylabel('ppm')
plt.axhline(0, color='black', lw=2)
plt.xticks(y_pos)
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False, # ticks along the top edge are off
labelbottom=False)
date_index_number1 = (len(date_range1) - 1)
date_index_number2 = (len(date_range2) - 1)
title= ('Biogenic vs. anthropogenic contribution at ' + str(station) + '\n' + 'Date range one (left): ' + str(date_range1[0].year) + '-' + str(date_range1[0].month) + '-' + str(date_range1[0].day) + ' to ' + str(date_range1[date_index_number1].year) +\
'-' + str(date_range1[date_index_number1].month) + '-' + str(date_range1[date_index_number1].day) + ', Hour(s): ' + str(timeselect) + '\n' + 'Date range two (right): ' + str(date_range2[0].year) + '-' + str(date_range2[0].month) + '-' + str(date_range2[0].day) + ' to ' + str(date_range2[date_index_number2].year) +\
'-' + str(date_range2[date_index_number2].month) + '-' + str(date_range2[date_index_number2].day)+ ', Hour(s): ' + str(timeselect2))
plt.title(title)
plt.show()