From c15ef4f97e9de1e998fdb99bec64d90065dddde9 Mon Sep 17 00:00:00 2001 From: Shayan Date: Mon, 10 Oct 2022 22:28:13 +1100 Subject: [PATCH] In Paris --- Decarbonization.py | 18 ++++++++------ Summary.py | 61 +++++++++++++++++++++------------------------- WindSolar.py | 14 +++++------ callbacks.py | 5 ++-- figures.py | 45 ++++++++++++++++++++++++++++++---- functions.py | 24 ++++++++++++++++-- 6 files changed, 109 insertions(+), 58 deletions(-) diff --git a/Decarbonization.py b/Decarbonization.py index 4531743..6186a22 100644 --- a/Decarbonization.py +++ b/Decarbonization.py @@ -293,9 +293,11 @@ def generate_card_deck_2(): generate_select('carbon-price', "Carbon price: $/ton", 0, 100, 0.1, 30), dbc.Label("RE size and installation cost"), - generate_select('PV-cost',"Large scale PV: $/W",0.5,5,0.1,3), - generate_select('PV-battery-cost',"Small PV+B: $/W",1,15,0.1,7), - generate_select('wind-large-cost',"Large scale wind: $/W",1,5,0.1,3), + generate_select('PV-cost',"Large scale PV: $/W",0.5,8,0.1,4.5), + generate_select('PV-battery-cost',"Rooftop PV: $/W",1,15,0.1,4.5), + generate_select('small-battery-cost', "Residential Battery: $/W", 1, 15, 0.1, 4), + + generate_select('wind-large-cost',"Large scale wind: $/W",1,8,0.1,6), generate_select('wind-battery-cost',"Small Wind+B: $/W",2.5,12,0.1,6), generate_select('rooftop-size', "Rooftop PV size: kW", 0.5, 5, 0.1, 2.5), @@ -312,8 +314,8 @@ def generate_card_deck_2(): ), ] ), - generate_select('ComBattery-MWh', "Battery size (MWh):", 0, 10000, 0.5, 3), - generate_select('ComBattery-cost', "Cost(M$/MWh):", 0, 10, 0.05, 2), + generate_select('ComBattery-MWh', "Battery size (MWh):", 0, 50000, 0.5, 3), + generate_select('ComBattery-cost', "Cost(M$/MWh):", 0, 10, 0.05, 3), html.Div( [ dbc.Label("Geothermal parameters"), @@ -328,7 +330,7 @@ def generate_card_deck_2(): ] ), - generate_select('geothermal-MW', "Geothermal (MW):", 0, 4000, 1, 25), + generate_select('geothermal-MW', "Geothermal (MW):", 0, 4000, 1, 0), generate_select('geothermal-completion', "Completion year:", 2022, 2050, 1, 2035), generate_select('geothermal-cost', "Geothermal cost (M$/MW):", 0.5, 10, 0.1, 5), @@ -340,14 +342,14 @@ def generate_card_deck_2(): html.Br(), generate_select('small-PV-share', "PV+B to all PV: %", 0, 100, 5, 40), - generate_select('small-wind-share', "Wind+B to all Wind: %", 0, 100, 5, 40), + generate_select('small-wind-share', "Wind+B to all Wind: %", 0, 100, 5, 0), generate_select('demand-growth', "Demand growth: %/year", 0, 100, 1, 2), generate_select('decarb-year', "100% RE target:", 2022, 2060, 1, 2030), generate_select('discount-rate', "Discount rate: %", 0, 100, 1, - 6), + 7), generate_select('inflation-rate', "Inflation rate: %", 0, 100, 1, 3), diff --git a/Summary.py b/Summary.py index cbeb0ed..5eeebe3 100644 --- a/Summary.py +++ b/Summary.py @@ -1,24 +1,18 @@ from dash import html from dash import dcc import dash_bootstrap_components as dbc -import figures -import EnergyFlows + from app import app import pandas as pd import dash import os -# import dash_daq as daq +import dash_daq as daq from EnergyFlows import figure_border_style -from EnergyFlows import Year_List -from EnergyFlows import CONTENT_STYLE +import EnergyFlows from dash import dash_table -import plotly.figure_factory as ff - +import figures summary_df = pd.read_csv('Data/SummaryTable.csv') -table = dbc.Table.from_dataframe(summary_df, striped=False, bordered=True, hover=True,style={'color':'white','fontSize':'18'},responsive=True) -# table = dbc.Table(summary_df, striped=False, bordered=True, hover=True,style={'color':'white'},responsive=True) -# table = ff.create_table(summary_df, height_constant=1500) - +table = dbc.Table.from_dataframe(summary_df, striped=True, bordered=True, hover=True,style={'color':'red'},responsive=True) dataTable = dash_table.DataTable( data=summary_df.to_dict('records'), @@ -29,31 +23,29 @@ }, style_as_list_view=False, style_header={ - 'padding': '5px', 'backgroundColor': 'rgb(30, 30, 30)', 'fontWeight': 'bold', 'border': '1px solid grey', - 'textAlign': 'left', - 'height': 'auto', - 'overflow': 'hidden', - 'textOverflow': 'ellipsis', - 'whiteSpace': 'normal', + # 'textAlign': 'left', + }, + style_data={ 'border': '1px solid grey', 'whiteSpace': 'normal', + 'height': 'auto',}, + style_cell_conditional=[ # style_cell_c. refers to the whole table + { + 'if': {'column_id': 'Country / Territory'}, + 'textAlign': 'left' + } + ], + style_table={ + 'width': '100%', + 'margin': '0 0 0 0px', + 'padding': '0 0px', + 'overflowX': 'auto', + 'overflowY': 'auto', }, - style_data={ 'border': '0.15px solid white' },#ff4d4d - # style_cell_conditional=([ - # {'if': {'column_id': 'Population density (Person/km2)'}, - # 'width': '5%'}, - # {'if': {'column_id': 'Youngest volcanism'}, - # 'width': '20%'}, - # {'if': {'column_id': 'Known geothermal locations'}, - # 'width': '20%'}, - # {'if': {'column_id': 'Geothermal investigations'}, - # 'width': '15%'}, - # {'if': {'column_id': 'Observed hot spring temperature'}, - # 'width': '20%'}, - # {'if': {'column_id': 'Potentials'}, - # 'width': '17.5%'}]), + # fixed_rows={'data': 0}, + fixed_columns={'headers': True, 'data': 0}, # 'headers': True, ) Transit = [ @@ -93,7 +85,7 @@ dbc.Col(html.Div(dcc.Graph(id="Oil-imports", figure=figures.UNstats_plots(2019)[3]), style=figure_border_style), md=6), - dbc.Col(html.Div(dcc.Graph(id="transit_figure4", figure=figures.imports_to_GDP(2019)[0]), + dbc.Col(html.Div(dcc.Graph(id="imports-to-GDP", figure=figures.imports_to_GDP(2019)[0]), style=figure_border_style), md=6), ]), html.Br(), @@ -103,6 +95,8 @@ dbc.Col(html.Div(dcc.Graph(id="renewables-per-capita", figure=figures.UNstats_plots(2019)[8]), style=figure_border_style), md=6), ]), + html.Br(), + dbc.Row([ dbc.Col(html.Div(dcc.Graph(id="transit_figure3", figure=figures.UNstats_plots(2019)[2]), style=figure_border_style), md=6), @@ -141,6 +135,7 @@ + BODY = dbc.Container( [ dbc.Row([dbc.Col(dbc.Card(Transit)), ], style={"marginTop": 30, @@ -151,4 +146,4 @@ ) -content = [BODY] \ No newline at end of file +content = [EnergyFlows.generate_single_year_drpdwn(),BODY] \ No newline at end of file diff --git a/WindSolar.py b/WindSolar.py index b789d92..c101c13 100644 --- a/WindSolar.py +++ b/WindSolar.py @@ -69,24 +69,22 @@ def generate_single_country_drpdwn(): html.Br(), dbc.Row([ - # dbc.Col( - # html.Div(dcc.Graph(id="PV_technical_GW", figure=figures.Solar_physical_resources()[6]), - # style=figure_border_style), md=6), - dbc.Col( - html.Div(dcc.Graph(id="PV_theoretical_GW", figure=figures.Solar_physical_resources()[3]), + html.Div(dcc.Graph(id="PV_technical_GW", figure=figures.Solar_physical_resources()[6]), style=figure_border_style), md=6), + + # dbc.Col( + # html.Div(dcc.Graph(id="PV_theoretical_GW", figure=figures.Solar_physical_resources()[3]), + # style=figure_border_style), md=6), dbc.Col(html.Div( dcc.Graph(id="Wind_thechnical_MW", figure=figures.Solar_physical_resources()[5]), style=figure_border_style), md=6), ]), + html.Br(), dbc.Row([ dbc.Col(html.Div( dcc.Graph(id="PV_technical_GWh", figure=figures.Solar_physical_resources()[7]), style=figure_border_style), md=6), - dbc.Col(html.Div( - dcc.Graph(id="PV_technical_GWh", figure=figures.Solar_physical_resources()[4]), - style=figure_border_style), md=6), dbc.Col(html.Div( dcc.Graph(id="Wind_thechnical_GWh", figure=figures.Solar_physical_resources()[2]), diff --git a/callbacks.py b/callbacks.py index 989b250..75ca8a2 100644 --- a/callbacks.py +++ b/callbacks.py @@ -80,6 +80,7 @@ def update_options(Country,style): State("diesel_price_slider", "value"), State("PV-cost", "value"), State("PV-battery-cost", "value"), + State("small-battery-cost", "value"), State("wind-battery-cost", "value"), State("wind-large-cost", "value"), State("demand-growth", "value"), @@ -102,7 +103,7 @@ def update_options(Country,style): State('switches-communityBattery', "value"), ]) -def sensor_checklist(n_clicks,year,country,diesel_price,PV_cost,PVBatt_cost,WindBatt_cost,Wind_cost,demand_growth,decarb_year,rooftop_size, +def sensor_checklist(n_clicks,year,country,diesel_price,PV_cost,rooftop_PV_cost,res_batt_cost,WindBatt_cost,Wind_cost,demand_growth,decarb_year,rooftop_size, emission_tonneperMWh, emission_dollarpertonne, wind_share, small_PV_share,small_wind_share, geothermal_switch,geothermal_completion_year,geothermal_MW,geothermal_CF,geothermal_CAPEX, @@ -154,7 +155,7 @@ def sensor_checklist(n_clicks,year,country,diesel_price,PV_cost,PVBatt_cost,Wind emission_cost_mdollar = round(emission_cost_mdollar, 2) oil_supplied_cost = round(oil_supplied_cost,1) power_generated_GWh = round(power_generated_GWh,1) - fig_lists = figures.decarbonization_scenarios(country,Efficiency/100,net_oil_product_import_ml,power_generated_GWh, demand_growth, PV_cost, PVBatt_cost, + fig_lists = figures.decarbonization_scenarios(country,Efficiency/100,net_oil_product_import_ml,power_generated_GWh, demand_growth, PV_cost, rooftop_PV_cost,res_batt_cost, WindBatt_cost, Wind_cost, decarb_year, wind_share, small_PV_share, small_wind_share, PV_pot, Wind_pot, diesel_HHV, diesel_price, geothermal_switch,geothermal_completion_year,geothermal_MW,geothermal_CF,geothermal_CAPEX, diff --git a/figures.py b/figures.py index 4301eb4..6e413eb 100644 --- a/figures.py +++ b/figures.py @@ -4,8 +4,8 @@ import plotly.express as px import functions from EnergyFlows import Country_List -font_color = 'black' -line_color = 'black' +font_color = 'white' +line_color = 'white' def imports_to_GDP(year): net_imp_list= [] @@ -33,7 +33,7 @@ def imports_to_GDP(year): df_GDP['net_imp_per_capita'] = df_GDP['net_imp_per_capita'].round(0) # df_GDP['net_imp_per_capita'] = df_GDP['net_imp_per_capita'] fig = go.Figure() - fig.add_trace(go.Bar(x=df_GDP['Country'], y=df_GDP['net_imp_to_GDP'],text=df_GDP['net_imp_to_GDP'],name='dasdsa',marker_color='forestgreen')) + fig.add_trace(go.Bar(x=df_GDP['Country'], y=df_GDP['net_imp_to_GDP'],text=df_GDP['net_imp_to_GDP'],name='',marker_color='forestgreen')) fig.update_layout(#width=1500, # height=500, barmode='relative') @@ -325,7 +325,7 @@ def annual_demand(demand,growth_rate,decarb_rate): return fig -def decarbonization_scenarios(Country,Efficiency,oil_imports_2019,demand,growth_rate,PV_cost,PVBatt_cost,WindBatt_cost,Wind_cost,decarb_year, +def decarbonization_scenarios(Country,Efficiency,oil_imports_2019,demand,growth_rate,PV_cost,rooftop_PV_cost,res_batt_cost,WindBatt_cost,Wind_cost,decarb_year, total_wind_share,small_PV_share,small_wind_share, PV_pot,Wind_pot,diesel_HHV,diesel_price, geothermal_switch,geothermal_completion_year,geothermal_MW,geothermal_CF,geothermal_CAPEX, @@ -410,10 +410,16 @@ def decarbonization_scenarios(Country,Efficiency,oil_imports_2019,demand,growth_ demand_df['Small Wind+B'] = demand_df['wind_inst'] * small_wind_share #MW demand_df['Large Wind'] = demand_df['wind_inst'] * large_wind_share #MW - demand_df['RE_inst_cost'] = (1000000 * demand_df['PV_inst'] * (small_PV_share*PVBatt_cost*1.5+large_PV_share*PV_cost) +\ + # demand_df['RE_inst_cost'] = (1000000 * (demand_df['PV_inst'] * (small_PV_share*rooftop_PV_cost+large_PV_share*PV_cost) )+\ + # 1000000 * demand_df['wind_inst'] * (small_wind_share*WindBatt_cost+large_wind_share*Wind_cost)+ \ + # demand_df['Geothermal_inst_cost']+ + # demand_df['Battery_inst_cost']*1000000)/1000000 #M$ + demand_df['RE_inst_cost'] = (1000000 * (demand_df['Small PV+B'] *rooftop_PV_cost + demand_df['Small PV+B'] * 2 * res_batt_cost + demand_df['Large PV'] *PV_cost)+\ 1000000 * demand_df['wind_inst'] * (small_wind_share*WindBatt_cost+large_wind_share*Wind_cost)+ \ demand_df['Geothermal_inst_cost']+ demand_df['Battery_inst_cost']*1000000)/1000000 #M$ + + demand_df["non_RE_demand_TJ"] = (demand_df['Demand'] - demand_df['RE_cumulative']-demand_df['Geothermal_GWh'])/0.2777 demand_df['non_RE_demand_TJ'][demand_df['non_RE_demand_TJ'] < 0] = 0 demand_df["diesel_litre_dec"] = demand_df["non_RE_demand_TJ"] / (diesel_HHV*Efficiency) # L @@ -1038,6 +1044,35 @@ def UNstats_plots(year): marker_line_width=1.5, opacity=1) fig8.update_traces(hovertemplate=None) + fig_re_imp = go.Figure() + fig_re_imp.add_trace(go.Bar(x=summary_df['Country'], y=summary_df['Renewables/Total_imports'], name='Total energy from renewables',text=summary_df['Renewables/Total_imports'], + marker_color='forestgreen')) + + fig_re_imp.update_layout(legend=dict(bgcolor='rgba(0,0,0,0)', yanchor="bottom", orientation="h", + y=0.98, + xanchor="center", + x=0.5), + font=dict( + family="Calibri", + size=16, + color=font_color + ), + hovermode="x" + ) + fig_re_imp.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_re_imp.update_yaxes(title_text="% of total energy imports", showline=True, linecolor=line_color, gridcolor=line_color) + fig_re_imp.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Energy Balances, United Nations") + fig_re_imp.update_layout( + title="Proportion of renewable consumption to total energy imports in {}".format(year)) + fig_re_imp.update_traces(marker_line_color=font_color, + marker_line_width=1.5, opacity=1) + fig_re_imp.update_traces(hovertemplate=None) + fig_re_imp.write_image("renewables_to_total_imports.png") + fig9 = go.Figure() fig9.add_trace(go.Bar(x=summary_df['Country'], y=summary_df['Renewables/capita'], name='Total energy from renewables',text=summary_df['Renewables/capita'], marker_color='forestgreen')) diff --git a/functions.py b/functions.py index 779f646..7e37e24 100644 --- a/functions.py +++ b/functions.py @@ -89,6 +89,8 @@ def fetch_all_countries_demand(Year,Unit='GWh',Use="Analysis"): renewables_in_total = df[df['Transactions(down)/Commodity(right)']=='Total energy supply']['memo: Of which Renewables'].values #TJ renewable_electricity = df[df['Transactions(down)/Commodity(right)']=='Primary production']['Electricity'].values #TJ imports = df[df['Transactions(down)/Commodity(right)']=='Imports']['All Oil'].values + all_imports = df[df['Transactions(down)/Commodity(right)']=='Imports']['Total Energy'].values + Int_marine = df[df['Transactions(down)/Commodity(right)']=='International marine bunkers']['All Oil'].values Int_avi = df[df['Transactions(down)/Commodity(right)']=='International aviation bunkers']['All Oil'].values transformation = -df[df['Transactions(down)/Commodity(right)']=='Electricity CHP & Heat Plants']['All Oil'].values @@ -103,14 +105,16 @@ def fetch_all_countries_demand(Year,Unit='GWh',Use="Analysis"): transformation_losses = transformation_losses * 0.277778 renewables_in_total = renewables_in_total * 0.277778 renewable_electricity = renewable_electricity * 0.277778 - + all_imports = all_imports * 0.277778 df_demand = pd.DataFrame() df_demand['Country'] = Countries df_demand['Non-RE'] = non_RE_demand df_demand['Total'] = total_demand df_demand.to_csv('demand_df.csv') - return [Countries,total_demand,imports,Int_marine,Int_avi,transformation,transformation_losses,renewables_in_total,renewable_electricity,non_RE_demand] + return [Countries,total_demand,imports,Int_marine,Int_avi,transformation, + transformation_losses,renewables_in_total, + renewable_electricity,non_RE_demand,all_imports] def all_countries_cross_comparison_unstats(Year,Unit,Use): summary_df = pd.DataFrame() @@ -130,10 +134,14 @@ def all_countries_cross_comparison_unstats(Year,Unit,Use): summary_df['transformation_losses'] = summary_list[6] summary_df['renewables_in_total'] = summary_list[7] summary_df['renewable_electricity'] = summary_list[8] + summary_df['total imports'] = summary_list[10] summary_df['Renewables/Total_demand'] = 100 * summary_df['renewables_in_total']/summary_df['Total_demand'] summary_df['Renewables/Total_demand']=summary_df['Renewables/Total_demand'].round(1) + summary_df['Renewables/Total_imports'] = 100 * summary_df['renewables_in_total']/summary_df['total imports'] + summary_df['Renewables/Total_imports']=summary_df['Renewables/Total_imports'].round(1) + summary_df['Renewables/capita'] = (summary_df['renewables_in_total']/population['Population']) * 1000000 #MJ summary_df['Renewables/capita'] = summary_df['Renewables/capita'].round(0) @@ -147,6 +155,18 @@ def all_countries_cross_comparison_unstats(Year,Unit,Use): summary_df['Domestic navigation'] = 100 * df[df['Transactions(down)/Commodity(right)']=='Domestic navigation']['All Oil'].values/summary_df['Oil imports'] summary_df['Pipeline transport'] = 100 * df[df['Transactions(down)/Commodity(right)']=='Pipeline transport']['All Oil'].values/summary_df['Oil imports'] summary_df['transport n.e.s'] = 100 * df[df['Transactions(down)/Commodity(right)']=='Transport n.e.s']['All Oil'].values/summary_df['Oil imports'] + + summary_df['road_real'] = df[df['Transactions(down)/Commodity(right)'] == 'Road']['All Oil'].values + summary_df['rail_real'] = df[df['Transactions(down)/Commodity(right)'] == 'Rail']['All Oil'].values + summary_df['Domestic aviation_real'] = df[df['Transactions(down)/Commodity(right)'] == 'Domestic aviation'][ + 'All Oil'].values + summary_df['Domestic navigation_real'] = df[df['Transactions(down)/Commodity(right)'] == 'Domestic navigation'][ + 'All Oil'].values + summary_df['Pipeline transport_real'] = df[df['Transactions(down)/Commodity(right)'] == 'Pipeline transport'][ + 'All Oil'].values + summary_df['transport n.e.s_real'] = df[df['Transactions(down)/Commodity(right)'] == 'Transport n.e.s'][ + 'All Oil'].values + summary_df.to_csv("Summary_df.csv") return summary_df