This module creates a Python wrapper for the new Red Eléctrica de España electricity data API. Currently the API only has a few streams up and running, for this reason the wrapper has been designed to be highly generalisable as new streams are added.
from REData import REData
There is a standardised API to query any of the data streams and retrieve a dataframe of the results
category = 'balance'
widget = 'balance-electrico'
start_date = '2019-01-01T00:00'
end_date = '2019-01-12T00:00'
time_trunc = 'day'
RED_stream = REData(category, widget)
df = RED_stream.query_REData(start_date, end_date, time_trunc)
df.head()
Hydro | Wind | Solar photovoltaic | Thermal solar | Hydroeolian | Other renewables | Renewable waste | Renewable generation | Pumped storage | Nuclear | Combined cycle | Coal | Fuel + Gas | Cogeneration | Non-renewable waste | Non-renewable generation | Pumped storage consumption | Cross-border exchange balance | Demand at busbars | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
datetime | |||||||||||||||||||
2019-01-01 00:00:00+01:00 | 53722.120 | 78024.599 | 19037.740 | 7457.265 | 16.410 | 8432.490 | 2661.1455 | 169351.7695 | 825.588 | 145065.884 | 102405.013 | 46490.345 | 15296.578 | 65180.123 | 5881.8945 | 381145.4255 | -8556.568 | 41009.179 | 582949.806 |
2019-01-02 00:00:00+01:00 | 61294.768 | 195509.161 | 18819.394 | 7592.590 | 13.481 | 8440.714 | 2627.5065 | 294297.6145 | 5146.511 | 144935.411 | 101005.855 | 65173.359 | 16756.131 | 81637.709 | 6193.4215 | 420848.3975 | -13556.968 | 40610.363 | 742199.407 |
2019-01-03 00:00:00+01:00 | 82981.951 | 111015.260 | 16813.988 | 6419.244 | 5.994 | 9215.684 | 2605.2615 | 229057.3825 | 9632.887 | 147271.468 | 143640.176 | 82277.309 | 18236.381 | 88044.425 | 6904.3125 | 496006.9585 | 204.628 | 62495.994 | 787764.963 |
2019-01-04 00:00:00+01:00 | 94301.940 | 79621.037 | 18271.437 | 6109.126 | 4.697 | 9434.681 | 2633.5645 | 210376.4825 | 10894.167 | 150097.415 | 182524.379 | 94253.889 | 18796.975 | 90680.246 | 6955.1415 | 554202.2125 | 369.975 | 31061.365 | 796010.035 |
2019-01-05 00:00:00+01:00 | 58822.692 | 116501.377 | 19538.384 | 7205.657 | 14.331 | 9411.312 | 2678.8940 | 214172.6470 | 256.618 | 150843.671 | 117718.032 | 86777.689 | 16965.448 | 85813.533 | 6698.1630 | 465073.1540 | -1153.945 | 42937.795 | 721029.651 |
Sometimes you may want to access the raw response so that functionality has been made available as well
r = RED_stream.make_request(start_date, end_date, time_trunc)
Additionaly, rather than re-initialising the class each time you want to query a new set of data you could instead simply update the stream info
category = 'demanda'
widget = 'evolucion'
RED_stream.update_stream(category, widget)
df = RED_stream.query_REData(start_date, end_date, time_trunc)
df.head()
Demand | |
---|---|
datetime | |
2019-01-01 00:00:00+01:00 | 582949.806 |
2019-01-02 00:00:00+01:00 | 742199.407 |
2019-01-03 00:00:00+01:00 | 787764.963 |
2019-01-04 00:00:00+01:00 | 796010.035 |
2019-01-05 00:00:00+01:00 | 721029.651 |