Merge pull request #80 from PyPSA/retro-new-pandas

Retro new pandas
This commit is contained in:
Tom Brown 2020-12-04 16:17:10 +01:00 committed by GitHub
commit 21c4fd4761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 53 deletions

View File

@ -17,3 +17,10 @@ IRENA existing VRE capacities,existing_infrastructure/{solar|onwind|offwind}_cap
USGS ammonia production,myb1-2017-nitro.xls,unknown,https://www.usgs.gov/centers/nmic/nitrogen-statistics-and-information USGS ammonia production,myb1-2017-nitro.xls,unknown,https://www.usgs.gov/centers/nmic/nitrogen-statistics-and-information
hydrogen salt cavern potentials,hydrogen_salt_cavern_potentials.csv,CC BY 4.0,https://doi.org/10.1016/j.ijhydene.2019.12.161 hydrogen salt cavern potentials,hydrogen_salt_cavern_potentials.csv,CC BY 4.0,https://doi.org/10.1016/j.ijhydene.2019.12.161
hotmaps industrial site database,Industrial_Database.csv,CC BY 4.0,https://gitlab.com/hotmaps/industrial_sites/industrial_sites_Industrial_Database hotmaps industrial site database,Industrial_Database.csv,CC BY 4.0,https://gitlab.com/hotmaps/industrial_sites/industrial_sites_Industrial_Database
Hotmaps building stock data,data_building_stock.csv,CC BY 4.0,https://gitlab.com/hotmaps/building-stock
U-values Poland,u_values_poland.csv,unknown,https://data.europa.eu/euodp/de/data/dataset/building-stock-observatory
Floor area missing in hotmaps building stock data,floor_area_missing.csv,unknown,https://data.europa.eu/euodp/de/data/dataset/building-stock-observatory
Comparative level investment,comparative_level_investment.csv,Eurostat,https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Comparative_price_levels_for_investment
Electricity taxes,electricity_taxes_eu.csv,Eurostat,https://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=nrg_pc_204&lang=en
Average surface components,average_surface_components.csv,unknown,http://webtool.building-typology.eu/#bm
Retrofitting thermal envelope costs for Germany,retro_cost_germany.csv,unkown,https://www.iwu.de/forschung/handlungslogiken/kosten-energierelevanter-bau-und-anlagenteile-bei-modernisierung/

1 description file/folder licence source
17 USGS ammonia production myb1-2017-nitro.xls unknown https://www.usgs.gov/centers/nmic/nitrogen-statistics-and-information
18 hydrogen salt cavern potentials hydrogen_salt_cavern_potentials.csv CC BY 4.0 https://doi.org/10.1016/j.ijhydene.2019.12.161
19 hotmaps industrial site database Industrial_Database.csv CC BY 4.0 https://gitlab.com/hotmaps/industrial_sites/industrial_sites_Industrial_Database
20 Hotmaps building stock data data_building_stock.csv CC BY 4.0 https://gitlab.com/hotmaps/building-stock
21 U-values Poland u_values_poland.csv unknown https://data.europa.eu/euodp/de/data/dataset/building-stock-observatory
22 Floor area missing in hotmaps building stock data floor_area_missing.csv unknown https://data.europa.eu/euodp/de/data/dataset/building-stock-observatory
23 Comparative level investment comparative_level_investment.csv Eurostat https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Comparative_price_levels_for_investment
24 Electricity taxes electricity_taxes_eu.csv Eurostat https://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=nrg_pc_204&lang=en
25 Average surface components average_surface_components.csv unknown http://webtool.building-typology.eu/#bm
26 Retrofitting thermal envelope costs for Germany retro_cost_germany.csv unkown https://www.iwu.de/forschung/handlungslogiken/kosten-energierelevanter-bau-und-anlagenteile-bei-modernisierung/

View File

