Created
June 3, 2021 09:35
-
-
Save AyrtonB/ce2e3d40327b1ddf881b8b2599da8551 to your computer and use it in GitHub Desktop.
GB Curtailment Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import os | |
import dotenv | |
import pandas as pd | |
import ElexonDataPortal.API as edp_API | |
# Helper Functions | |
def create_BMRS_wrapper(API_key=None, env_fp='.env'): | |
if API_key is None: | |
if env_fp is not None: | |
assert dotenv.load_dotenv(env_fp), 'No `.env` file was identified' | |
API_key = os.environ['BMRS_API_key'] | |
edp_wrapper = edp_API.Wrapper(API_key) | |
return edp_wrapper | |
flatten_list = lambda list_: [item for sublist in list_ for item in sublist] | |
def get_wf_ids(dictionary_url='https://raw.githubusercontent.com/OSUKED/Power-Station-Dictionary/main/data/output/power_stations.csv'): | |
df_dictionary = pd.read_csv(dictionary_url) | |
wf_ids = flatten_list(df_dictionary.query('fuel_type=="wind"')['sett_bmu_id'].str.split(', ').to_list()) | |
return wf_ids | |
def calc_curt_wind(df_detsysprices, wf_ids=[]): | |
s_curt_wind = (df_detsysprices | |
.query('recordType=="BID" & soFlag=="T" & id in @wf_ids') | |
.astype({'bidVolume': float}) | |
.groupby('datetime') | |
['bidVolume'] | |
.sum() | |
.abs() | |
) | |
return s_curt_wind | |
# Retrieval | |
stream = 'DETSYSPRICES' | |
query_args = { | |
'start_date' : '2019-12-01', | |
'end_date' : '2019-12-07 23:30', | |
} | |
edp_wrapper = create_BMRS_wrapper() | |
df_detsysprices = edp_wrapper.query_orchestrator(stream, query_args) | |
wf_ids = get_wf_ids() | |
s_curt_wind = calc_curt_wind(df_detsysprices, wf_ids) | |
s_curt_wind.plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment