From 954cc47fb85c950aa3dcee87f96fb192bbb377a8 Mon Sep 17 00:00:00 2001 From: Darryl Melander Date: Thu, 18 May 2023 18:50:47 -0600 Subject: [PATCH] Add flag to ignore look-ahead period counts when parsing RTS-GMLC. RTS-GMLC metadata has "Look_Ahead_Periods_per_Step" fields that indicate how much data to include in each simulation step. Consumers of RTS-GMLC data (such as Prescient) may have their own mechanisms for determining the simulation horizon, and it may not match the values stored in the metadata. This commit adds a new argument to rts_gmlc.parser.parse_to_cache(), called "honor_lookahead". If this is True (the default), it uses the lookahead period count found in the data's metadata. If it is False, it does not include any extra data beyond the specified end_time. When calling this function, consumers of the parsed data are expected to adjust the end_time to include any look-ahead periods it may need. --- egret/parsers/rts_gmlc/parser.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/egret/parsers/rts_gmlc/parser.py b/egret/parsers/rts_gmlc/parser.py index f5b75043..bd5284a8 100644 --- a/egret/parsers/rts_gmlc/parser.py +++ b/egret/parsers/rts_gmlc/parser.py @@ -102,7 +102,8 @@ def create_model_data_dict(rts_gmlc_dir:str, def parse_to_cache(rts_gmlc_dir:str, begin_time:Union[datetime,str], end_time:Union[datetime,str], - t0_state:Optional[dict]=None) -> ParsedCache: + t0_state:Optional[dict]=None, + honor_lookahead=True) -> ParsedCache: ''' Parse data in RTS-GMLC format, keeping the portions between a start and end time rts_gmlc_dir : str @@ -127,7 +128,7 @@ def parse_to_cache(rts_gmlc_dir:str, model_data = _create_rtsgmlc_skeleton(rts_gmlc_dir) # Save the data frequencies - metadata_df = _read_metadata(rts_gmlc_dir) + metadata_df = _read_metadata(rts_gmlc_dir, honor_lookahead) minutes_per_period = {'DAY_AHEAD':int(metadata_df.loc['Period_Resolution', 'DAY_AHEAD'])//60, 'REAL_TIME':int(metadata_df.loc['Period_Resolution', 'REAL_TIME'])//60} @@ -151,7 +152,7 @@ def parse_to_cache(rts_gmlc_dir:str, timeseries_df, load_participation_factors, constant_reserve_data) -def _read_metadata(base_dir:str) -> pd.DataFrame: +def _read_metadata(base_dir:str, honor_lookahead:bool) -> pd.DataFrame: metadata_path = os.path.join(base_dir, "simulation_objects.csv") if not os.path.exists(metadata_path): raise ValueError(f'RTS-GMLC directory "{rts_gmlc_dir}" does not contain expected CSV files.') @@ -159,6 +160,10 @@ def _read_metadata(base_dir:str) -> pd.DataFrame: # Read metadata about the data metadata_df = pd.read_csv(metadata_path, index_col=0) + if not honor_lookahead: + metadata_df.loc['Look_Ahead_Periods_per_Step']['DAY_AHEAD'] = 0 + metadata_df.loc['Look_Ahead_Periods_per_Step']['REAL_TIME'] = 0 + return metadata_df def _get_data_date_range(metadata_df) -> Tuple[datetime, datetime]: