Merge branch 'master' into master

This commit is contained in:
martavp 2021-02-04 09:15:03 +01:00 committed by GitHub
commit b264f2947d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -62,7 +62,9 @@ if __name__ == "__main__":
with open('config.yaml', encoding='utf8') as f: with open('config.yaml', encoding='utf8') as f:
snakemake.config = yaml.safe_load(f) snakemake.config = yaml.safe_load(f)
# This is a hack, to be replaced once snakemake is unicode-conform # This is a hack, to be replaced once snakemake is unicode-conform
if 'Secondary Forestry residues sawdust' in snakemake.config['biomass']['classes']['solid biomass']: if 'Secondary Forestry residues sawdust' in snakemake.config['biomass']['classes']['solid biomass']:
snakemake.config['biomass']['classes']['solid biomass'].remove('Secondary Forestry residues sawdust') snakemake.config['biomass']['classes']['solid biomass'].remove('Secondary Forestry residues sawdust')
snakemake.config['biomass']['classes']['solid biomass'].append('Secondary Forestry residues sawdust') snakemake.config['biomass']['classes']['solid biomass'].append('Secondary Forestry residues sawdust')

View File

@ -48,13 +48,16 @@ override_component_attrs["Store"].loc["build_year"] = ["integer","year",np.nan,"
override_component_attrs["Store"].loc["lifetime"] = ["float","years",np.nan,"lifetime","Input (optional)"] override_component_attrs["Store"].loc["lifetime"] = ["float","years",np.nan,"lifetime","Input (optional)"]
def co2_emissions_year(cts, opts, year): def co2_emissions_year(cts, opts, year):
""" """
calculate co2 emissions in one specific year (e.g. 1990 or 2018). calculate co2 emissions in one specific year (e.g. 1990 or 2018).
""" """
eea_co2 = build_eea_co2(year) eea_co2 = build_eea_co2(year)
#TODO: read Eurostat data from year>2014, this only affects the estimation of #TODO: read Eurostat data from year>2014, this only affects the estimation of
# CO2 emissions for "BA","RS","AL","ME","MK" # CO2 emissions for "BA","RS","AL","ME","MK"
if year > 2014: if year > 2014:
eurostat_co2 = build_eurostat_co2(year=2014) eurostat_co2 = build_eurostat_co2(year=2014)
@ -63,6 +66,7 @@ def co2_emissions_year(cts, opts, year):
co2_totals=build_co2_totals(eea_co2, eurostat_co2, year) co2_totals=build_co2_totals(eea_co2, eurostat_co2, year)
co2_emissions = co2_totals.loc[cts, "electricity"].sum() co2_emissions = co2_totals.loc[cts, "electricity"].sum()
if "T" in opts: if "T" in opts:
@ -77,6 +81,7 @@ def co2_emissions_year(cts, opts, year):
return co2_emissions return co2_emissions
def build_carbon_budget(o): def build_carbon_budget(o):
#distribute carbon budget following beta or exponential transition path #distribute carbon budget following beta or exponential transition path
if "be" in o: if "be" in o:
@ -118,12 +123,14 @@ def build_carbon_budget(o):
m=(1+np.sqrt(1+r*T))/T m=(1+np.sqrt(1+r*T))/T
CO2_CAP[o] = [(e_0/e_1990)*(1+(m+r)*(t-t_0))*np.exp(-m*(t-t_0)) for t in planning_horizons] CO2_CAP[o] = [(e_0/e_1990)*(1+(m+r)*(t-t_0))*np.exp(-m*(t-t_0)) for t in planning_horizons]
CO2_CAP.to_csv(path_cb + 'carbon_budget_distribution.csv', sep=',', CO2_CAP.to_csv(path_cb + 'carbon_budget_distribution.csv', sep=',',
line_terminator='\n', float_format='%.3f') line_terminator='\n', float_format='%.3f')
countries=pd.Series(data=cts) countries=pd.Series(data=cts)
countries.to_csv(path_cb + 'countries.csv', sep=',', countries.to_csv(path_cb + 'countries.csv', sep=',',
line_terminator='\n', float_format='%.3f') line_terminator='\n', float_format='%.3f')
def add_lifetime_wind_solar(n): def add_lifetime_wind_solar(n):
""" """
Add lifetime for solar and wind generators Add lifetime for solar and wind generators
@ -1859,6 +1866,7 @@ if __name__ == "__main__":
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='2020',
sector_opts='120H-T-H-B-I-onwind+p3-dist1-cb48be3'), sector_opts='120H-T-H-B-I-onwind+p3-dist1-cb48be3'),
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',
@ -1898,6 +1906,7 @@ if __name__ == "__main__":
floor_area = "resources/floor_area_{network}_s{simpl}_{clusters}.csv" floor_area = "resources/floor_area_{network}_s{simpl}_{clusters}.csv"
), ),
output=['results/version-cb48be3/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc'] output=['results/version-cb48be3/prenetworks/{network}_s{simpl}_{clusters}_lv{lv}__{sector_opts}_{planning_horizons}.nc']
) )
import yaml import yaml
with open('config.yaml', encoding='utf8') as f: with open('config.yaml', encoding='utf8') as f:
@ -2002,6 +2011,7 @@ if __name__ == "__main__":
print("CO2 limit set to",limit) print("CO2 limit set to",limit)
for o in opts: for o in opts:
if "cb" in o: if "cb" in o:
path_cb = snakemake.config['results_dir'] + snakemake.config['run'] + '/csvs/' path_cb = snakemake.config['results_dir'] + snakemake.config['run'] + '/csvs/'
if not os.path.exists(path_cb): if not os.path.exists(path_cb):
@ -2015,6 +2025,7 @@ if __name__ == "__main__":
limit=CO2_CAP.loc[investment_year] limit=CO2_CAP.loc[investment_year]
print("overriding CO2 limit with scenario limit",limit) print("overriding CO2 limit with scenario limit",limit)
for o in opts: for o in opts:
if "Co2L" in o: if "Co2L" in o:
limit = o[o.find("Co2L")+4:] limit = o[o.find("Co2L")+4:]
@ -2025,6 +2036,7 @@ if __name__ == "__main__":
add_co2limit(n, Nyears, limit) add_co2limit(n, Nyears, limit)
for o in opts: for o in opts:
if o[:10] == 'linemaxext': if o[:10] == 'linemaxext':
maxext = float(o[10:])*1e3 maxext = float(o[10:])*1e3
print("limiting new HVAC and HVDC extensions to",maxext,"MW") print("limiting new HVAC and HVDC extensions to",maxext,"MW")
@ -2035,7 +2047,6 @@ if __name__ == "__main__":
if snakemake.config["sector"]['electricity_distribution_grid']: if snakemake.config["sector"]['electricity_distribution_grid']:
insert_electricity_distribution_grid(n) insert_electricity_distribution_grid(n)
for o in opts: for o in opts:
if "+" in o: if "+" in o:
oo = o.split("+") oo = o.split("+")
@ -2060,6 +2071,7 @@ if __name__ == "__main__":
c.df.loc[sel,attr] *= factor c.df.loc[sel,attr] *= factor
print("changing", attr ,"for",carrier,"by factor",factor) print("changing", attr ,"for",carrier,"by factor",factor)
if snakemake.config["sector"]['gas_distribution_grid']: if snakemake.config["sector"]['gas_distribution_grid']:
insert_gas_distribution_costs(n) insert_gas_distribution_costs(n)
if snakemake.config["sector"]['electricity_grid_connection']: if snakemake.config["sector"]['electricity_grid_connection']: