From 8ce0a1f8ffc36d16cb36b1adedf27acfb624331d Mon Sep 17 00:00:00 2001 From: Shayan Date: Mon, 17 Oct 2022 22:56:45 +1100 Subject: [PATCH] Dynamic ratio of energy breakdowns works perfectly --- Data/SummaryTable.csv | 34 +- Decarbonization.py | 1 + DecarbonizationFunctions.py | 18 + EnergyFlows.py | 103 ++++- FinancialFlows.py | 4 +- Summary.py | 30 ++ WindSolar.py | 6 +- callbacks_sankey.py | 43 ++ figures.py | 802 +++++++++++++++++++++++++++++++----- functions.py | 181 +++++++- index.py | 2 + test.py | 13 + 12 files changed, 1084 insertions(+), 153 deletions(-) create mode 100644 DecarbonizationFunctions.py create mode 100644 test.py diff --git a/Data/SummaryTable.csv b/Data/SummaryTable.csv index 9b5b1cc..76df746 100644 --- a/Data/SummaryTable.csv +++ b/Data/SummaryTable.csv @@ -1,20 +1,20 @@ Country / Territory,Political Status,Land area (km2),Population,Area per person (m2),Population density (Person/km2),GDP ($Million),GDP Per Capita ($),Geographic Type,No. islands,No. inhab. island -American Samoa,US territory,240,"45,443","5,176",193,658,"14,480",High islands + atolls,7,6 -Cook Islands,Independent. NZ-affiliated,180,"17,459","10,310",97,300,"17,183",High islands + atolls,15,13 -Federated States of Micronesia,Independent. US-affiliated,702,"104,468","6,720",149,390,"3,733",High islands + atolls,607,65 -Fiji,Independent,"18,376","929,276","19,775",51,"12,180","13,107",High islands + atolls,330,110 -French Polynesia,French Territory,"3,521","275,918","12,761",78,"5,490","19,897",High islands + atolls,118,67 +American Samoa,US territory,240,"45,443","5,176",193,658,14480,High islands + atolls,7,6 +Cook Islands,Independent. NZ-affiliated,180,"17,459","10,310",97,300,17183,High islands + atolls,15,13 +Federated States of Micronesia,Independent. US-affiliated,702,"104,468","6,720",149,390,3733,High islands + atolls,607,65 +Fiji,Independent,"18,376","929,276","19,775",51,"12,180",13107,High islands + atolls,330,110 +French Polynesia,French Territory,"3,521","275,918","12,761",78,"5,490",19897,High islands + atolls,118,67 Guam,US territory,549,"168,801","3,252",307,6,34,High islands,1,1 -Kiribati,Independent,726,"119,000","6,101",164,270,"2,269",Atolls,33,21 -Marshall Islands,Independent. US-affiliated,720,"58,413","12,326",81,240,"4,109",Atolls,34,24 -Nauru,Independent,21,"10,670","1,968",508,150,"14,058",Raised coral island,1,1 -Niue,Independent. NZ-affiliated,258,"1,620","159,259",6,10,"6,235",Raised coral island,1,1 -Palau,Independent. US-affiliated,475,"17,907","26,526",38,320,"17,870",High islands + atolls,1,1 -Papua New Guinea,Independent,"461,690","8,935,000","51,672",19,"38,170","4,272",High islands + atolls,600,No data -Solomon Islands,Independent,"29,785","652,857","45,623",22,"1,780","2,726",High islands + atolls,992,347 -Tokelau,NZ territory,12,"1,500","8,000",125,8,"5,333",Atolls,3,3 -Tonga,Independent,696,"100,651","6,915",145,670,"6,657",High islands,169,36 -Tuvalu,Independent,26,"11,646","2,233",448,50,"4,293",Atolls,9,8 -Vanuatu,Independent,"12,189","307,815","39,598",25,930,"3,021",High islands + atolls,83,65 -Samoa,Independent,"2,934","202,506","14,488",69,"1,280","6,321",High islands,12,4 +Kiribati,Independent,726,"119,000","6,101",164,270,2269,Atolls,33,21 +Marshall Islands,Independent. US-affiliated,720,"58,413","12,326",81,240,4109,Atolls,34,24 +Nauru,Independent,21,"10,670","1,968",508,150,14058,Raised coral island,1,1 +Niue,Independent. NZ-affiliated,258,"1,620","159,259",6,10,6235,Raised coral island,1,1 +Palau,Independent. US-affiliated,475,"17,907","26,526",38,320,17870,High islands + atolls,1,1 +PNG,Independent,"461,690","8,935,000","51,672",19,"38,170",4272,High islands + atolls,600,No data +Solomon Islands,Independent,"29,785","652,857","45,623",22,"1,780",2726,High islands + atolls,992,347 +Tokelau,NZ territory,12,"1,500","8,000",125,8,5333,Atolls,3,3 +Tonga,Independent,696,"100,651","6,915",145,670,6657,High islands,169,36 +Tuvalu,Independent,26,"11,646","2,233",448,50,4293,Atolls,9,8 +Vanuatu,Independent,"12,189","307,815","39,598",25,930,3021,High islands + atolls,83,65 +Samoa,Independent,"2,934","202,506","14,488",69,"1,280",6321,High islands,12,4 New Caledonia,French Territory,"18,275","297,160","61,499",16,11,37,No Data,55,No data diff --git a/Decarbonization.py b/Decarbonization.py index 595f477..4e8e68d 100644 --- a/Decarbonization.py +++ b/Decarbonization.py @@ -315,6 +315,7 @@ def generate_card_deck_2(): ] ), generate_select('ComBattery-MWh', "Battery size (MWh):", 0, 50000, 0.5, 3), + generate_select('storage-days', "Storage Capacity (days):", 0, 15, 1, 5), generate_select('ComBattery-cost', "Cost(M$/MWh):", 0, 10, 0.05, 3), html.Div( [ diff --git a/DecarbonizationFunctions.py b/DecarbonizationFunctions.py new file mode 100644 index 0000000..29fa697 --- /dev/null +++ b/DecarbonizationFunctions.py @@ -0,0 +1,18 @@ +import pandas as pd +import functions +def calculate_community_battery_size(country,residential_battery_capacity,demand_scenario="Decarbonization", total_storage_days = 5): + demand = functions.fetch_single_country_demand(Country=country,Year=2019) + if demand_scenario == "World average": + demand = demand * 0.8 + daily_average_demand = demand/365 + total_storage_capacity_GWh = total_storage_days * daily_average_demand + community_storage_capacity = total_storage_capacity_GWh - residential_battery_capacity + + return community_storage_capacity + + + +def run_decarbonization_scenario(): + pass + +calculate_community_battery_size("PNG",5) \ No newline at end of file diff --git a/EnergyFlows.py b/EnergyFlows.py index b59e657..e1eab46 100644 --- a/EnergyFlows.py +++ b/EnergyFlows.py @@ -193,6 +193,107 @@ def generate_navbar(app): style={"marginTop": 0, "marginBottom": 0}, ), ] +def select_flow(): + import os + + path = 'Data/EnergyBalance' + files = os.listdir(path) + + df = pd.read_csv("Data/EnergyBalance/{}/all_countries_df.csv".format(files[-1])) + input_from = ["Imports","Primary production","Total energy supply"] + input_source = ["Primary Coal and Peat","Coal and Peat Products","Primary Oil","Oil Products","Natural Gas","Biofuels and Waste","Nuclear", + "Electricity","Heat","Total Energy","All Coal","All Oil","memo: Of which Renewables"] + consumer_list = ['Electricity Plants',"CHP plants","Energy industries own use","Manufacturing const. and mining","Losses", + 'International marine bunkers',"Domestic navigation","International aviation bunkers","Domestic aviation","Road","Rail","Domestic aviation","Transport n.e.s", + "Agriculture forestry and fishing","Commerce and public services","Households","Other consumption n.e.s","Non-energy use", + ] + + farm_drpdwn_dbc = dbc.FormGroup( + [ + dbc.Row([ + dbc.Col([ + dbc.Label("From", style={'margin-right': "5px"}), + dbc.Select( + id="select-flow-provider", + options=[ + {"label": i, "value": i} for i in input_from + ], + value=input_from[0], + style={'width': "50%", 'margin-left': "0px", 'margin-right': "10px", 'fontColor': 'black', + 'fontSize': 15, 'color': 'black'}, + ),] + ), + dbc.Col([ + dbc.Label("Energy carrier", style={'margin-right': "5px"}), + dbc.Select( + id="select-flow-provider-source", + options=[ + {"label": i, "value": i} for i in input_source + ], + value="All Oil", + style={'width': "50%", 'margin-left': "0px", 'margin-right': "10px", 'fontColor': 'black', + 'fontSize': 15, 'color': 'black'}, + ), + ]) + ]), + html.Br(), + dbc.Row([ + dbc.Col([dbc.Label("To"),],md=0.5), + dbc.Col([ + + dcc.Dropdown( + id="select-flow-cunsumer", + options=[ + {"label": i, "value": i} for i in consumer_list + ], + value=consumer_list[:4], + style={'width': "90%", 'margin-left': "0px", 'fontColor': 'black', 'fontSize': 15, + 'color': 'black'}, + multi=True, + searchable=True, + clearable=False, + )],md = 6), +]), + + + html.Br(), + dbc.Button("Add Figure", color="danger", id='update-button-cross-country-flow', n_clicks=0, className="me-1"), + dbc.Button("Clear Canvas", color="primary", id='update-button-flow-clear', n_clicks=0, + className="me-1"), + + ], + inline=True, + style={'marginLeft':35,'marginTop':25,'fontSize':25} + ) + return farm_drpdwn_dbc +Tracing_energy_flows = [ + + dbc.CardHeader(html.H5("Cross-country comparison of energy flows consumed in different sectors")), + dbc.CardBody( + [ + dcc.Loading( + id="loading-sankey", + children=[ + dbc.Alert( + "Something's gone wrong! Give us a moment, but try loading this page again if problem persists.", + id="no-data-alert-sankey", + color="warning", + style={"display": "none"}, + ), + select_flow(), + html.Br(), + # html.Div(dcc.Graph(id="cross_country_sankey_figure"),style=figure_border_style), + html.Div(id='Hidden_Div_breakdown', children=[0, 0], style={'display': 'none'}), + html.Div(id='dynamic_callback_container_energy_breakdown', children=[], + style={'margin-top': '15px', 'margin-left': '20px','margin-right': '20px'}), + html.Br(), + ], + type="default", + ) + ], + style={"marginTop": 0, "marginBottom": 0}, + ), +] Cross_country_sankey = [ @@ -231,7 +332,7 @@ def generate_navbar(app): BODY = dbc.Container( [ dbc.Row([dbc.Col(dbc.Card(Sankey)),], style={"marginTop": 30}), - # dbc.Row([dbc.Col(dbc.Card(dynamic_callback)), ], style={"marginTop": 30}), + dbc.Row([dbc.Col(dbc.Card(Tracing_energy_flows)),], style={"marginTop": 30}), dbc.Row([dbc.Col(dbc.Card(Cross_country_sankey)), ], style={"marginTop": 30}), ], diff --git a/FinancialFlows.py b/FinancialFlows.py index ece589e..e7082ac 100644 --- a/FinancialFlows.py +++ b/FinancialFlows.py @@ -149,8 +149,8 @@ def select_product(): searchable=True, clearable=False, ), - dbc.Button("Add Figure", color="danger", id='update-button-cross-country-products', n_clicks=0, className="me-1"), - dbc.Button("Clear Canvas", color="primary", id='update-button-products-clear-canvas', n_clicks=0, + dbc.Button("Add Figure", color="danger", id='update-button-cross-country-trace', n_clicks=0, className="me-1"), + dbc.Button("Clear Canvas", color="primary", id='update-button-trace-clear-canvas', n_clicks=0, className="me-1"), ], diff --git a/Summary.py b/Summary.py index 5eeebe3..573f2d5 100644 --- a/Summary.py +++ b/Summary.py @@ -121,8 +121,38 @@ dbc.Col(html.Div(dcc.Graph(id="demand-per-capita", figure=figures.land_use_plot()[5]), style=figure_border_style), md=6), ]), + html.Br(), + dbc.Row([ + dbc.Col(html.Div(dcc.Graph(id="demand-per-capita-world", figure=figures.per_capita_comparison()), + style=figure_border_style), md=12), + ]), + html.Br(), + dbc.Row([ + dbc.Col(html.Div(dcc.Graph(id="demand-per-capita-world", figure=figures.per_capita_renewables()), + style=figure_border_style), md=6), + dbc.Col(html.Div(dcc.Graph(id="intensity-capita-world", figure=figures.per_capita_intensity()), + style=figure_border_style), md=6), + ]), + html.Br(), + dbc.Row([ + dbc.Col(html.Div(dcc.Graph(id="share-of-imports", figure=figures.percentage_of_imports()), + style=figure_border_style), md=12), + ]), + html.Br(), + dbc.Row([ + dbc.Col(html.Div(dcc.Graph(id="dependance-on-imports", figure=figures.dependance_on_imports()), + style=figure_border_style), md=6), + dbc.Col(html.Div(dcc.Graph(id="GDP-per-capita", figure=figures.GDP_per_capita()), + style=figure_border_style), md=6), + ]), html.Br(), + dbc.Row([ + dbc.Col(html.Div(dcc.Graph(id="dependance-on-imports", figure=figures.navigation_and_int_maritime()), + style=figure_border_style), md=6), + dbc.Col(html.Div(dcc.Graph(id="biomass-breakdown", figure=figures.biomass_consumption_breakdown()), + style=figure_border_style), md=6), + ]), ], diff --git a/WindSolar.py b/WindSolar.py index 5630752..1475914 100644 --- a/WindSolar.py +++ b/WindSolar.py @@ -190,13 +190,13 @@ def generate_single_country_drpdwn(): ), dbc.Row([ dbc.Col(html.Div(dcc.Graph(id="Pop-and-famil-size",figure=figures.rooftop_PV_plot(0.3,2.5)[0]), style=figure_border_style), md=6), - dbc.Col(html.Div(dcc.Graph(id="number-of-buildings-rooftop",figure=figures.rooftop_PV_plot(0.7,2.5)[1]), style=figure_border_style), md=6), + dbc.Col(html.Div(dcc.Graph(id="number-of-buildings-rooftop",figure=figures.rooftop_PV_plot(0.3,2.5)[1]), style=figure_border_style), md=6), ]), html.Br(), dbc.Row([ - dbc.Col(html.Div(dcc.Graph(id="rooftop-capacity", figure=figures.rooftop_PV_plot(0.7, 2.5)[3]), + dbc.Col(html.Div(dcc.Graph(id="rooftop-capacity", figure=figures.rooftop_PV_plot(0.3, 2.5)[3]), style=figure_border_style), md=6), - dbc.Col(html.Div(dcc.Graph(id="roofotp-generation",figure=figures.rooftop_PV_plot(0.7,2.5)[2]), style=figure_border_style), md=6), + dbc.Col(html.Div(dcc.Graph(id="roofotp-generation",figure=figures.rooftop_PV_plot(0.3,2.5)[2]), style=figure_border_style), md=6), ]), html.Br(), ], diff --git a/callbacks_sankey.py b/callbacks_sankey.py index 24ab442..9421208 100644 --- a/callbacks_sankey.py +++ b/callbacks_sankey.py @@ -116,3 +116,46 @@ def update_cross_country_comparison(n_clicks,clear_canvas,from_,to_,normalizatio return hidden_div,div_children + + + +@app.callback( + [ + Output('Hidden_Div_breakdown', "children"), + Output('dynamic_callback_container_energy_breakdown', 'children')], + [Input('update-button-cross-country-flow', 'n_clicks'), + Input('update-button-flow-clear', 'n_clicks')], + [State("select-flow-provider", "value"), + State("select-flow-cunsumer", "value"), + State("select-flow-provider-source", "value"), + State('Hidden_Div_breakdown', "children"), + State('dynamic_callback_container_energy_breakdown', 'children') + ] +) +def update_cross_country_comparison(n_clicks,clear_canvas,from_,consumer_list,carrier,hidden_div,div_children): + if n_clicks != hidden_div[0]: + print("Hereee") + + fig = figures.dynamic_breakdown_figure_generation(from_=from_,list_of_consumers=consumer_list,carrier=carrier) + print("Here2") + new_child = html.Div( + style={'display': 'inline-block', 'outline': 'thin lightgrey solid', 'padding': 5}, + children=[ + dcc.Graph( + id={ + 'type': 'dynamic-graph', + 'index': n_clicks + }, + figure=fig, + ), + ] + ) + div_children.append(new_child) + + elif clear_canvas != hidden_div[1]: + div_children = [] + + hidden_div = [n_clicks,clear_canvas] + + return hidden_div,div_children + diff --git a/figures.py b/figures.py index 21fcba9..fcb0185 100644 --- a/figures.py +++ b/figures.py @@ -4,8 +4,10 @@ import plotly.express as px import functions from EnergyFlows import Country_List -font_color = 'white' -line_color = 'white' +import warnings +warnings.filterwarnings('ignore') +font_color = 'black' +line_color = 'black' def imports_to_GDP(year): net_imp_list= [] @@ -647,30 +649,35 @@ def decarbonization_scenarios(Country,Efficiency,oil_imports_2019,demand,growth_ def rooftop_PV_plot(available_buildings,PV_size): - import pandas as pd - rooftop_df = pd.DataFrame() - df = pd.read_csv('Data/Rooftop Potential.csv') - Countries = df['Country'] - Population = df['Population'] - Household_size = df['Household size'] - solar_radiation = df['Potential of Av.PV gen (GWh/MW/year)'] - number_of_homes = available_buildings*Population/Household_size # only those homes with rooftop PV potential - number_of_homes = number_of_homes.round(0) - rooftop_capacity_MW = number_of_homes * PV_size/1000 - rooftop_capacity_MW = rooftop_capacity_MW.round(1) - rooftop_PV_generation_GWh = rooftop_capacity_MW * solar_radiation - rooftop_PV_generation_GWh = rooftop_PV_generation_GWh.astype(float) - rooftop_PV_generation_GWh = rooftop_PV_generation_GWh.round(decimals=1) - - rooftop_df['Generation_GWh'] = rooftop_PV_generation_GWh - rooftop_df.to_csv('rooftop_Pv_potential.csv') + # import pandas as pd + # rooftop_df = pd.DataFrame() + # df = pd.read_csv('Data/Rooftop Potential.csv') + # Countries = df['Country'] + # Population = df['Population'] + # Household_size = df['Household size'] + # solar_radiation = df['Potential of Av.PV gen (GWh/MW/year)'] + # number_of_homes = available_buildings*Population/Household_size # only those homes with rooftop PV potential + # number_of_homes = number_of_homes.round(0) + # rooftop_capacity_MW = number_of_homes * PV_size/1000 + # rooftop_capacity_MW = rooftop_capacity_MW.round(1) + # rooftop_PV_generation_GWh = rooftop_capacity_MW * solar_radiation + # rooftop_PV_generation_GWh = rooftop_PV_generation_GWh.astype(float) + # rooftop_PV_generation_GWh = rooftop_PV_generation_GWh.round(decimals=1) + # + # rooftop_df['Generation_GWh'] = rooftop_PV_generation_GWh + # rooftop_df['Country'] = Countries + # + # rooftop_df.to_csv('rooftop_Pv_potential.csv') + + rooftop_df = functions.calculate_rooftop_PV_potential(available_buildings=available_buildings,PV_size=PV_size) + fig = make_subplots(specs=[[{"secondary_y": True}]]) fig.add_trace( - go.Bar(x=Countries, y=Population, name="Population",marker_color='forestgreen'), + go.Bar(x=rooftop_df['Country'], y=rooftop_df['Population'], name="Population",marker_color='forestgreen'), secondary_y=False, ) fig.add_trace( - go.Scatter(x=Countries, y=Household_size, name="Average household size",marker_color='red',mode='markers'), + go.Scatter(x=rooftop_df['Country'], y=rooftop_df['Household_size'], name="Average household size",marker_color='red',mode='markers'), secondary_y=True,) fig.update_yaxes(title_text="Population", secondary_y=False,showline=True,showgrid=True,linecolor=line_color,gridcolor=line_color) fig.update_yaxes(title_text="Average household size", secondary_y=True,showline=True, showgrid=True,linecolor=line_color,gridcolor=line_color) @@ -701,7 +708,7 @@ def rooftop_PV_plot(available_buildings,PV_size): barmode='group') fig2 = make_subplots(specs=[[{"secondary_y": True}]]) fig2.add_trace( - go.Bar(x=Countries, y=number_of_homes,text=number_of_homes, name="Number of homes available for rooftop PV",marker_color='forestgreen'), + go.Bar(x=rooftop_df['Country'], y=rooftop_df['avaialble_homes'],text=rooftop_df['avaialble_homes'], name="Number of homes available for rooftop PV",marker_color='forestgreen'), secondary_y=False, ) fig2.update_yaxes(title_text="Number of homes available for rooftop PV", secondary_y=False,showline=True,showgrid=True,linecolor=line_color,gridcolor=line_color) @@ -731,7 +738,7 @@ def rooftop_PV_plot(available_buildings,PV_size): fig3 = make_subplots(specs=[[{"secondary_y": False}]]) fig3.add_trace( - go.Bar(x=Countries, y=rooftop_PV_generation_GWh,text=rooftop_PV_generation_GWh, name="Potential rooftop PV generation (GWh)",marker_color='forestgreen'), + go.Bar(x=rooftop_df['Country'], y=rooftop_df['Country'],text=rooftop_df['Country'], name="Potential rooftop PV generation (GWh)",marker_color='forestgreen'), ) fig3.update_yaxes(title_text="Rooftop PV generation (GWh/year)", showline=True, showgrid=True,linecolor=line_color,gridcolor=line_color) fig3.update_xaxes(showgrid=False,showline=True,linecolor=line_color) @@ -759,7 +766,7 @@ def rooftop_PV_plot(available_buildings,PV_size): fig4 = make_subplots(specs=[[{"secondary_y": False}]]) fig4.add_trace( - go.Bar(x=Countries, y=rooftop_capacity_MW, text=rooftop_capacity_MW,name="Rooftop PV capacity",marker_color='forestgreen'), + go.Bar(x=rooftop_df['Country'], y=rooftop_df['Capacity_MW'], text=rooftop_df['Capacity_MW'],name="Rooftop PV capacity",marker_color='forestgreen'), ) fig4.update_yaxes(title_text="Potential rooftop PV capacity (MW)", secondary_y=False,showline=True,showgrid=True,linecolor=line_color,gridcolor=line_color) @@ -1110,11 +1117,11 @@ def land_use_plot(): countries = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[0] non_RE_demand = non_RE_demand.round(0) final_demand=final_demand.round(0) + world_average_demand = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[11].round(0) summary_demand_df['countries'] = countries summary_demand_df['non-RE-GWh'] = non_RE_demand summary_demand_df['final-GWh'] = final_demand - summary_demand_df.to_csv("demand_df_GWh.csv") df_pop = pd.read_csv('Data/Economic Indicators.csv') df = pd.read_excel('Data/Potentials.xlsx') @@ -1146,10 +1153,11 @@ def land_use_plot(): - final_demand_per_capita = 1000*final_demand/df_pop['Population']#MWh/year.person - non_RE_demand_per_capita = 1000*non_RE_demand/df_pop['Population']#MWh/year.person + final_demand_per_capita = 1000 * final_demand/df_pop['Population']#MWh/year.person + non_RE_demand_per_capita = 1000 * non_RE_demand/df_pop['Population']#MWh/year.person final_demand_per_capita = final_demand_per_capita.round(1) non_RE_demand_per_capita = non_RE_demand_per_capita.round(1) + fig = make_subplots(specs=[[{"secondary_y": False}]]) fig.add_trace(go.Scatter(x=countries, y=Wind_MW_non_RE, name='Decarbonizing the electricity sector', @@ -1300,6 +1308,9 @@ def land_use_plot(): fig4.add_trace(go.Bar(x=countries, y=final_demand,text=final_demand, name='Meeting the final demand', marker_color='darkgrey', )) + fig4.add_trace(go.Bar(x=countries, y=world_average_demand,text=world_average_demand, name='World average per capita demand', + marker_color='green', + )) fig4.update_layout(legend=dict(bgcolor='rgba(0,0,0,0)', yanchor="bottom", orientation="h", y=0.98, xanchor="center", @@ -1349,7 +1360,7 @@ def land_use_plot(): 'plot_bgcolor': 'rgba(0,0,0,0)', 'paper_bgcolor': 'rgba(0,0,0,0)', }) - fig5.update_yaxes(title_text="Demand (MWh/year.person)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig5.update_yaxes(title_text="Demand (MWh/year/person)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) fig5.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) fig5.update_layout( title="Demand per capita") @@ -1644,68 +1655,14 @@ def import_export_figure_dynamic(df,product): def Solar_physical_resources(): - df_technical_potential = pd.DataFrame() import plotly.graph_objs as go - names = ['Wind', 'PV'] - df = pd.read_excel('Data/Potentials.xlsx') - countries = Country_List - Wind_pot = df.iloc[2, 2:] # GWh/MW/year - PV_pot = df.iloc[0, 2:] # GWh/MW/year - coastline = df.iloc[13,2:] - area = df.iloc[14,2:] - - arable = df.iloc[4, 2:] - crops = df.iloc[5, 2:] - pasture = df.iloc[6, 2:] - forested = df.iloc[7, 2:] - other = df.iloc[8, 2:] - percentage_of_available_land = 0.01 - Technical_PV_area = (percentage_of_available_land * pasture/100 + percentage_of_available_land * arable/100) * area - - - Theoretical_PV = PV_pot * area * 0.1 * 1000 * 0.8 #GWh - Theoretical_wind = Wind_pot * coastline * (1.5/0.25) * 0.8 # GWh - - Technical_PV_GWh = PV_pot * Technical_PV_area * 0.1 * 1000 * 0.8 #GWh - Technical_wind_GWh = Theoretical_wind * 0.1 - - Theoretical_PV_GW = area * 1000 * 0.1/1000 - Technical_PV_GW = Technical_PV_area * 1000 * 0.1 / 1000 - - Theoretical_wind_GW = (1.5/0.25) * coastline/1000 - Technical_wind_GW = Theoretical_wind_GW * 0.1 - Theoretical_wind = Theoretical_wind * 0.1 - Theoretical_wind_GW = Theoretical_wind_GW * 0.1 - - Theoretical_PV = Theoretical_PV.astype(int) - Theoretical_wind = Theoretical_wind.astype(float) - Theoretical_wind = Theoretical_wind.round(decimals= 1) - - Theoretical_PV_GW = Theoretical_PV_GW.astype(int) - Theoretical_wind_GW = Theoretical_wind_GW.astype(float) - Theoretical_wind_GW = Theoretical_wind_GW.round(decimals= 2) - Technical_PV_GW = Technical_PV_GW.astype(float) - Technical_PV_GW = Technical_PV_GW.round(decimals=1) - - Technical_PV_GWh = Technical_PV_GWh.astype(int) - Technical_wind_GWh = Technical_wind_GWh.astype(int) - - df_technical_potential['Country'] = countries - df_technical_potential['PV_technical_potential_GWh'] = Technical_PV_GWh.values - df_technical_potential['Wind_technical_potential_GWh'] = Technical_wind_GWh.values - df_technical_potential['sum_of_wind_and_solar_GWh'] =df_technical_potential['PV_technical_potential_GWh']+df_technical_potential['Wind_technical_potential_GWh'] - df_technical_potential['Pv_MW'] = Technical_PV_GW.values - df_technical_potential['Wind_MW'] = Theoretical_wind_GW.values - df_technical_potential.to_csv('Wind_and_solar_technical_potential.csv') - - - + df_technical_potential = functions.calculate_PV_Wind_potential() fig = go.Figure(data=[go.Bar( - x=countries, - y=PV_pot, + x=df_technical_potential['Country'], + y=df_technical_potential['PV_pot'], )]) fig.update_layout( @@ -1728,8 +1685,8 @@ def Solar_physical_resources(): fig2 = go.Figure(data=[go.Bar( - x=countries, - y=Wind_pot, + x=df_technical_potential['Country'], + y=df_technical_potential['Wind_pot'], )]) fig2.update_layout( @@ -1749,9 +1706,9 @@ def Solar_physical_resources(): marker_line_width=2, opacity=1) fig3 = go.Figure(data=[go.Bar( - x=countries, - y=Theoretical_wind, - text=Theoretical_wind + x=df_technical_potential['Country'], + y=df_technical_potential['Wind_technical_GWh'], + text=df_technical_potential['Wind_technical_GWh'] )]) fig3.update_layout( title="Technical wind generation") @@ -1771,9 +1728,9 @@ def Solar_physical_resources(): # fig3.update_traces(texttemplate='%{text:.1s}') fig4 = go.Figure(data=[go.Bar( - x=countries, - y=Theoretical_PV, - text=Theoretical_PV + x=df_technical_potential['Country'], + y=df_technical_potential['Theoretical_PV_GWh'], + text=df_technical_potential['Theoretical_PV_GWh'] )]) fig4.update_layout( title="Theoretical PV generation") @@ -1792,9 +1749,9 @@ def Solar_physical_resources(): fig4.update_traces(texttemplate='%{text:.1s}') fig5 = go.Figure(data=[go.Bar( - x=countries, - y=Theoretical_PV_GW, - text=Theoretical_PV_GW + x=df_technical_potential['Country'], + y=df_technical_potential['Theoretical_PV_GW'], + text=df_technical_potential['Theoretical_PV_GW'] )]) fig5.update_layout( title="Theoretical PV capacity") @@ -1812,9 +1769,9 @@ def Solar_physical_resources(): marker_line_width=2, opacity=1) fig6 = go.Figure(data=[go.Bar( - x=countries, - y=Theoretical_wind_GW, - text=Theoretical_wind_GW + x=df_technical_potential['Country'], + y=df_technical_potential['Wind_technical_GW'], + text=df_technical_potential['Wind_technical_GW'] )]) fig6.update_layout( title="Technical wind capacity") @@ -1832,9 +1789,9 @@ def Solar_physical_resources(): marker_line_width=2, opacity=1) fig7 = go.Figure(data=[go.Bar( - x=countries, - y=Technical_PV_GW, - text=Technical_PV_GW + x=df_technical_potential['Country'], + y=df_technical_potential['PV_technical_GW'], + text=df_technical_potential['PV_technical_GW'] )]) fig7.update_layout( title="Technical PV capacity") @@ -1853,9 +1810,9 @@ def Solar_physical_resources(): # fig7.update_traces(texttemplate='%{text:.1s}') fig8 = go.Figure(data=[go.Bar( - x=countries, - y=Technical_PV_GWh, - text=Technical_PV_GWh + x=df_technical_potential['Country'], + y=df_technical_potential['PV_technical_GWh'], + text=df_technical_potential['PV_technical_GWh'] )]) fig8.update_layout( title="Technical PV generation") @@ -1941,7 +1898,634 @@ def elec_price_plot(): return fig -def Total_imports_plot(): - pass - #total imports in GWh - # final demand comparative in GWh \ No newline at end of file +def per_capita_comparison(): + + total_demand_electrified = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[1] + total_demand = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='SummaryPlot')[1] + + non_RE_elec = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[9] # Decarbonizing the electricity sector + + countries = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[0] + non_RE_elec = non_RE_elec.round(0) + total_demand_electrified = total_demand_electrified.round(0) + + df_pop = pd.read_csv('Data/Economic Indicators.csv') + + total_demand_electrified_per_capita = 1000 * total_demand_electrified / df_pop['Population'] # MWh/year/person + total_demand_per_capita = 1000 * total_demand / df_pop['Population'] # MWh/year/person + non_RE_elec_per_capita = 1000 * non_RE_elec / df_pop['Population'] # MWh/year/person + + total_demand_electrified_per_capita = total_demand_electrified_per_capita.round(1) + total_demand_per_capita = total_demand_per_capita.round(1) + non_RE_elec_per_capita = non_RE_elec_per_capita.round(1) + + wolrd_per_capita_use = pd.read_csv('Data/worldinData/per-capita-energy-use.csv') + wolrd_per_capita_use = wolrd_per_capita_use.sort_values('Year', ascending=False).drop_duplicates(['Entity']) + wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'] = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)']/1000 #MWh/capita + wolrd_average_per_capita_use = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].mean() + wolrd_median_per_capita_use = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].median() + + wolrd_per_capita_use['Entity'] = wolrd_per_capita_use['Entity'].replace('Micronesia (country)','Micronesia') + wolrd_per_capita_use['Entity'] = wolrd_per_capita_use['Entity'].replace('Papua New Guinea','PNG') + + wolrd_per_capita_use = wolrd_per_capita_use[wolrd_per_capita_use.Entity.isin(Country_List)] + wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'] = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].round(1) + + fig_use_cap = make_subplots(specs=[[{"secondary_y": False}]]) + fig_use_cap.add_trace(go.Bar(x=countries, y=non_RE_elec_per_capita,text=non_RE_elec_per_capita, name='Decarbonizing the electricity sector-this research', + marker_color='red', + )) + fig_use_cap.add_trace(go.Bar(x=countries, y=total_demand_electrified_per_capita,text=total_demand_electrified_per_capita, name='Final electrified demand-this research', + marker_color='green', + )) + fig_use_cap.add_trace(go.Bar(x=countries, y=total_demand_per_capita,text=total_demand_per_capita, name='Total demand-this research', + marker_color='blue', + )) + fig_use_cap.add_trace(go.Bar(x=wolrd_per_capita_use['Entity'], y=wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'],text=wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'], name='Total demand-our world in data', + marker_color='orange', + )) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='red'), + x0=0, x1=len(countries), y0=wolrd_average_per_capita_use, y1=wolrd_average_per_capita_use + ) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='orange'), + x0=0, x1=len(countries), y0=wolrd_median_per_capita_use, y1=wolrd_median_per_capita_use + ) + fig_use_cap.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=18, + color=font_color + ), + hovermode="x" + + ) + fig_use_cap.add_annotation(x=0.5, y=wolrd_average_per_capita_use+4, + text="World average = {}".format(wolrd_average_per_capita_use.round(1)), + showarrow=False, font=dict( + color=font_color, + size=18 + ), + ) + fig_use_cap.add_annotation(x=0.5, y=wolrd_median_per_capita_use+4, + text="World median = {}".format(wolrd_median_per_capita_use.round(1)), + showarrow=False, font=dict( + color=font_color, + size=18 + ), + ) + fig_use_cap.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_use_cap.update_yaxes(title_text="Demand (MWh/year/person)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig_use_cap.update_layout( + title="Demand per capita for different demand scenarios") + fig_use_cap.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig_use_cap.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Our world in data ") + + + + + + return fig_use_cap + +def per_capita_renewables(): + countries = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[0] + + renewable_electricity = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[8] + df_pop = pd.read_csv('Data/Economic Indicators.csv') + + renewable_electricity = 1000 * renewable_electricity / df_pop['Population'] #MWh/year/capita + + + wolrd_per_capita_RE_elec = pd.read_csv('Data/worldinData/low-carbon-elec-per-capita.csv') + + wolrd_per_capita_RE_elec = wolrd_per_capita_RE_elec.sort_values('Year', ascending=False).drop_duplicates(['Entity']) + wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'] = wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)']/1000 #MWh/capita + wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'] = wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'] + wolrd_average_per_capita_RE_elec = wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'].mean() + wolrd_median_per_capita_RE_elec = wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'].median() + + wolrd_per_capita_RE_elec['Entity'] = wolrd_per_capita_RE_elec['Entity'].replace('Micronesia (country)','Micronesia') + wolrd_per_capita_RE_elec['Entity'] = wolrd_per_capita_RE_elec['Entity'].replace('Papua New Guinea','PNG') + + + wolrd_per_capita_RE_elec = wolrd_per_capita_RE_elec[wolrd_per_capita_RE_elec.Entity.isin(Country_List)] + + + + fig_use_cap = make_subplots(specs=[[{"secondary_y": False}]]) + fig_use_cap.add_trace(go.Bar(x=countries, y=renewable_electricity,text=renewable_electricity.round(2), name='This research', + marker_color='red', + )) + fig_use_cap.add_trace(go.Bar(x=wolrd_per_capita_RE_elec['Entity'], y=wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'],text=wolrd_per_capita_RE_elec['Low-carbon electricity per capita (kWh)'].round(1), name='Our world in data', + marker_color='green', + )) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='red'), + x0=0, x1=len(countries), y0=wolrd_average_per_capita_RE_elec, y1=wolrd_average_per_capita_RE_elec + ) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='orange'), + x0=0, x1=len(countries), y0=wolrd_median_per_capita_RE_elec, y1 = wolrd_median_per_capita_RE_elec + ) + fig_use_cap.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_use_cap.add_annotation(x=0.8, y=wolrd_average_per_capita_RE_elec+0.1, + text="World average = {}".format(wolrd_average_per_capita_RE_elec.round(1)), + showarrow=False, font=dict( + color=font_color, + size=16 + ), + ) + fig_use_cap.add_annotation(x=0.8, y=wolrd_median_per_capita_RE_elec+0.1, + text="World median = {}".format(wolrd_median_per_capita_RE_elec.round(1)), + showarrow=False, font=dict( + color=font_color, + size=16 + ), + ) + fig_use_cap.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_use_cap.update_yaxes(title_text="Renewable electricity (MWh/year/person)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig_use_cap.update_layout( + title="Renewable electricity generation per capita") + fig_use_cap.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig_use_cap.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Our world in data ") + + return fig_use_cap + + +def per_capita_intensity(): + + countries = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[0] + + wolrd_per_capita_intensity = pd.read_csv('Data/worldinData/energy-intensity-of-economies.csv') + wolrd_per_capita_intensity = wolrd_per_capita_intensity.sort_values('Year', ascending=False).drop_duplicates(['Entity']) + wolrd_average_per_capita_intensity = wolrd_per_capita_intensity['Energy intensity level of primary energy (MJ/$2017 PPP GDP)'].mean() + wolrd_median_per_capita_intensity = wolrd_per_capita_intensity['Energy intensity level of primary energy (MJ/$2017 PPP GDP)'].median() + + wolrd_per_capita_intensity['Entity'] = wolrd_per_capita_intensity['Entity'].replace('Micronesia (country)','Micronesia') + wolrd_per_capita_intensity['Entity'] = wolrd_per_capita_intensity['Entity'].replace('Papua New Guinea','PNG') + wolrd_per_capita_intensity = wolrd_per_capita_intensity[wolrd_per_capita_intensity.Entity.isin(Country_List)] + + + total_demand = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='SummaryPlot')[1] + df_GDP = pd.read_csv('Data/Economic Indicators.csv') + df_GDP['Demand'] = total_demand + df_GDP['Demand_per_gdp'] = (df_GDP['Demand']*1000000)/(df_GDP['GDP(million$)2019']*1000000) + + + + fig_use_cap = make_subplots(specs=[[{"secondary_y": False}]]) + fig_use_cap.add_trace(go.Bar(x=countries, y=df_GDP['Demand_per_gdp'].round(1),text=df_GDP['Demand_per_gdp'].round(1), name='This research', + marker_color='red', + )) + fig_use_cap.add_trace(go.Bar(x=wolrd_per_capita_intensity['Entity'], y=wolrd_per_capita_intensity['Energy intensity level of primary energy (MJ/$2017 PPP GDP)'],text=wolrd_per_capita_intensity['Energy intensity level of primary energy (MJ/$2017 PPP GDP)'].round(1), name='Our world in data', + marker_color='green', + )) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='red'), + x0=0, x1=len(countries), y0=wolrd_average_per_capita_intensity, y1=wolrd_average_per_capita_intensity + ) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='orange'), + x0=0, x1=len(countries), y0=wolrd_median_per_capita_intensity, y1 = wolrd_median_per_capita_intensity + ) + fig_use_cap.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_use_cap.add_annotation(x=15, y=wolrd_average_per_capita_intensity+0.12, + text="World average = {}".format(wolrd_average_per_capita_intensity.round(1)), + showarrow=False, font=dict( + color=font_color, + size=16 + ), + ) + fig_use_cap.add_annotation(x=15, y=wolrd_median_per_capita_intensity+0.12, + text="World median = {}".format(wolrd_median_per_capita_intensity.round(1)), + showarrow=False, font=dict( + color=font_color, + size=16 + ), + ) + fig_use_cap.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_use_cap.update_yaxes(title_text="(kWh/$ PPP GDP)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig_use_cap.update_layout( + title="Energy (primary, total) intensity of economies") + fig_use_cap.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig_use_cap.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Our world in data ") + return fig_use_cap + +def percentage_of_imports(): + countries = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[0] + total_energy_supply = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='SummaryPlot')[1] + net_imports = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[15] + current_share_of_imports = 100 * net_imports/total_energy_supply + + + world_average_demand = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[11] *100/80 # convert to total instead of electricity + renewables_in_total = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[7] + world_average_demand_non_RE = (world_average_demand - renewables_in_total) * 80/100 # convert to electricity + rooftop_PV_df = functions.calculate_rooftop_PV_potential() + wind_PV_df = functions.calculate_PV_Wind_potential() + remaining_demand_world_average = world_average_demand_non_RE - rooftop_PV_df['Generation_GWh'] - wind_PV_df['PV_technical_GWh'] + imports_world_average = 100 * remaining_demand_world_average/world_average_demand_non_RE + + imports_df = pd.DataFrame() + + demand_for_decarb = functions.fetch_all_countries_demand(2019)[9] + countries = functions.fetch_all_countries_demand(2019)[0] + remaining_demand_for_decarb = demand_for_decarb - rooftop_PV_df['Generation_GWh'] - wind_PV_df['PV_technical_GWh'] + imports_decarbonization = 100 * remaining_demand_for_decarb/demand_for_decarb + imports_df['countries'] = countries + imports_df['imports_decarb_%'] = imports_decarbonization + imports_df['imports_decarb_%'] = imports_df['imports_decarb_%'].clip(lower=0) + imports_df['imports_decarb_GWh'] = remaining_demand_for_decarb + imports_df['imports_decarb_GWh'] = imports_df['imports_decarb_GWh'].clip(lower=0) + + + electrified_demand = functions.fetch_all_countries_demand(2019,Use="Analysis")[1] + remaining_demand_electrified = electrified_demand - rooftop_PV_df['Generation_GWh'] - wind_PV_df['PV_technical_GWh'] + imports_electrified = 100 * remaining_demand_electrified/electrified_demand + imports_df['imports_electrified_%'] = imports_electrified + imports_df['imports_electrified_%'] = imports_df['imports_electrified_%'].clip(lower=0) + imports_df['imports_electrified_GWh'] = remaining_demand_electrified + imports_df['imports_electrified_GWh'] = imports_df['imports_electrified_GWh'].clip(lower=0) + + imports_df['imports_world_average_%'] = imports_world_average + imports_df['imports_world_average_%'] = imports_df['imports_world_average_%'].clip(lower=0) + imports_df['imports_world_average_GWh'] = remaining_demand_world_average + imports_df['imports_world_average_GWh'] = imports_df['imports_world_average_GWh'].clip(lower=0) + + imports_df['Current_%'] = current_share_of_imports + imports_df['Current_%'] = imports_df['Current_%'].clip(lower=0) + imports_df['Current_GWh'] = net_imports + imports_df['Current_GWh'] = imports_df['Current_GWh'].clip(lower=0) + + imports_df.to_csv("imports_for_scenarios.csv") + fig_use_cap = make_subplots(specs=[[{"secondary_y": False}]]) + fig_use_cap.add_trace(go.Bar(x=imports_df['countries'], y=imports_df['Current_%'].round(1),text=imports_df['Current_%'].round(1), name='Current', + marker_color='red', + )) + fig_use_cap.add_trace(go.Bar(x=imports_df['countries'], y=imports_df['imports_decarb_%'].round(1),text=imports_df['imports_decarb_%'].round(1), name='Decarbonization', + marker_color='blue', + )) + fig_use_cap.add_trace(go.Bar(x=imports_df['countries'], y=imports_df['imports_electrified_%'].round(1),text=imports_df['imports_electrified_%'].round(1), name='Electrification', + marker_color='brown', + )) + fig_use_cap.add_trace(go.Bar(x=imports_df['countries'], y=imports_df['imports_world_average_%'].round(1),text=imports_df['imports_world_average_%'].round(1), name="Wolrd average", + marker_color='green', + )) + + fig_use_cap.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_use_cap.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_use_cap.update_yaxes(title_text="% of total demand", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig_use_cap.update_layout( + title="The share of total demand met by net energy imports") + fig_use_cap.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig_use_cap.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Our world in data ") + return fig_use_cap + +def dependance_on_imports(): + countries = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[0] + total_energy_supply = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='SummaryPlot')[1] + net_imports = functions.fetch_all_countries_demand(2019,Unit='GWh',Use='Analysis')[15] + current_share_of_imports = 100 * net_imports/total_energy_supply + + + + fig_use_cap = make_subplots(specs=[[{"secondary_y": False}]]) + fig_use_cap.add_trace(go.Bar(x=countries, y=current_share_of_imports,text=current_share_of_imports.round(0), name='This research', + marker_color='green', + )) + + fig_use_cap.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_use_cap.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_use_cap.update_yaxes(title_text="Dependance on net imports (%)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig_use_cap.update_layout( + title="Dependance on net imports (share of net imports in total demand)") + fig_use_cap.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig_use_cap.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Our world in data ") + return fig_use_cap + + +def GDP_per_capita(): + summary_df = pd.read_csv('Data/SummaryTable.csv') + + summary_df = summary_df[summary_df['Country / Territory'].isin(Country_List)] + + world_GDP_capita = pd.read_csv("Data/worldinData/gdp-per-capita-worldbank.csv") + world_GDP_capita = world_GDP_capita.sort_values('Year', ascending=False).drop_duplicates(['Entity']) + + wolrd_average_GDP_per_capita = world_GDP_capita['GDP per capita, PPP (constant 2017 international $)'].mean() + wolrd_median_GDP_per_capita = world_GDP_capita['GDP per capita, PPP (constant 2017 international $)'].median() + fig_use_cap = make_subplots(specs=[[{"secondary_y": False}]]) + fig_use_cap.add_trace(go.Bar(x=summary_df['Country / Territory'], y=summary_df['GDP Per Capita ($)'],text=summary_df['GDP Per Capita ($)'],name='This research', + marker_color='green', + )) + + + fig_use_cap.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_use_cap.add_shape( + type='line', line=dict(dash='dot', color='red'), + x0=0, x1=len(summary_df['Country / Territory']), y0=wolrd_average_GDP_per_capita, y1=wolrd_average_GDP_per_capita + ) + fig_use_cap.add_shape( + type='line', line=dict(dash='dot', color='orange'), + x0=0, x1=len(summary_df['Country / Territory']), y0=wolrd_median_GDP_per_capita, y1 = wolrd_median_GDP_per_capita + ) + fig_use_cap.add_annotation(x=15, y=wolrd_average_GDP_per_capita+1000, + text="World average = {}".format(wolrd_average_GDP_per_capita.round(0)), + showarrow=False, font=dict( + color=font_color, + size=16 + ), + ) + fig_use_cap.add_annotation(x=15, y=wolrd_median_GDP_per_capita+1000, + text="World median = {}".format(wolrd_median_GDP_per_capita.round(0)), + showarrow=False, font=dict( + color=font_color, + size=16 + ), + ) + + fig_use_cap.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig_use_cap.update_yaxes(title_text="GDP per Capita ($)", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig_use_cap.update_layout( + title="GDP per capita and comparison with world's average") + fig_use_cap.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig_use_cap.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig_use_cap.update_xaxes(showline=True, linecolor=line_color, + title_text="Source: Our world in data ") + return fig_use_cap + + +def biomass_consumption_breakdown(): + import os + import plotly.express as px + + list_of_consumers = ['Electricity Plants',"Manufacturing const. and mining",'Households','Commerce and public services', + 'Agriculture forestry and fishing','Other consumption n.e.s'] + path = 'Data/EnergyBalance' + files = os.listdir(path) + + df = pd.read_csv("Data/EnergyBalance/{}/all_countries_df.csv".format(files[-1])) + df = df[["Country ({})".format(files[-1]),"Transactions(down)/Commodity(right)",'Biofuels and Waste']] + df_final = pd.DataFrame() + for country in Country_List: + df_1 = df[df["Country ({})".format(files[-1])]==country] + primary_production = df_1.iloc[0, 2] + # print(primary_production) + # df_1.loc[:,'primary_production'] = primary_production + df_1.loc[:,'Biofuels and Waste'] = 100 * df_1.loc[:,'Biofuels and Waste']/primary_production#/df_1.loc[:,'primary_production'] + if df_final.shape[0] ==0: + df_final = df_1 + else: + df_final = pd.concat([df_final,df_1]) + df_final = df_final[df_final["Transactions(down)/Commodity(right)"].isin(list_of_consumers)] + + fig = px.bar(df_final, x="Country ({})".format(files[-1]), y="Biofuels and Waste", color="Transactions(down)/Commodity(right)") + + + fig.update_layout(legend=dict(bgcolor='rgba(0,0,0,0)', yanchor="bottom", orientation="v", + # y=0.98, + xanchor="center", + # x=0.2 + ), + font=dict( + family="Calibri", + size=16, + color=font_color + ), + # hovermode="x" + + ) + + fig.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig.update_yaxes(title_text="% biofuel and waste primary production", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig.update_layout( + title="Breakdown of biofuel and waste consumption") + fig.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig.update_layout(legend={'title_text': ''}) + + fig.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig.update_xaxes(showline=True,linecolor=line_color, + title_text="Source: Energy Balances, United Nations"), + return fig + + +def navigation_and_int_maritime(): + import os + import plotly.express as px + + list_of_consumers = ['International marine bunkers',"Domestic navigation"] + path = 'Data/EnergyBalance' + files = os.listdir(path) + + df = pd.read_csv("Data/EnergyBalance/{}/all_countries_df.csv".format(files[-1])) + df = df[["Country ({})".format(files[-1]),"Transactions(down)/Commodity(right)",'Total Energy']] + df_final = pd.DataFrame() + for country in Country_List: + df_1 = df[df["Country ({})".format(files[-1])]==country] + total_primary_production = df_1.iloc[0, 2] + # print(primary_production) + # df_1.loc[:,'total_primary_production'] = total_primary_production + df_1.loc[:,'Total Energy'] = 100 * abs(df_1.loc[:,'Total Energy'])/total_primary_production#df_1.loc[:,'total_primary_production'] + if df_final.shape[0] ==0: + df_final = df_1 + else: + df_final = pd.concat([df_final,df_1]) + df_final = df_final[df_final["Transactions(down)/Commodity(right)"].isin(list_of_consumers)] + + fig = px.bar(df_final, x="Country ({})".format(files[-1]), y="Total Energy", color="Transactions(down)/Commodity(right)") + fig.update_layout(legend=dict(bgcolor='rgba(0,0,0,0)', yanchor="bottom", orientation="v", + # y=0.98, + xanchor="center", + # x=0.2 + ), + font=dict( + family="Calibri", + size=16, + color=font_color + ), + # hovermode="x" + + ) + + fig.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig.update_yaxes(title_text="% of total primary production", showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig.update_layout( + title="Primary production vs domestic and international marine transport") + fig.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig.update_layout(legend={'title_text': ''}) + + fig.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig.update_xaxes(showline=True,linecolor=line_color, + title_text="Source: Energy Balances, United Nations"), + return fig +# biomass_consumption_breakdown() + + + +def dynamic_breakdown_figure_generation(from_="Primary production",list_of_consumers = ['International marine bunkers',"Domestic navigation"],carrier = 'Total Energy'): + import os + import plotly.express as px + + # list_of_consumers = ['International marine bunkers',"Domestic navigation"] + path = 'Data/EnergyBalance' + files = os.listdir(path) + + df = pd.read_csv("Data/EnergyBalance/{}/all_countries_df.csv".format(files[-1])) + df = df[["Country ({})".format(files[-1]),"Transactions(down)/Commodity(right)",carrier]] + df_final = pd.DataFrame() + for country in Country_List: + df_1 = df[df["Country ({})".format(files[-1])]==country] + # total_primary_production = df_1.loc[from_, carrier] + total_primary_production = df_1[df_1["Transactions(down)/Commodity(right)"] == from_][carrier].values[0] + df_1.loc[:,carrier] = 100 * abs(df_1.loc[:,carrier])/total_primary_production# + if df_final.shape[0] == 0: + df_final = df_1 + else: + df_final = pd.concat([df_final,df_1]) + df_final = df_final[df_final["Transactions(down)/Commodity(right)"].isin(list_of_consumers)] + + fig = px.bar(df_final, x="Country ({})".format(files[-1]), y=carrier, color="Transactions(down)/Commodity(right)") + fig.update_layout( + legend=dict(bgcolor='rgba(0,0,0,0)', orientation="h", + # yanchor="bottom", + y=1.2, + # xanchor="right", + # x=0 + ), + font=dict( + family="Calibri", + size=15, + color=font_color + ), + # hovermode="x" + + ) + + fig.update_layout({ + 'plot_bgcolor': 'rgba(0,0,0,0)', + 'paper_bgcolor': 'rgba(0,0,0,0)', + }) + fig.update_yaxes(title_text="% of {} {}".format(carrier,from_), showline=True,rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig.update_xaxes(showline=True,showgrid=False,linecolor=line_color,) + fig.update_layout( + title="") + fig.update_traces(marker_line_color=font_color, + marker_line_width=0, opacity=1) + fig.update_layout(legend={'title_text': ''}) + + fig.update_yaxes(rangemode='tozero',linecolor=line_color,gridcolor=line_color) + fig.update_xaxes(showline=True,linecolor=line_color, + title_text="Source: Energy Balances, United Nations"), + return fig \ No newline at end of file diff --git a/functions.py b/functions.py index 7e37e24..f8cb376 100644 --- a/functions.py +++ b/functions.py @@ -1,6 +1,6 @@ import pandas as pd import numpy as np - +from EnergyFlows import Country_List def fetch_wind_PV_potential(Country): df_p = pd.read_excel('Data/Potentials.xlsx') @@ -29,12 +29,18 @@ def fetch_single_country_demand(Country,Year,Unit='GWh'): final demand is the non renewable part of the demand, assuming that all sectors are electrified """ final_demand = non_RE_demand + (final_consumption-final_consumption_electricity-ofWhichRenewable_final_consumption) * (1-electrification_efficiency_improvement) - #previously - # final_demand = df[df['Transactions(down)/Commodity(right)']=='Total energy supply']['Total Energy'].values[0] #TJ + + df_world_per_capita_demand = pd.read_csv("Data/worldinData/per-capita-energy-use.csv") + per_capita_average = df_world_per_capita_demand['Primary energy consumption per capita (kWh/person)'].mean() #kWh/person + df_pop = pd.read_csv('Data/Economic Indicators.csv') + population = df_pop[df_pop.Country == Country]['Population'].values[0] + print(population) + wolrd_average_demand = per_capita_average * population/1000000 # GWh/year if Unit =='GWh': final_demand = final_demand * 0.277778 non_RE_demand = non_RE_demand * 0.277778 + wolrd_average_demand = wolrd_average_demand * 0.277778 return non_RE_demand,final_demand @@ -68,17 +74,18 @@ def fetch_all_countries_demand(Year,Unit='GWh',Use="Analysis"): # final_demand = df[df['Transactions(down)/Commodity(right)']=='Total energy supply']['Total Energy'].values Countries = df. iloc[:, 1].unique() - ElectricitySupply = df[df['Transactions(down)/Commodity(right)']=='Transformation']['Electricity'].values #TJ - ofWhichRenewable_transformation = -df[df['Transactions(down)/Commodity(right)']=='Transformation']['memo: Of which Renewables'].values #TJ # This is the input to power plants + ElectricitySupply = df[df['Transactions(down)/Commodity(right)']=='Electricity Plants']['Electricity'].values #TJ + ofWhichRenewable_transformation = -df[df['Transactions(down)/Commodity(right)']=='Electricity Plants']['memo: Of which Renewables'].values #TJ # This is the input to power plants renewable_transformation_efficiency = 0.35 - non_RE_demand = ElectricitySupply - ofWhichRenewable_transformation * renewable_transformation_efficiency #TJ + transformed_elec_from_renewables = ofWhichRenewable_transformation * renewable_transformation_efficiency + non_RE_elec = ElectricitySupply - transformed_elec_from_renewables #TJ if Use == 'Analysis': electrification_efficiency_improvement = 0.4 final_consumption = df[df['Transactions(down)/Commodity(right)']=='Final consumption']['Total Energy'].values #TJ#Does not include fuel for transformation. Only output of power plants and energy delivered to users ofWhichRenewable_final_consumption = df[df['Transactions(down)/Commodity(right)']=='Final consumption']['memo: Of which Renewables'].values #TJ # This is the input to power plants final_consumption_electricity = df[df['Transactions(down)/Commodity(right)']=='Final consumption']['Electricity'].values - total_demand = non_RE_demand + (final_consumption-final_consumption_electricity-ofWhichRenewable_final_consumption) * (1-electrification_efficiency_improvement) + total_demand = non_RE_elec + (final_consumption-final_consumption_electricity-ofWhichRenewable_final_consumption) * (1-electrification_efficiency_improvement) @@ -87,34 +94,65 @@ def fetch_all_countries_demand(Year,Unit='GWh',Use="Analysis"): total_demand = df[df['Transactions(down)/Commodity(right)']=='Total energy supply']['Total Energy'].values #TJ#Total energy entering the country(oil and renewables) 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 + renewable_electricity_primary = df[df['Transactions(down)/Commodity(right)']=='Primary production']['Electricity'].values #TJ + renewable_electricity = renewable_electricity_primary + transformed_elec_from_renewables + + + imports_oil = 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 + Int_marine_oil = df[df['Transactions(down)/Commodity(right)']=='International marine bunkers']['All Oil'].values + Int_avi_oil = df[df['Transactions(down)/Commodity(right)']=='International aviation bunkers']['All Oil'].values + + Int_marine_total = df[df['Transactions(down)/Commodity(right)'] == 'International marine bunkers']['Total Energy'].values + Int_avi_total = df[df['Transactions(down)/Commodity(right)'] == 'International aviation bunkers']['Total Energy'].values + exports_total = df[df['Transactions(down)/Commodity(right)'] == 'Exports']['Total Energy'].values + net_imports_total = all_imports + Int_marine_total + Int_avi_total + exports_total + + + transformation = -df[df['Transactions(down)/Commodity(right)']=='Electricity CHP & Heat Plants']['All Oil'].values transformation_losses = - df[df['Transactions(down)/Commodity(right)']=='Electricity CHP & Heat Plants']['Total Energy'].values + + wolrd_per_capita_use = pd.read_csv('Data/worldinData/per-capita-energy-use.csv') + wolrd_per_capita_use = wolrd_per_capita_use.sort_values('Year', ascending=False).drop_duplicates(['Entity']) + + wolrd_average_per_capita_use = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].mean() + wolrd_median_per_capita_use = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].median() + df_pop = pd.read_csv('Data/Economic Indicators.csv') + df_pop.rename(columns={'Country': 'Entity'}, inplace=True) + + df_pop['average_scenario_demand_GWh'] = 0.8 * df_pop[ + "Population"] * wolrd_average_per_capita_use / 1000000 # GWh/year + + world_average_demand = df_pop['average_scenario_demand_GWh']/0.277778 # it is calculated on GWh > convert to TJ + if Unit == "GWh": - non_RE_demand = non_RE_demand * 0.277778 + non_RE_elec = non_RE_elec * 0.277778 total_demand = total_demand * 0.277778 - imports = imports * 0.277778 - Int_marine = Int_marine * 0.277778 - Int_avi = Int_avi * 0.277778 + imports_oil = imports_oil * 0.277778 + Int_marine_oil = Int_marine_oil * 0.277778 + Int_avi_oil = Int_avi_oil * 0.277778 transformation = transformation * 0.277778 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 + world_average_demand = world_average_demand * 0.277778 + exports_total = exports_total * 0.277778 + Int_avi_total = Int_avi_total * 0.277778 + Int_marine_total = Int_marine_total * 0.277778 + net_imports_total = net_imports_total * 0.277778 df_demand = pd.DataFrame() df_demand['Country'] = Countries - df_demand['Non-RE'] = non_RE_demand + df_demand['Non-RE'] = non_RE_elec df_demand['Total'] = total_demand - df_demand.to_csv('demand_df.csv') - - return [Countries,total_demand,imports,Int_marine,Int_avi,transformation, + df_demand['World_average_demand'] = world_average_demand.round(0) + df_demand.to_csv("demand_df_{}.csv".format(Unit)) + return [Countries,total_demand,imports_oil,Int_marine_oil,Int_avi_oil,transformation, transformation_losses,renewables_in_total, - renewable_electricity,non_RE_demand,all_imports] + renewable_electricity,non_RE_elec,all_imports,world_average_demand, + Int_marine_total,Int_avi_total,exports_total,net_imports_total] def all_countries_cross_comparison_unstats(Year,Unit,Use): summary_df = pd.DataFrame() @@ -135,6 +173,7 @@ def all_countries_cross_comparison_unstats(Year,Unit,Use): summary_df['renewables_in_total'] = summary_list[7] summary_df['renewable_electricity'] = summary_list[8] summary_df['total imports'] = summary_list[10] + summary_df['World_average_demand'] = summary_list[11].round(0) 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) @@ -142,7 +181,7 @@ def all_countries_cross_comparison_unstats(Year,Unit,Use): 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_in_total']/population['Population']) #Tj or GWh summary_df['Renewables/capita'] = summary_df['Renewables/capita'].round(0) summary_df['marine_to_import'] = 100 * summary_df['int marine']/summary_df['Oil imports'] @@ -196,3 +235,103 @@ def Update_UNstats_database(year): all_countries_df.replace('Papua New Guinea', 'PNG',inplace=True) all_countries_df.to_csv("Data/EnergyBalance/{}/all_countries_df.csv".format(year)) + + + + +def calculate_PV_Wind_potential(available_land = 0.01,available_coastline = 0.1): + df_technical_potential = pd.DataFrame() + import plotly.graph_objs as go + df = pd.read_excel('Data/Potentials.xlsx') + countries = Country_List + Wind_pot = df.iloc[2, 2:] # GWh/MW/year + PV_pot = df.iloc[0, 2:] # GWh/MW/year + coastline = df.iloc[13,2:] + area = df.iloc[14,2:] + + arable = df.iloc[4, 2:] + crops = df.iloc[5, 2:] + pasture = df.iloc[6, 2:] + forested = df.iloc[7, 2:] + other = df.iloc[8, 2:] + Technical_PV_area = (available_land * pasture/100 + available_land * arable/100) * area + + + Theoretical_PV_GWh = PV_pot * area * 0.1 * 1000 * 0.8 #GWh + Theoretical_wind_GWh = Wind_pot * coastline * (1.5/0.25) * 0.8 # GWh + + Technical_PV_GWh = PV_pot * Technical_PV_area * 0.1 * 1000 * 0.8 #GWh + Technical_wind_GWh = Theoretical_wind_GWh * available_coastline + + Theoretical_PV_GW = area * 1000 * 0.1/1000 + Technical_PV_GW = Technical_PV_area * 1000 * 0.1 / 1000 + + Theoretical_wind_GW = (1.5/0.25) * coastline/1000 + Technical_wind_GW = Theoretical_wind_GW * available_coastline + Technical_wind_GW = Technical_wind_GW.astype(float) + Technical_wind_GW = Technical_wind_GW.round(decimals=1) + + Theoretical_PV_GWh = Theoretical_PV_GWh.astype(int) + Theoretical_wind_GWh = Theoretical_wind_GWh.astype(float) + Theoretical_wind_GWh = Theoretical_wind_GWh.round(decimals= 1) + + Theoretical_PV_GW = Theoretical_PV_GW.astype(int) + Theoretical_wind_GW = Theoretical_wind_GW.astype(float) + Theoretical_wind_GW = Theoretical_wind_GW.round(decimals= 2) + Technical_PV_GW = Technical_PV_GW.astype(float) + Technical_PV_GW = Technical_PV_GW.round(decimals=2) + + Technical_PV_GWh = Technical_PV_GWh.astype(float) + Technical_PV_GWh = Technical_PV_GWh.round(decimals=1) + + Technical_wind_GWh = Technical_wind_GWh.astype(float) + Technical_wind_GWh = Technical_wind_GWh.round(decimals=1) + + df_technical_potential['Country'] = countries + df_technical_potential['PV_pot'] = PV_pot.values + df_technical_potential['Wind_pot'] = Wind_pot.values + df_technical_potential['Theoretical_PV_GWh'] = Theoretical_PV_GWh.values + df_technical_potential['Theoretical_wind_GWh'] = Theoretical_wind_GWh.values + + df_technical_potential['Theoretical_PV_GW'] = Theoretical_PV_GW.values + df_technical_potential['Theoretical_wind_GW'] = Theoretical_wind_GW.values + + df_technical_potential['PV_technical_GWh'] = Technical_PV_GWh.values + df_technical_potential['Wind_technical_GWh'] = Technical_wind_GWh.values + + df_technical_potential['PV_technical_GW'] = Technical_PV_GW.values + df_technical_potential['Wind_technical_GW'] = Technical_wind_GW.values + + df_technical_potential['sum_of_wind_and_solar_GWh'] = df_technical_potential['PV_technical_GWh'] + df_technical_potential['Wind_technical_GWh'] + + df_technical_potential.to_csv('Wind_and_solar_technical_potential.csv') + + return df_technical_potential + +def calculate_rooftop_PV_potential(available_buildings = 0.3,PV_size = 2.5): + import pandas as pd + rooftop_df = pd.DataFrame() + df = pd.read_csv('Data/Rooftop Potential.csv') + Countries = df['Country'] + Population = df['Population'] + Household_size = df['Household size'] + solar_radiation = df['Potential of Av.PV gen (GWh/MW/year)'] + number_of_homes = available_buildings*Population/Household_size # only those homes with rooftop PV potential + number_of_homes = number_of_homes.round(0) + rooftop_capacity_MW = number_of_homes * PV_size/1000 + rooftop_capacity_MW = rooftop_capacity_MW.round(1) + rooftop_PV_generation_GWh = rooftop_capacity_MW * solar_radiation + rooftop_PV_generation_GWh = rooftop_PV_generation_GWh.astype(float) + rooftop_PV_generation_GWh = rooftop_PV_generation_GWh.round(decimals=1) + + rooftop_df['Generation_GWh'] = rooftop_PV_generation_GWh + rooftop_df['Country'] = Countries + rooftop_df['Capacity_MW'] = rooftop_capacity_MW + rooftop_df['avaialble_homes'] = number_of_homes + rooftop_df['Household_size'] = Household_size + rooftop_df['Population'] = Population + + + rooftop_df.to_csv('rooftop_Pv_potential.csv') + + return rooftop_df diff --git a/index.py b/index.py index 7e51ffa..bf4e6f4 100644 --- a/index.py +++ b/index.py @@ -7,6 +7,8 @@ import callbacks_sankey import callbacks_FinancialFlows import dash_auth +import warnings +warnings.filterwarnings('ignore') # VALID_USERNAME_PASSWORD_PAIRS = { # 'hello': 'world' diff --git a/test.py b/test.py new file mode 100644 index 0000000..4e379ac --- /dev/null +++ b/test.py @@ -0,0 +1,13 @@ +import pandas as pd +from EnergyFlows import Country_List +wolrd_per_capita_use = pd.read_csv('Data/worldinData/per-capita-energy-use.csv') +wolrd_per_capita_use = wolrd_per_capita_use.sort_values('Year', ascending=False).drop_duplicates(['Entity']) +wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'] = wolrd_per_capita_use[ + 'Primary energy consumption per capita (kWh/person)'] # kWh/capita +wolrd_average_per_capita_use = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].mean() +wolrd_median_per_capita_use = wolrd_per_capita_use['Primary energy consumption per capita (kWh/person)'].median() +df_pop = pd.read_csv('Data/Economic Indicators.csv') +df_pop.rename(columns={'Country': 'Entity'}, inplace=True) + +df_pop['average_scenario_demand_GWh'] = 0.8 * df_pop["Population"] * wolrd_average_per_capita_use/1000000 #GWh/year +print(df_pop[df_pop["Entity"]=="Samoa"]['Population'].values[0]) \ No newline at end of file