Skip to content

Commit

Permalink
finish US-SEC: merge gas/coal from EIA with solar
Browse files Browse the repository at this point in the history
for electricitymaps#1713

uses `ENTSOE.merge_production_outputs()`, and there isn't much precedent for parsers reusing, so i've also added a TODO to move that function to `lib.utils`.
  • Loading branch information
snarfed committed Jul 18, 2019
1 parent 9d04fee commit 79fcba7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions parsers/ENTSOE.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ def fetch_production(zone_key, session=None, target_datetime=None,
}


# TODO: generalize and move to lib.utils so other parsers can reuse it. (it's
# currently used by US_SEC.)
def merge_production_outputs(parser_outputs, merge_zone_key, merge_source=None):
"""
Given multiple parser outputs, sum the production and storage
Expand Down
42 changes: 27 additions & 15 deletions parsers/US_SEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"""Parser for the Seminole Electric Cooperative in Florida, USA.
https://www.seminole-electric.com/facilities/generation/
http://apps.seminole.coop/db/cs/
https://github.com/tmrowco/electricitymap-contrib/issues/1713
"""

Expand All @@ -10,41 +12,51 @@

import pandas as pd

import EIA
from parsers import EIA
from parsers.ENTSOE import merge_production_outputs


def fetch_production(zone_key='US-SEC', session=None,
target_datetime=None, logger=logging.getLogger(__name__)):
"""Requests the last known production mix (in MW) of a given country
def fetch_production(zone_key='US-SEC', session=None, target_datetime=None,
logger=logging.getLogger(__name__)):
unknown = fetch_unknown(zone_key=zone_key, session=session,
target_datetime=target_datetime, logger=logger)
solar = fetch_solar(session=session, logger=logger)
return merge_production_outputs((unknown, solar), zone_key,
merge_source='eia.org, apps.seminole.coop')

See example.py for details.
"""

def fetch_unknown(zone_key='US-SEC', session=None, target_datetime=None,
logger=logging.getLogger(__name__)):
data = EIA.fetch_production(zone_key=zone_key, session=session,
target_datetime=target_datetime, logger=logger)
for hour in data:
hour['production'] = {'unknown': hour.pop('value')}
hour.update({
'production': {'unknown': hour.pop('value')},
'storage': {}, # required by merge_production_outputs
})

return data


def fetch_solar(session=None, logger=logging.getLogger(__name__)):
url = 'http://apps.seminole.coop/db/cs/render.ashx?ItemPath=/Applications/Solar+Dashboard/Cooperative+Solar+-+Data&Format=EXCEL&rptHDInterval=Day&rptHDOffset=0'
url = 'http://apps.seminole.coop/db/cs/render.ashx?ItemPath=/Applications/Solar+Dashboard/Cooperative+Solar+-+Data&Format=EXCEL&rptHDInterval=Week&rptHDOffset=0'
df = pd.read_excel(url, sheet_name='Hourly', skiprows=[0])

return [{
'zoneKey': 'US_SEC',
'zoneKey': 'US-SEC',
'datetime': row['Date/Time (UTC)'].to_pydatetime().replace(tzinfo=timezone.utc),
'production': {'solar': row['kW'] / 1000.0},
'storage': {}, # required by merge_production_outputs
'source': 'apps.seminole.coop',
} for _, row in df.iterrows()]



if __name__ == '__main__':
def main():
"""Main method, not used by the ElectricityMap backend, just for testing."""

import pprint
print('fetch_production() ->')
print(pprint.pprint(fetch_production(target_datetime='20190705T22Z')))
print('fetch_solar() ->')
print(pprint.pprint(fetch_solar()))
print(pprint.pprint(fetch_production()))


if __name__ == '__main__':
main()

0 comments on commit 79fcba7

Please sign in to comment.