Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Create_tariff_files/__init__.py
Empty file.
46 changes: 46 additions & 0 deletions Create_tariff_files/interpolate_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pandas as pd
import numpy as np
from scipy.interpolate import interp1d

dir2 = 'C:/Users/w47147/misc_code/RODeO-master/RODeO-master/Create_tariff_files/Data_files/'
dir1 = dir2 + "CSV_data/"

dataframe = pd.read_excel(dir1 + "GAMS_renewables.xlsx", skiprows = 1, sheet_name = 'Sheet1')
dataframe_energy_sales = pd.read_excel(dir1 + "GAMS_Energy_Sale.xlsx", skiprows = 1, sheet_name = 'Sheet1')

interval_length = 4
year_length = 8760

def interpolate_matrix(dataframe, year_length, interval_length, interpolation_type):
GAMS_num_rows = dataframe.shape[0]
output_df = pd.DataFrame()

# pre-check dataframe is already of desired row length; if yes simply return dataframe
if GAMS_num_rows == year_length * interval_length:
return dataframe

if interpolation_type == "linear":
# The ' + 1' is due to np.linspace including both upper and lower bounds in count of bins;
lower_inter_bound = min(dataframe["Interval"])
upper_inter_bound = max(dataframe["Interval"])
interpolate_hour_array = [round(x, 2) for x in np.linspace(lower_inter_bound, upper_inter_bound, GAMS_num_rows * interval_length + 1)]
output_df["Interval"] = interpolate_hour_array

# Create linear interpolation function. Add column to output data frame
for column in dataframe.columns:
if column not in ["Date", "Interval"]:
f = interp1d(dataframe["Interval"], dataframe[column]/max(dataframe[column]),kind = 'linear')
output_df[column] = f(interpolate_hour_array)


if interpolation_type == "repeat":
# iterate through all dataframe columns and repeat 'interval_length' times
for x in dataframe.columns:
output_df[x] = dataframe[x].repeat(interval_length)

return output_df




