-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunProject.py
176 lines (126 loc) · 8.31 KB
/
runProject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 20 00:42:56 2019
@author: Mehmood Ali Khan
"""
import time
from DataPreprocessing import DataPreprocessing
from DataReader import DataReader
from LSTMModel import LSTMModel
if __name__=='__main__':
objReader = DataReader()
objDataPrep = DataPreprocessing()
#############################################################
## Data preprocessing, combining date and hour offset to creat date time column,
## combining observed wind power values with atomospheric data of wind farms
## uncomment the below code to check data preprocessing steps
"""
print("\nStarted reading wind farms Data csv files along with train.csv file....\n")
train, wf1, wf2, wf3, wf4, wf5 = objReader.readData()
print("Reading of All Wind Farms data files along with train.csv file completed..!\n")
print("Started data preparation of individual Wind Farms wf1, wf2, . . . wf5 ...\n")
objDataPrep = DataPreprocessing()
Wf1WithDatetime = objDataPrep.prepareWindFarmDateTimeColumn(wf1, 1)
print("Wind Farm--1 DataTime Column calculated using date & hour columns...\n")
Wf2WithDatetime = objDataPrep.prepareWindFarmDateTimeColumn(wf2, 2)
print("Wind Farm--2 DataTime Column calculated using date & hour columns...\n")
Wf3WithDatetime = objDataPrep.prepareWindFarmDateTimeColumn(wf3, 3)
print("Wind Farm--3 DataTime Column calculated using date & hour columns...\n")
Wf4WithDatetime = objDataPrep.prepareWindFarmDateTimeColumn(wf4, 4)
print("Wind Farm--4 DataTime Column calculated using date & hour columns...\n")
Wf5WithDatetime = objDataPrep.prepareWindFarmDateTimeColumn(wf5, 5)
print("Wind Farm--5 DataTime Column calculated using date & hour columns...\n")
del wf1, wf2, wf3, wf4, wf5
print('Reading Training Data file\n')
train = objReader.readTrainingData("train.csv")
print('Reading Wind Farm-01 Data')
wf1WithDateTime = objReader.readWindFarm("wf1_dateTime_col.csv")
print('Reading Wind Farm-02 Data')
wf2WithDateTime = objReader.readWindFarm("wf2_dateTime_col.csv")
print('Reading Wind Farm-03 Data')
wf3WithDateTime = objReader.readWindFarm("wf3_dateTime_col.csv")
print('Reading Wind Farm-04 Data')
wf4WithDateTime = objReader.readWindFarm("wf4_dateTime_col.csv")
print('Reading Wind Farm-05 Data')
wf5WithDateTime = objReader.readWindFarm("wf5_dateTime_col.csv")
print("Preparing Wind Farm-01 Data with Power Values from training file Data")
wf1WithPowerVals = objDataPrep.combinePowerWithForecastVals(train, wf1WithDateTime, 1)
np.savetxt("WF1DataWithPowerVals.csv",wf1WithPowerVals,fmt='%s,%s,%s,%s,%s,%s')
print("Preparing Wind Farm-02 Data with Power Values from training file Data")
wf2WithPowerVals = objDataPrep.combinePowerWithForecastVals(train, wf2WithDateTime, 2)
np.savetxt("WF2DataWithPowerVals.csv",wf2WithPowerVals,fmt='%s,%s,%s,%s,%s,%s')
print("Preparing Wind Farm-03 Data with Power Values from training file Data")
wf3WithPowerVals = objDataPrep.combinePowerWithForecastVals(train, wf3WithDateTime, 3)
np.savetxt("WF3DataWithPowerVals.csv",wf3WithPowerVals,fmt='%s,%s,%s,%s,%s,%s')
print("Preparing Wind Farm-04 Data with Power Values from training file Data")
wf4WithPowerVals = objDataPrep.combinePowerWithForecastVals(train, wf4WithDateTime, 4)
np.savetxt("WF4DataWithPowerVals.csv",wf4WithPowerVals,fmt='%s,%s,%s,%s,%s,%s')
print("Preparing Wind Farm-05 Data with Power Values from training file Data")
wf5WithPowerVals = objDataPrep.combinePowerWithForecastVals(train, wf5WithDateTime, 5)
np.savetxt("WF5DataWithPowerVals.csv",wf5WithPowerVals,fmt='%s,%s,%s,%s,%s,%s')
"""
objLSTM = LSTMModel()
Windfarm1, Windfarm2, Windfarm3, Windfarm4, Windfarm5 = \
objLSTM.getWindFarmData()
nepochs = 5
#Wind Farm 1 training and prediction
X_train, Y_train, X_test, Y_test, test, min_max_scaler = \
objLSTM.preProcessDataForLSTM(Windfarm1, 1, 'Wind Farm-1')
modelLSTMbi = objLSTM.build_model_LSTMBidirectional(X_train)
modelLSTMstacked = objLSTM.build_model_LSTMSStacked(X_train)
global_start_time = time.time()
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMbi, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-1')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-1', 'Bidirectional LSTM')
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMstacked, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-1')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-1', 'Stacked LSTM')
#Wind Farm 2 training and prediction
X_train, Y_train, X_test, Y_test, test, min_max_scaler = \
objLSTM.preProcessDataForLSTM(Windfarm2, 1, 'Wind Farm-2')
modelLSTMbi = objLSTM.build_model_LSTMBidirectional(X_train)
modelLSTMstacked = objLSTM.build_model_LSTMSStacked(X_train)
global_start_time = time.time()
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMbi, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-2')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-2', 'Bidirectional LSTM')
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMstacked, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-1')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-2', 'Stacked LSTM')
#Wind Farm 3 training and prediction
X_train, Y_train, X_test, Y_test, test, min_max_scaler = \
objLSTM.preProcessDataForLSTM(Windfarm3, 1, 'Wind Farm-3')
modelLSTMbi = objLSTM.build_model_LSTMBidirectional(X_train)
modelLSTMstacked = objLSTM.build_model_LSTMSStacked(X_train)
global_start_time = time.time()
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMbi, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-3')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-3', 'Bidirectional LSTM')
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMstacked, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-3')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-3', 'Stacked LSTM')
#Wind Farm 4 training and prediction
X_train, Y_train, X_test, Y_test, test, min_max_scaler = \
objLSTM.preProcessDataForLSTM(Windfarm4, 1, 'Wind Farm-4')
modelLSTMbi = objLSTM.build_model_LSTMBidirectional(X_train)
modelLSTMstacked = objLSTM.build_model_LSTMSStacked(X_train)
global_start_time = time.time()
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMbi, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-4')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-4', 'Bidirectional LSTM')
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMstacked, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-4')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-4', 'Stacked LSTM')
#Wind Farm 5 training and prediction
X_train, Y_train, X_test, Y_test, test, min_max_scaler = \
objLSTM.preProcessDataForLSTM(Windfarm5, 1, 'Wind Farm-5')
modelLSTMbi = objLSTM.build_model_LSTMBidirectional(X_train)
modelLSTMstacked = objLSTM.build_model_LSTMSStacked(X_train)
global_start_time = time.time()
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMbi, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-5')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-5', 'Bidirectional LSTM')
actualwf1, predictedwf1 = objLSTM.modelLSTMfit(modelLSTMstacked, X_train, Y_train,\
X_test, Y_test, nepochs, 'Wind Farm-5')
objLSTM.plotGraph(actualwf1, predictedwf1, 'Wind Farm-5', 'Stacked LSTM')