Skip to content

Commit 7b4fae3

Browse files
authored
Merge pull request #27 from KTH-dESA/temporal_clust
Temporal clust
2 parents 36be570 + a3f9bac commit 7b4fae3

12 files changed

+523
-693
lines changed

src/Benin_run/build_osemosysdatafiles.py

Lines changed: 106 additions & 329 deletions
Large diffs are not rendered by default.

src/config/Beninnominal_parameters.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name,group,indexes,min_value_base_year,max_value_base_year,min_value_end_year,max_value_end_year,dist,interpolation_index,action,floor
22
Spatial,Spatial resolution,GLOBAL,1,1230,1,1230,unif,None,fixed,Y
33
DiscountRate,Discount Rate,GLOBAL,0.08,0.15,0.08,0.15,unif,None,fixed,N
4-
Dailytemporalresolution,Temporal resolution,GLOBAL,1,24,1,24,unif,None,fixed,Y
4+
Dailytemporalresolution,Temporal resolution,GLOBAL,2,12,2,12,unif,None,fixed,Y
55
CapitalCost_PV,Capital Cost PV,SOPV,2743.333,2743.333,670.7297516,1650.927983,unif,None,fixed,Y
66
CapitalCost_Battery_kWh,CapitalCost Battery kWh,battery,654.5783917,654.5783917,213.7218153,339.3920417,unif,None,fixed,Y
77
CapitalCost_Wind,Capital Cost Wind,WI,1405,1405,589,913,unif,YEAR,interpolate,N
88
CapitalCost_transm,CapitalCost transmission lines,Transmission,2,4,2,4,unif,None,fixed,N
99
CapitalCost_distribution,Capital Cost distribution lines,Distribution,10000,28000,10000,28000,unif,None,fixed,N
10-
CapacityFactor_error,Capacity Factor error,SOPV,-0.05,0.05,-0.05,0.05,unif,None,fixed,N
10+
CapacityFactor_error,Capacity Factor error,SOPV,-0.03,0.03,-0.03,0.03,unif,None,fixed,N
1111
Demand,Demand,GLOBAL,4564000,4564000,10217431.38,47420554.72,unif,None,fixed,Y
1212
FuelpriceNG,Fuel price natural gas,Natural gas,9,9,4,8,unif,YEAR,interpolate,N
1313
FuelpriceCRUDEOIL,Fuel price crude oil,Oil,17.20123217,17.20123217,7.354149984,22.06244995,unif,None,fixed,Y

src/config/Beninparameters.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name,group,indexes,min_value_base_year,max_value_base_year,min_value_end_year,max_value_end_year,dist,interpolation_index,action,floor
22
Spatial,Spatial resolution,GLOBAL,1,100,1,100,unif,None,fixed,Y
33
DiscountRate,Discount Rate,GLOBAL,0.07,0.2,0.07,0.2,unif,None,fixed,N
4-
Dailytemporalresolution,Temporal resolution,GLOBAL,1,24,1,24,unif,None,fixed,Y
4+
Dailytemporalresolution,Temporal resolution,GLOBAL,2,12,2,12,unif,None,fixed,Y
55
CapitalCost_PV,Capital Cost PV,SOPV,1,4,1,4,unif,None,fixed,Y
66
CapitalCost_Battery_kWh,CapitalCost Battery kWh,battery,1,4,1,4,unif,None,fixed,Y
77
CapitalCost_Wind,Capital Cost Wind,WI,1405,1405,589,913,unif,YEAR,interpolate,N
88
CapitalCost_transm,CapitalCost transmission lines,Transmission,2,4,2,4,unif,None,fixed,N
99
CapitalCost_distribution,Capital Cost distribution lines,Distribution,17448,35448,17448,35448,unif,None,fixed,N
10-
CapacityFactor_error,Capacity Factor error,SOPV,-0.05,0.05,-0.05,0.05,unif,None,fixed,N
10+
CapacityFactor_error,Capacity Factor error,SOPV,-0.03,0.03,-0.03,0.03,unif,None,fixed,N
1111
Demand,Demand,GLOBAL,1,4,1,4,unif,None,fixed,Y
1212
FuelpriceNG,Fuel price natural gas,Natural gas,9,9,4,8,unif,YEAR,interpolate,N
1313
FuelpriceCRUDEOIL,Fuel price crude oil,Oil,1,4,1,4,unif,None,fixed,Y

