adaptions using query
This commit is contained in:
parent
c4fd099cc8
commit
ffef74e9c5
@ -43,9 +43,8 @@ electricity:
|
|||||||
# Solar: [solar]
|
# Solar: [solar]
|
||||||
|
|
||||||
conventional_carriers: [] # nuclear, oil, OCGT, CCGT, coal, lignite, geothermal, biomass]
|
conventional_carriers: [] # nuclear, oil, OCGT, CCGT, coal, lignite, geothermal, biomass]
|
||||||
my_carriers_for_countries: ['DE'] # will replace generators in Germany by those saved in resources/powerplants_DE.csv
|
custom_powerplants: replace #replace or add
|
||||||
my_carriers_switch: replace-selection #replace-all, replace-selection or add (replace whole country/replace carriertype within country/add and do not delete from original generators)
|
restrict_buildyear: 2015 #delete generators built after 2015
|
||||||
restrict_buildyear: 2050 #delete generators built in between x-2050
|
|
||||||
|
|
||||||
atlite:
|
atlite:
|
||||||
nprocesses: 4
|
nprocesses: 4
|
||||||
|
@ -18,30 +18,27 @@ def country_alpha_2(name):
|
|||||||
cntry = pyc.countries.get(official_name=name)
|
cntry = pyc.countries.get(official_name=name)
|
||||||
return cntry.alpha_2
|
return cntry.alpha_2
|
||||||
|
|
||||||
def add_my_carriers(ppl):
|
def add_custom_carriers(ppl):
|
||||||
switch = snakemake.config['electricity']['my_carriers_switch']
|
switch = snakemake.config['electricity']['custom_powerplants']
|
||||||
if switch == 'replace-all' or switch == 'replace-selection' or switch == 'add':
|
if switch not in ('replace', 'add'):
|
||||||
countries_dict = snakemake.config['countries_dict'] # dictionary, eg. GB: United Kindgom
|
logger.warning('custom_carriers is invalid keyword, try "replace" or "add"]. powerplants remain unchanged.')
|
||||||
for country in snakemake.config['electricity']['my_carriers_for_countries']:
|
|
||||||
dirname = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
|
|
||||||
add_ppls = pd.read_csv(dirname + "/resources/powerplants_" + country + ".csv", index_col=0)
|
|
||||||
if switch == 'replace-all' or switch == 'replace-selection':
|
|
||||||
to_drop = ppl[ppl.Country == countries_dict[country]]
|
|
||||||
if switch == 'replace-selection':
|
|
||||||
to_drop = to_drop[to_drop.Fueltype.isin(add_ppls.groupby('Fueltype').mean().index)]
|
|
||||||
ppl = ppl.drop(to_drop.index)
|
|
||||||
ppl = ppl.append(add_ppls, sort='False')
|
|
||||||
else:
|
|
||||||
logger.warning('my_carriers_switch is invalid keyword, try one of [add, replace-all, replace-selection]. powerplants remain unchanged.')
|
|
||||||
return ppl
|
return ppl
|
||||||
|
dirname = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
|
||||||
|
add_ppls = pd.read_csv(dirname + "/data/custom_powerplants.csv", index_col=0)
|
||||||
|
if switch == 'replace':
|
||||||
|
countries = add_ppls.Country.unique().tolist()
|
||||||
|
carriers = add_ppls.Fueltype.unique().tolist()
|
||||||
|
logger.info('replacing ' + str(carriers) + ' in ' + str(countries) + '...')
|
||||||
|
ppl.query('Fueltype != @carriers or Country != @countries',inplace=True)
|
||||||
|
logger.info('adding custom carriers...')
|
||||||
|
return ppl.append(add_ppls, sort='False')
|
||||||
|
|
||||||
def restrict_buildyear(ppl):
|
def restrict_buildyear(ppl):
|
||||||
year = snakemake.config['electricity']['restrict_buildyear']
|
year = snakemake.config['electricity']['restrict_buildyear']
|
||||||
search_pattern = [str(int(year)+x) for x in range(1,2050-int(year))]
|
|
||||||
logger.info('restricting build year of generators to ' + str(year) + '...')
|
logger.info('restricting build year of generators to ' + str(year) + '...')
|
||||||
for pattern in search_pattern: #do it in forloop+contains instead of map as YearCommissioned might have the weirdest formats
|
ppl.YearCommissioned = ppl.YearCommissioned.fillna(0).astype(int) #in case of bad arrangement
|
||||||
ppl = ppl[ppl['YearCommissioned'].str.contains(pattern) == False]
|
ppl.YearCommissioned = ppl.YearCommissioned.astype(int)
|
||||||
return ppl
|
ppl.query('YearCommissioned <= @year',inplace=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if 'snakemake' not in globals():
|
if 'snakemake' not in globals():
|
||||||
@ -63,8 +60,8 @@ if __name__ == "__main__":
|
|||||||
df.Fueltype.where(df.Fueltype != 'Natural Gas',
|
df.Fueltype.where(df.Fueltype != 'Natural Gas',
|
||||||
df.Technology.replace('Steam Turbine', 'OCGT').fillna('OCGT'))))
|
df.Technology.replace('Steam Turbine', 'OCGT').fillna('OCGT'))))
|
||||||
.pipe(ppm.utils.fill_geoposition))
|
.pipe(ppm.utils.fill_geoposition))
|
||||||
ppl = add_my_carriers(ppl) # add carriers from own powerplant files
|
ppl = add_custom_carriers(ppl) # add carriers from own powerplant files
|
||||||
ppl = restrict_buildyear(ppl)
|
restrict_buildyear(ppl)
|
||||||
|
|
||||||
# ppl.loc[(ppl.Fueltype == 'Other') & ppl.Technology.str.contains('CCGT'), 'Fueltype'] = 'CCGT'
|
# ppl.loc[(ppl.Fueltype == 'Other') & ppl.Technology.str.contains('CCGT'), 'Fueltype'] = 'CCGT'
|
||||||
# ppl.loc[(ppl.Fueltype == 'Other') & ppl.Technology.str.contains('Steam Turbine'), 'Fueltype'] = 'CCGT'
|
# ppl.loc[(ppl.Fueltype == 'Other') & ppl.Technology.str.contains('Steam Turbine'), 'Fueltype'] = 'CCGT'
|
||||||
|
Loading…
Reference in New Issue
Block a user