# print(interpolate_matrix(dataframe_energy_sales, year_length, interval_length, "repeat").loc[0:1])
Empty file added __init__.py
Empty file.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pandas
numpy
scipy
pytest
Binary file added test/GAMS_Energy_Sale.xlsx
Binary file not shown.
Binary file added test/GAMS_renewables.xlsx
Binary file not shown.
22 changes: 22 additions & 0 deletions test/interpolate_linear_testoutput_1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
,Interval,PV1,PV2
20,6.0,0.0,0.0
21,6.25,0.0,0.0
22,6.5,0.0,0.0
23,6.75,0.0,0.0
24,7.0,0.0,0.0
25,7.25,0.005184746619664406,0.005488941743218661
26,7.5,0.010369493239328812,0.010977883486437322
27,7.75,0.015554239858993218,0.016466825229655983
28,8.0,0.020738986478657625,0.021955766972874644
29,8.25,0.049644147481294476,0.047582460313061126
30,8.5,0.07854930848393132,0.0732091536532476
31,8.75,0.10745446948656817,0.09883584699343408
32,9.0,0.13635963048920502,0.12446254033362056
33,9.25,0.13795003844681872,0.13261203130275284
34,9.5,0.13954044640443242,0.14076152227188515
35,9.75,0.14113085436204612,0.14891101324101744
36,10.0,0.14272126231965981,0.15706050421014972
37,10.25,0.18556067399555487,0.2061623305400044
38,10.5,0.22840008567144995,0.2552641568698591
39,10.75,0.27123949734734504,0.30436598319971375
40,11.0,0.3140789090232401,0.35346780952956847
165 changes: 165 additions & 0 deletions test/interpolate_repeat_testoutput_1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
,Date,Interval,PV1,PV2
0,,1,0.0,0.0
0,,1,0.0,0.0
0,,1,0.0,0.0
0,,1,0.0,0.0
1,,2,0.0,0.0
1,,2,0.0,0.0
1,,2,0.0,0.0
1,,2,0.0,0.0
2,,3,0.0,0.0
2,,3,0.0,0.0
2,,3,0.0,0.0
2,,3,0.0,0.0
3,,4,0.0,0.0
3,,4,0.0,0.0
3,,4,0.0,0.0
3,,4,0.0,0.0
4,,5,0.0,0.0
4,,5,0.0,0.0
4,,5,0.0,0.0
4,,5,0.0,0.0
5,,6,0.0,0.0
5,,6,0.0,0.0
5,,6,0.0,0.0
5,,6,0.0,0.0
6,,7,0.0,0.0
6,,7,0.0,0.0
6,,7,0.0,0.0
6,,7,0.0,0.0
7,,8,11.8133,13.0713
7,,8,11.8133,13.0713
7,,8,11.8133,13.0713
7,,8,11.8133,13.0713
8,,9,77.6729,74.0984
8,,9,77.6729,74.0984
8,,9,77.6729,74.0984
8,,9,77.6729,74.0984
9,,10,81.2966,93.5055
9,,10,81.2966,93.5055
9,,10,81.2966,93.5055
9,,10,81.2966,93.5055
10,,11,178.905,210.436
10,,11,178.905,210.436
10,,11,178.905,210.436
10,,11,178.905,210.436
11,,12,106.609,109.389
11,,12,106.609,109.389
11,,12,106.609,109.389
11,,12,106.609,109.389
12,,13,62.1788,62.2835
12,,13,62.1788,62.2835
12,,13,62.1788,62.2835
12,,13,62.1788,62.2835
13,,14,53.338,61.5023
13,,14,53.338,61.5023
13,,14,53.338,61.5023
13,,14,53.338,61.5023
14,,15,11.7076,14.9477
14,,15,11.7076,14.9477
14,,15,11.7076,14.9477
14,,15,11.7076,14.9477
15,,16,7.82321,10.2814
15,,16,7.82321,10.2814
15,,16,7.82321,10.2814
15,,16,7.82321,10.2814
16,,17,1.45219,2.58744
16,,17,1.45219,2.58744
16,,17,1.45219,2.58744
16,,17,1.45219,2.58744
17,,18,0.0,0.0
17,,18,0.0,0.0
17,,18,0.0,0.0
17,,18,0.0,0.0
18,,19,0.0,0.0
18,,19,0.0,0.0
18,,19,0.0,0.0
18,,19,0.0,0.0
19,,20,0.0,0.0
19,,20,0.0,0.0
19,,20,0.0,0.0
19,,20,0.0,0.0
20,,21,0.0,0.0
20,,21,0.0,0.0
20,,21,0.0,0.0
20,,21,0.0,0.0
21,,22,0.0,0.0
21,,22,0.0,0.0
21,,22,0.0,0.0
21,,22,0.0,0.0
22,,23,0.0,0.0
22,,23,0.0,0.0
22,,23,0.0,0.0
22,,23,0.0,0.0
23,,24,0.0,0.0
23,,24,0.0,0.0
23,,24,0.0,0.0
23,,24,0.0,0.0
24,,25,0.0,0.0
24,,25,0.0,0.0
24,,25,0.0,0.0
24,,25,0.0,0.0
25,,26,0.0,0.0
25,,26,0.0,0.0
25,,26,0.0,0.0
25,,26,0.0,0.0
26,,27,0.0,0.0
26,,27,0.0,0.0
26,,27,0.0,0.0
26,,27,0.0,0.0
27,,28,0.0,0.0
27,,28,0.0,0.0
27,,28,0.0,0.0
27,,28,0.0,0.0
28,,29,0.0,0.0
28,,29,0.0,0.0
28,,29,0.0,0.0
28,,29,0.0,0.0
29,,30,0.0,0.0
29,,30,0.0,0.0
29,,30,0.0,0.0
29,,30,0.0,0.0
30,,31,0.0,0.0
30,,31,0.0,0.0
30,,31,0.0,0.0
30,,31,0.0,0.0
31,,32,72.3054,54.4181
31,,32,72.3054,54.4181
31,,32,72.3054,54.4181
31,,32,72.3054,54.4181
32,,33,305.638,218.257
32,,33,305.638,218.257
32,,33,305.638,218.257
32,,33,305.638,218.257
33,,34,25.0956,31.0493
33,,34,25.0956,31.0493
33,,34,25.0956,31.0493
33,,34,25.0956,31.0493
34,,35,79.9829,90.1767
34,,35,79.9829,90.1767
34,,35,79.9829,90.1767
34,,35,79.9829,90.1767
35,,36,27.7483,26.9279
35,,36,27.7483,26.9279
35,,36,27.7483,26.9279
35,,36,27.7483,26.9279
36,,37,10.7837,10.6404
36,,37,10.7837,10.6404
36,,37,10.7837,10.6404
36,,37,10.7837,10.6404
37,,38,350.313,414.932
37,,38,350.313,414.932
37,,38,350.313,414.932
37,,38,350.313,414.932
38,,39,247.912,230.612
38,,39,247.912,230.612
38,,39,247.912,230.612
38,,39,247.912,230.612
39,,40,275.871,200.199
39,,40,275.871,200.199
39,,40,275.871,200.199
39,,40,275.871,200.199
40,,41,51.2348,44.9344
40,,41,51.2348,44.9344
40,,41,51.2348,44.9344
40,,41,51.2348,44.9344
40 changes: 40 additions & 0 deletions test/test_rodeo_python_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pandas as pd
import numpy as np
from scipy.interpolate import interp1d
import sys
sys.path.append('..')
from Create_tariff_files.interpolate_matrix import *


def interpolate_linear():
dataframe_energy_sales = pd.read_excel("GAMS_renewables.xlsx", skiprows = 1, sheet_name = 'Sheet1')

return interpolate_matrix(dataframe, year_length, interval_length, "linear").loc[20:40]


def test_interpolate_linear():
input_df = interpolate_linear().round(3)
print(input_df)
test_df = pd.read_csv("interpolate_linear_testoutput_1.csv", index_col = 0).round(3)
for column in input_df:
assert input_df[column].to_list() == test_df[column].to_list()






def interpolate_repeat():
dataframe_energy_sales = pd.read_excel("GAMS_Energy_Sale.xlsx", skiprows = 1, sheet_name = 'Sheet1')

return interpolate_matrix(dataframe, year_length, interval_length, "repeat").loc[0:40]


def test_interpolate_repeat():
input_df = interpolate_repeat().round(3)
test_df = pd.read_csv("interpolate_repeat_testoutput_1.csv", index_col = 0).round(3)
for column in input_df:
if column == "Date":
continue
assert input_df[column].to_list() == test_df[column].to_list()