src/config/Kenyanominal_parameters.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name,group,indexes,min_value_base_year,max_value_base_year,min_value_end_year,max_value_end_year,dist,interpolation_index,action,floor
22
Spatial,Spatial resolution,GLOBAL,1,5800,1,5800,unif,None,fixed,Y
33
DiscountRate,Discount Rate,GLOBAL,0.08,0.15,0.08,0.15,unif,None,fixed,N
4-
Dailytemporalresolution,Temporal resolution,GLOBAL,1,24,1,24,unif,None,fixed,Y
4+
Dailytemporalresolution,Temporal resolution,GLOBAL,2,12,2,12,unif,None,fixed,Y
55
CapitalCost_PV,Capital Cost PV,SOPV,2743.333,2743.333,670.7297516,1650.927983,unif,None,fixed,Y
66
CapitalCost_Battery_kWh,CapitalCost Battery kWh,battery,654.5783917,654.5783917,213.7218153,339.3920417,unif,None,fixed,Y
77
CapitalCost_Wind,Capital Cost Wind,WI,1405,1405,589,913,unif,YEAR,interpolate,N
88
CapitalCost_transm,CapitalCost transmission lines,Transmission,2,4,2,4,unif,None,fixed,N
99
CapitalCost_distribution,Capital Cost distribution lines,Distribution,10000,28000,10000,28000,unif,None,fixed,N
10-
CapacityFactor_error,Capacity Factor error,SOPV,-0.05,0.05,-0.05,0.05,unif,None,fixed,N
10+
CapacityFactor_error,Capacity Factor error,SOPV,-0.03,0.03,-0.03,0.03,unif,None,fixed,N
1111
Demand,Demand,GLOBAL,33557630.4,33557630.4,83417746.52,196572113.6,unif,None,fixed,Y
1212
FuelpriceNG,Fuel price natural gas,Natural gas,9,9,4,8,unif,YEAR,interpolate,N
1313
FuelpriceCRUDEOIL,Fuel price crude oil,Oil,17.20123217,17.20123217,7.354149984,22.06244995,unif,None,fixed,Y

src/config/Kenyaparameters.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name,group,indexes,min_value_base_year,max_value_base_year,min_value_end_year,max_value_end_year,dist,interpolation_index,action,floor
22
Spatial,Spatial resolution,GLOBAL,1,100,1,100,unif,None,fixed,Y
33
DiscountRate,Discount Rate,GLOBAL,0.08,0.21,0.08,0.21,unif,None,fixed,N
4-
Dailytemporalresolution,Temporal resolution,GLOBAL,1,24,1,24,unif,None,fixed,Y
4+
Dailytemporalresolution,Temporal resolution,GLOBAL,2,12,2,12,unif,None,fixed,Y
55
CapitalCost_PV,Capital Cost PV,SOPV,1,4,1,4,unif,None,fixed,Y
66
CapitalCost_Battery_kWh,CapitalCost Battery kWh,battery,1,4,1,4,unif,None,fixed,Y
77
CapitalCost_Wind,Capital Cost Wind,WI,1405,1405,589,913,unif,YEAR,interpolate,N
88
CapitalCost_transm,CapitalCost transmission lines,Transmission,2,4,2,4,unif,None,fixed,N
99
CapitalCost_distribution,Capital Cost distribution lines,Distribution,15645,33645,15645,33645,unif,None,fixed,N
10-
CapacityFactor_error,Capacity Factor error,SOPV,-0.05,0.05,-0.05,0.05,unif,None,fixed,N
10+
CapacityFactor_error,Capacity Factor error,SOPV,-0.03,0.03,-0.03,0.03,unif,None,fixed,N
1111
Demand,Demand,GLOBAL,1,4,1,4,unif,None,fixed,Y
1212
FuelpriceNG,Fuel price natural gas,Natural gas,9,9,4,8,unif,YEAR,interpolate,N
1313
FuelpriceCRUDEOIL,Fuel price crude oil,Oil,1,4,1,4,unif,None,fixed,Y

src/config/config_input.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ seasonOctMarch = 0
1818
basetopeak = 1.4
1919
Kenya_PVshare_baseyear = 0.1
2020
Benin_PVshare_baseyear = 0.2
21+
typicalperiods = 2
2122
[inputfiles]
2223
Benincountry = Benin
2324
Kenyacountry = Kenya

src/environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies:
1616
- seaborn>=0.11.2
1717
- snakemake-minimal>=5.19.2
1818
- pytest
19+
- tsam
20+
- pulp
1921
- pip:
2022
- numpy>=1.21.6
2123
- sklearn>=0.0