@ -23,7 +23,6 @@ Structure:
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
pd.options.mode.chained_assignment = None
#%% ************ FUCNTIONS *************************************************** #%% ************ FUCNTIONS ***************************************************
@ -175,9 +174,9 @@ def prepare_building_stock_data():
area = building_data[(building_data.type == 'Heated area [Mm²]') & area = building_data[(building_data.type == 'Heated area [Mm²]') &
(building_data.subsector != "Total")] (building_data.subsector != "Total")]
area_tot = area.groupby(["country", "sector"]).sum() area_tot = area.groupby(["country", "sector"]).sum()
area["weight"] = area.apply(lambda x: x.value / area = pd.concat([area, area.apply(lambda x: x.value /
area_tot.value.loc[(x.country, x.sector)], area_tot.value.loc[(x.country, x.sector)],
axis=1) axis=1).rename("weight")],axis=1)
area = area.groupby(['country', 'sector', 'subsector', 'bage']).sum() area = area.groupby(['country', 'sector', 'subsector', 'bage']).sum()
area_tot.rename(index=country_iso_dic, inplace=True) area_tot.rename(index=country_iso_dic, inplace=True)
@ -192,9 +191,9 @@ def prepare_building_stock_data():
pop_layout["ct"] = pop_layout.index.str[:2] pop_layout["ct"] = pop_layout.index.str[:2]
ct_total = pop_layout.total.groupby(pop_layout["ct"]).sum() ct_total = pop_layout.total.groupby(pop_layout["ct"]).sum()
area_per_pop = area_tot.unstack().apply(lambda x: x / ct_total[x.index]) area_per_pop = area_tot.unstack().reindex(index=ct_total.index).apply(lambda x: x / ct_total[x.index])
missing_area_ct = ct_total.index.difference(area_tot.index.levels[0]) missing_area_ct = ct_total.index.difference(area_tot.index.levels[0])
for ct in missing_area_ct: for ct in (missing_area_ct & ct_total.index):
averaged_data = pd.DataFrame( averaged_data = pd.DataFrame(
area_per_pop.value.reindex(map_for_missings[ct]).mean() area_per_pop.value.reindex(map_for_missings[ct]).mean()
* ct_total[ct], * ct_total[ct],
@ -233,7 +232,7 @@ def prepare_building_stock_data():
# smallest possible today u values for windows 0.8 (passive house standard) # smallest possible today u values for windows 0.8 (passive house standard)
# maybe the u values for the glass and not the whole window including frame # maybe the u values for the glass and not the whole window including frame
# for those types assumed in the dataset # for those types assumed in the dataset
u_values[(u_values.type=="Windows") & (u_values.value<0.8)]["value"] = 0.8 u_values.loc[(u_values.type=="Windows") & (u_values.value<0.8), "value"] = 0.8
# drop unnecessary columns # drop unnecessary columns
u_values.drop(['topic', 'feature','detail', 'estimated','unit'], u_values.drop(['topic', 'feature','detail', 'estimated','unit'],
axis=1, inplace=True, errors="ignore") axis=1, inplace=True, errors="ignore")
@ -314,8 +313,12 @@ def calculate_cost_energy_curve(u_values, l_strength, l_weight, average_surface_
for l in l_strength: for l in l_strength:
u_values[l] = calculate_new_u(u_values, l, l_weight) u_values[l] = calculate_new_u(u_values, l, l_weight)
energy_saved[l] = calculate_dE(u_values, l, average_surface_w) energy_saved = pd.concat([energy_saved,
costs[l] = calculate_costs(u_values, l, cost_retro, average_surface) calculate_dE(u_values, l, average_surface_w).rename(l)],
axis=1)
costs = pd.concat([costs,
calculate_costs(u_values, l, cost_retro, average_surface).rename(l)],
axis=1)
# energy and costs per country, sector, subsector and year # energy and costs per country, sector, subsector and year
e_tot = energy_saved.groupby(['country', 'sector', 'subsector', 'bage']).sum() e_tot = energy_saved.groupby(['country', 'sector', 'subsector', 'bage']).sum()
@ -334,11 +337,13 @@ def calculate_cost_energy_curve(u_values, l_strength, l_weight, average_surface_
axis=1, keys=["dE", "cost"]) axis=1, keys=["dE", "cost"])
res.rename(index=country_iso_dic, inplace=True) res.rename(index=country_iso_dic, inplace=True)
res = res.loc[countries] res = res.reindex(index=countries, level=0)
# reset index because otherwise not considered countries still in index.levels[0]
res = res.reset_index().set_index(["country", "sector"])
# map missing countries # map missing countries
for ct in map_for_missings.keys(): for ct in pd.Index(map_for_missings.keys()) & countries:
averaged_data = pd.DataFrame(res.loc[map_for_missings[ct], :].mean(level=1)) averaged_data = res.reindex(index=map_for_missings[ct], level=0).mean(level=1)
index = pd.MultiIndex.from_product([[ct], averaged_data.index.to_list()]) index = pd.MultiIndex.from_product([[ct], averaged_data.index.to_list()])
averaged_data.index = index averaged_data.index = index
if ct not in res.index.levels[0]: if ct not in res.index.levels[0]:
@ -436,12 +441,14 @@ if __name__ == "__main__":
# for missing weighting of surfaces of building types assume MultiFamily houses # for missing weighting of surfaces of building types assume MultiFamily houses
u_values["assumed_subsector"] = u_values.subsector u_values["assumed_subsector"] = u_values.subsector
u_values.assumed_subsector[ u_values.loc[~u_values.subsector.isin(average_surface.index),
~u_values.subsector.isin(average_surface.index)] = 'Multifamily houses' "assumed_subsector"] = 'Multifamily houses'
dE_and_cost = calculate_cost_energy_curve(u_values, l_strength, l_weight, dE_and_cost = calculate_cost_energy_curve(u_values, l_strength, l_weight,
average_surface_w, average_surface, area, average_surface_w, average_surface, area,
country_iso_dic, countries) country_iso_dic, countries)
# reset index because otherwise not considered countries still in index.levels[0]
dE_and_cost = dE_and_cost.reset_index().set_index(["country", "sector"])
# weights costs after construction index # weights costs after construction index
if construction_index: if construction_index:

View File

@ -1820,52 +1820,52 @@ def get_parameter(item):
return item return item
#%%
if __name__ == "__main__": if __name__ == "__main__":
# Detect running outside of snakemake and mock snakemake for testing # Detect running outside of snakemake and mock snakemake for testing
if 'snakemake' not in globals(): if 'snakemake' not in globals():
from vresutils.snakemake import MockSnakemake from vresutils.snakemake import MockSnakemake
snakemake = MockSnakemake( snakemake = MockSnakemake(
wildcards=dict(network='elec', simpl='', clusters='37', lv='1.0', wildcards=dict(network='elec', simpl='', clusters='37', lv='1.0',
opts='', planning_horizons='2020', opts='', planning_horizons='2030', co2_budget_name="go",
sector_opts='Co2L0-168H-T-H-B-I-solar3-dist1'), sector_opts='Co2L0-120H-T-H-B-I-solar3-dist1'),
input=dict(network='../pypsa-eur/networks/{network}_s{simpl}_{clusters}_ec_lv{lv}_{opts}.nc', input=dict( network='../pypsa-eur/networks/{network}_s{simpl}_{clusters}_ec_lv{lv}_{opts}.nc',
energy_totals_name='resources/energy_totals.csv', energy_totals_name='resources/energy_totals.csv',
co2_totals_name='resources/co2_totals.csv', co2_totals_name='resources/co2_totals.csv',
transport_name='resources/transport_data.csv', transport_name='resources/transport_data.csv',
biomass_potentials='resources/biomass_potentials.csv', traffic_data = "data/emobility/",
biomass_transport='data/biomass/biomass_transport_costs.csv', biomass_potentials='resources/biomass_potentials.csv',
timezone_mappings='data/timezone_mappings.csv', timezone_mappings='data/timezone_mappings.csv',
heat_profile="data/heat_load_profile_BDEW.csv", heat_profile="data/heat_load_profile_BDEW.csv",
costs="../technology-data/outputs/costs_{planning_horizons}.csv", costs="../technology-data/outputs/costs_{planning_horizons}.csv",
h2_cavern = "data/hydrogen_salt_cavern_potentials.csv", h2_cavern = "data/hydrogen_salt_cavern_potentials.csv",
profile_offwind_ac="../pypsa-eur/resources/profile_offwind-ac.nc", profile_offwind_ac="../pypsa-eur/resources/profile_offwind-ac.nc",
profile_offwind_dc="../pypsa-eur/resources/profile_offwind-dc.nc", profile_offwind_dc="../pypsa-eur/resources/profile_offwind-dc.nc",
clustermaps='../pypsa-eur/resources/clustermaps_{network}_s{simpl}_{clusters}.h5', busmap_s="../pypsa-eur/resources/busmap_{network}_s{simpl}.csv",
clustered_pop_layout="resources/pop_layout_{network}_s{simpl}_{clusters}.csv", busmap="../pypsa-eur/resources/busmap_{network}_s{simpl}_{clusters}.csv",
simplified_pop_layout="resources/pop_layout_{network}_s{simpl}.csv", clustered_pop_layout="resources/pop_layout_{network}_s{simpl}_{clusters}.csv",
industrial_demand="resources/industrial_energy_demand_{network}_s{simpl}_{clusters}.csv", simplified_pop_layout="resources/pop_layout_{network}_s{simpl}.csv",
heat_demand_urban="resources/heat_demand_urban_{network}_s{simpl}_{clusters}.nc", industrial_demand="resources/industrial_energy_demand_{network}_s{simpl}_{clusters}.csv",
heat_demand_rural="resources/heat_demand_rural_{network}_s{simpl}_{clusters}.nc", heat_demand_urban="resources/heat_demand_urban_{network}_s{simpl}_{clusters}.nc",
heat_demand_total="resources/heat_demand_total_{network}_s{simpl}_{clusters}.nc", heat_demand_rural="resources/heat_demand_rural_{network}_s{simpl}_{clusters}.nc",
temp_soil_total="resources/temp_soil_total_{network}_s{simpl}_{clusters}.nc", heat_demand_total="resources/heat_demand_total_{network}_s{simpl}_{clusters}.nc",
temp_soil_rural="resources/temp_soil_rural_{network}_s{simpl}_{clusters}.nc", temp_soil_total="resources/temp_soil_total_{network}_s{simpl}_{clusters}.nc",
temp_soil_urban="resources/temp_soil_urban_{network}_s{simpl}_{clusters}.nc", temp_soil_rural="resources/temp_soil_rural_{network}_s{simpl}_{clusters}.nc",
temp_air_total="resources/temp_air_total_{network}_s{simpl}_{clusters}.nc", temp_soil_urban="resources/temp_soil_urban_{network}_s{simpl}_{clusters}.nc",
temp_air_rural="resources/temp_air_rural_{network}_s{simpl}_{clusters}.nc", temp_air_total="resources/temp_air_total_{network}_s{simpl}_{clusters}.nc",
temp_air_urban="resources/temp_air_urban_{network}_s{simpl}_{clusters}.nc", temp_air_rural="resources/temp_air_rural_{network}_s{simpl}_{clusters}.nc",
cop_soil_total="resources/cop_soil_total_{network}_s{simpl}_{clusters}.nc", temp_air_urban="resources/temp_air_urban_{network}_s{simpl}_{clusters}.nc",
cop_soil_rural="resources/cop_soil_rural_{network}_s{simpl}_{clusters}.nc", cop_soil_total="resources/cop_soil_total_{network}_s{simpl}_{clusters}.nc",
cop_soil_urban="resources/cop_soil_urban_{network}_s{simpl}_{clusters}.nc", cop_soil_rural="resources/cop_soil_rural_{network}_s{simpl}_{clusters}.nc",
cop_air_total="resources/cop_air_total_{network}_s{simpl}_{clusters}.nc", cop_soil_urban="resources/cop_soil_urban_{network}_s{simpl}_{clusters}.nc",
cop_air_rural="resources/cop_air_rural_{network}_s{simpl}_{clusters}.nc", cop_air_total="resources/cop_air_total_{network}_s{simpl}_{clusters}.nc",
cop_air_urban="resources/cop_air_urban_{network}_s{simpl}_{clusters}.nc", cop_air_rural="resources/cop_air_rural_{network}_s{simpl}_{clusters}.nc",
solar_thermal_total="resources/solar_thermal_total_{network}_s{simpl}_{clusters}.nc", cop_air_urban="resources/cop_air_urban_{network}_s{simpl}_{clusters}.nc",
solar_thermal_urban="resources/solar_thermal_urban_{network}_s{simpl}_{clusters}.nc", solar_thermal_total="resources/solar_thermal_total_{network}_s{simpl}_{clusters}.nc",
traffic_data = "data/emobility/", solar_thermal_urban="resources/solar_thermal_urban_{network}_s{simpl}_{clusters}.nc",
solar_thermal_rural="resources/solar_thermal_rural_{network}_s{simpl}_{clusters}.nc", solar_thermal_rural="resources/solar_thermal_rural_{network}_s{simpl}_{clusters}.nc",
retro_cost_energy = "resources/retro_cost_{network}_s{simpl}_{clusters}.csv", retro_cost_energy = "resources/retro_cost_{network}_s{simpl}_{clusters}.csv",
floor_area = "resources/floor_area_{network}_s{simpl}_{clusters}.csv" floor_area = "resources/floor_area_{network}_s{simpl}_{clusters}.csv"
), ),
output=['pypsa-eur-sec/results/test/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_{planning_horizons}.nc'] output=['pypsa-eur-sec/results/test/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{co2_budget_name}_{planning_horizons}.nc']
) )