-
Notifications
You must be signed in to change notification settings - Fork 961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add data parser for Iceland #338
Changes from 5 commits
8bf4f4e
576fcd6
05f175f
2311478
f46c14a
825695b
06ec40f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import requests | ||
from datetime import datetime | ||
from collections import defaultdict | ||
import xml.etree.ElementTree as ET | ||
import json | ||
|
||
STATIONS = { | ||
|
||
# http://www.landsvirkjun.com/company/powerstations/ | ||
'Bjarnaflag': 'geothermal', # No data? | ||
'BLANDA_F': 'hydro', | ||
'BUDAR_O': 'hydro', | ||
'BURF_F': 'hydro', | ||
'FLJOTSDA': 'hydro', | ||
'Hafio': 'wind', # No data? | ||
'HRAUN_F': 'hydro', | ||
'IRAFOS_F': 'hydro', | ||
'KRAFLA_F': 'geothermal', | ||
'LAXA_F': 'hydro', | ||
'LAXARVAT': 'hydro', | ||
'laxa': 'hydro', # No data? | ||
'LJOSIF_F': 'hydro', | ||
'SIG_F': 'hydro', | ||
'Steingrimsstod': 'hydro', # No data? | ||
'SULTAR_F': 'hydro', | ||
'VATNSHAM': 'hydro', | ||
|
||
# https://en.wikipedia.org/wiki/List_of_power_stations_in_Iceland | ||
'KOLVID': 'geothermal', | ||
'LAGARF': 'hydro', | ||
'MJOLKA': 'hydro', | ||
'REY': 'geothermal', | ||
'X_NESJAV': 'geothermal', | ||
'SVA': 'geothermal', | ||
} | ||
|
||
def fetch_production(country_code='IS', session=None): | ||
|
||
# Query Landsnet for latest power production data for Iceland | ||
r = session or requests.session() | ||
url = 'http://amper.landsnet.is/MapData/api/measurements' | ||
response = r.get(url) | ||
json_obj = json.loads(response.text) | ||
|
||
production = defaultdict(float) | ||
|
||
# Calculate production values for each power station | ||
for key, value in STATIONS.items(): | ||
items = [item for item in json_obj if item["substation"] == key and item["MW"] >= 0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens to all stations that are not matched? They are simply ignored? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are ignored, yeah. I'm not sure it's a good idea to funnel them all into unknown by default because I don't think everything we get through that API is actually power generation. For example, there is a substation The data for that example has some pretty big MW values, so it'd skew our results quite heavily. Without better knowledge of Icelandic I was thinking it might be best for now to just stick with the stations that @birkir made specific note of? What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok I agree! Maybe add a small comment explaining that in the code. |
||
mw = sum(item['MW'] for item in items) | ||
production[value] = production[value] + mw; | ||
|
||
# Get datetime for last update (e.g. 2017-02-02T14:35:00) | ||
totalpowerflow = next(item for item in json_obj if item["key"] == "TOTAL_POWER_FLOW") | ||
datetime_last = datetime.strptime(totalpowerflow["time"], '%Y-%m-%dT%H:%M:%S') | ||
|
||
data = { | ||
'countryCode': country_code, | ||
'production': dict(production), | ||
'datetime': datetime_last, | ||
'storage': {}, | ||
'source': 'landsnet.is', | ||
} | ||
return data | ||
|
||
if __name__ == '__main__': | ||
print fetch_production() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove from here. In principle, because you have "unknown" not None, this should not be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I've added support for geothermal this is required again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this line is to make exceptions for specific countries that we want to show on the map even though they have no coal data.
However, having no coal data is different from having coal set to 0. For IS, if we can confirm that they do not produce any coal, we should set the
coal
key to 0 in the parser. We should do the same for all production types that we know IS doesn't have.