src/modelgenerator/Build_csv_files.py

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ def battery_to_pv(loadprofile, capacityfactor_pv, efficiency_discharge, efficien
2626
"""This function re-distributes the load based on the load and capacity factor from renewable ninja
2727
"""
2828

29-
def calculate_average(data, startdate, enddate):
29+
def extract_one_month(data, startdate, enddate):
3030
mask = (data.index > startdate) & (data.index <= enddate)
3131
thisMonthOnly = data.loc[mask]
3232
return (thisMonthOnly)
3333

34-
3534

3635
def indexfix(df_path):
37-
df = pd.read_csv(df_path).dropna()
36+
df = pd.read_csv(df_path)
3837
df_copy = df.copy()
3938
df_copy_datetime = pd.to_datetime(df_copy['adjtime'], errors='coerce', format='%Y/%m/%d %H:%M')
4039
df_copy.index = df_copy_datetime
@@ -45,8 +44,8 @@ def indexfix(df_path):
4544
load = indexfix(loadprofile)
4645
df = pd.read_csv(locations, index_col=0, header=0)
4746

48-
PV_range = calculate_average(capacityf_solar, startDate, endDate)
49-
load_range =calculate_average(load, startDate_load, endDate_load)
47+
PV_range = extract_one_month(capacityf_solar, startDate, endDate)
48+
load_range =extract_one_month(load, startDate_load, endDate_load)
5049

5150
#normalise data
5251
def reduceload_data(data):
@@ -80,30 +79,30 @@ def reduceload_data(data):
8079

8180
df_PV_battery_size.to_csv(tofilePV)
8281

83-
def annualload(minuteload, topath, nr_timeslice):
82+
def annualload(minuteload, topath):
8483
minutedf = pd.read_csv(minuteload)
8584
minutedf['Datetime'] = pd.to_datetime('1900-01-01 ' + minutedf['Minute'])
8685
minutedf.set_index('Datetime', inplace=True)
87-
length = str(1440/nr_timeslice)+'min'
86+
#length = str(1440/nr_timeslice)+'min'
8887

89-
minutedf_group = minutedf.groupby([pd.Grouper(freq=length)]).mean().reset_index()
88+
minutedf_group = minutedf.groupby([pd.Grouper(freq='H')]).mean().reset_index()
9089
minutedf_group.set_index('Datetime', inplace=True)
9190

92-
hours = []
93-
for i in range(0,24):
94-
fromDate = pd.to_datetime(f'1900-01-01 {i}:00')
95-
toDate = fromDate + timedelta(hours=1)
91+
# hours = []
92+
# for i in range(0,24):
93+
# fromDate = pd.to_datetime(f'1900-01-01 {i}:00')
94+
# toDate = fromDate + timedelta(hours=1)
9695

97-
result = minutedf_group.loc[fromDate:toDate]
98-
if (result.values.size == 0):
99-
value = hours[i-1]
100-
else:
101-
value = result.values[0][0]
96+
# result = minutedf_group.loc[fromDate:toDate]
97+
# if (result.values.size == 0):
98+
# value = hours[i-1]
99+
# else:
100+
# value = result.values[0][0]
102101

103-
hours.append(value)
104-
rural_dataframe = pd.DataFrame(hours)
102+
# hours.append(value)
103+
# rural_dataframe = pd.DataFrame(hours)
105104

106-
s = rural_dataframe.squeeze()
105+
s = minutedf_group.squeeze()
107106
fullyearhours = pd.DataFrame(np.tile(s, 365), columns = ['Load'])
108107
# create a new DataFrame with a datetime index that spans the entire year
109108
start_date = pd.to_datetime('1900-01-01')
@@ -115,21 +114,7 @@ def annualload(minuteload, topath, nr_timeslice):
115114
fullyearhours['adjtime'] = fullyearhours.index
116115

117116
fullyearhours.to_csv(topath)
118-
return topath
119-
120-
def highprofile_aggre(hourlyprofile, topath, nr_timeslice):
121-
hourlydf = pd.read_csv(hourlyprofile)
122-
hourlydf['adjtime'] = pd.to_datetime(hourlydf['adjtime'])
123-
hourlydf.set_index('adjtime', inplace=True)
124-
length = str(1440/nr_timeslice)+'min'
125-
126-
hourlydf_group = hourlydf.groupby([pd.Grouper(freq=length)]).mean().reset_index()
127-
hourlydf_group.set_index('adjtime', inplace=True)
128-
129-
hourly_data = hourlydf_group.resample('H').ffill()
130-
131-
hourly_data.to_csv(topath)
132-
return topath
117+
return fullyearhours, topath
133118

134119
def renewableninja(path, dest, spatial, CapacityFactor_adj):
135120
"""

src/modelgenerator/Distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def peakdemand_csv(demand_csv, specifieddemand,capacitytoactivity, yearsplit_csv
225225

226226
TRLV_TRLVM = pd.concat([peakdemand_divided_km_cleaned, peakdemandLVM_divided_km_cleaned])
227227

228-
TRLV_TRLVM.to_csv(os.path.join(tofolder,'%i_%i_%ipeakdemand.csv') %(spatail, demand_scneario, temporal_id))
228+
TRLV_TRLVM.to_csv(os.path.join(tofolder,'%i_%i_%ipeakdemand.csv') %(spatail, int(demand_scneario), temporal_id))
229229

230230
def distribution_elec_startyear(demand, capacitytoactivity, distrlosses,basetopeak, years, savepath, PVshare_baseyear, PV_capacityfactor):
231231
demand_df =pd.read_csv(demand)

src/modelgenerator/renewable_ninja_download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def adjust_timezone(path, time_zone_offset):
239239
if os.path.isfile(final_path):
240240
print('File already exists, skipping calculations.')
241241
else:
242-
df.to_csv(final_path)
242+
df.to_csv(final_path, index=False)
243243
return final_path
244244

245245
def uncertainty_capacityfactor(path, CapacityFactor_adj):
@@ -264,4 +264,4 @@ def reduce_num(x):
264264
if os.path.isfile(final_path):
265265
print('File already exists, skipping calculations.')
266266
else:
267-
adjusted_df.to_csv(final_path)
267+
adjusted_df.to_csv(final_path,index=False)

0 commit comments

Comments
 (0)