-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathget_week_data_for_scheduling.py
100 lines (87 loc) · 3.71 KB
/
get_week_data_for_scheduling.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
"""
Example to use ESIOS
Copyright 2016 Santiago Peñate Vera <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import datetime
import pickle
import pandas as pd
from matplotlib import pyplot as plt
from pyesios import ESIOS
plt.style.use("ggplot")
if __name__ == "__main__":
# Request arguments
# end_ = datetime.datetime.today()
# start_ = end_ - datetime.timedelta(days=7)
start_ = datetime.datetime(2016, 1, 1)
end_ = datetime.datetime(2017, 1, 1)
# The token is unique: You should ask for yours to:
# Consultas Sios <[email protected]>
token = "5c7f9ca844f598ab7b86bffcad08803f78e9fc5bf3036eef33b5888877a04e38"
esios = ESIOS(token)
# esios.save_indicators_table()
indicators_ = list()
# indicators_.append(677) # Precio Regulación Terciaria subir
# indicators_.append(676) # Precio Regulación Terciaria bajar
indicators_.append(634) # Precio Banda de regulación secundaria
indicators_.append(600) # Precio mercado SPOT Diario
# Requerimientos Banda de regulación secundaria a bajar
# indicators_.append(631)
# Requerimientos Banda de regulación secundaria a subir
# indicators_.append(630)
# indicators_.append(1293) # Demanda real
# indicators_.append(550) # Generación T.Real C.Combinado
# indicators_.append(547) # Generación T.Real carbón
# indicators_.append(1297) # Generación T.Real Cogeneración y resto
# indicators_.append(554) # Generación T.Real enlace balear
# indicators_.append(551) # Generación T.Real eólica
# indicators_.append(548) # Generación T.Real fuel-gas
# indicators_.append(546) # Generación T.Real hidráulica
# indicators_.append(553) # Generación T.Real intercambios
# indicators_.append(549) # Generación T.Real nuclear
# indicators_.append(10206) # Generación T.Real Solar
# indicators_.append(552) # Generación T.Real solar
# indicators_.append(1295) # Generación T.Real Solar fotovoltaica
# indicators_.append(1294) # Generación T.Real Solar térmica
# indicators_.append(1296) # Generación T.Real Térmica renovable
names = esios.get_names(indicators_)
df_list, names = esios.get_multiple_series(indicators_, start_, end_)
# save
file_handler = open(str(indicators_) + ".pkl", "wb")
pickle.dump([indicators_, df_list, names], file_handler)
file_handler.close()
# merge the DataFrames
df_merged = esios.merge_series(df_list, names)
xls_path = "2016_data.xlsx"
writer = pd.ExcelWriter(xls_path)
for i, df in enumerate(df_list):
df.to_excel(writer, str(indicators_[i]))
df_merged[names].to_excel(writer, "Merged")
writer.save()
# # plot
# fig = plt.figure(figsize=(12, 8))
#
# ax1 = fig.add_subplot(211)
# df[names[4]].plot(ax=ax1) # demand
# ax1.set_xlabel('time')
# ax1.set_ylabel('MWh')
#
# # secondary axis
# ax2 = fig.add_subplot(212, sharex=ax1)
# df[names[0:4]].plot(ax=ax2) # others
# ax2.set_ylabel('€')
#
# for df, n in zip(df_list, names):
# print('name: ', n, df.columns.values)
# df[[n]].plot(marker='x')
#
# plt.show()