def get_initial_model(self, options: Options, num_time_steps: int, minutes_per_timestep: int) -> EgretModel: ''' Get a model ready to be populated with data Returns ------- A model object populated with static system information, such as buses and generators, and with time series arrays that are large enough to hold num_time_steps entries. Initial values in time time series do not have meaning. ''' # Get data for the first simulation day first_day_model = self._get_forecast_by_date(self._first_day) # Copy it, making sure we've got the right number of time periods data = _recurse_copy_with_time_series_length(first_day_model.data, num_time_steps) new_model = EgretModel(data) new_model.data['system']['time_keys'] = list( str(i) for i in range(1, num_time_steps + 1)) new_model.data['system'][ 'time_period_length_minutes'] = minutes_per_timestep return new_model
def _get_initial_model(self, options: Options, num_time_steps: int, minutes_per_timestep: int) -> EgretModel: ''' Get a model ready to be populated with data Returns ------- A model object populated with static system information, such as buses and generators, and with time series arrays that are large enough to hold num_time_steps entries. Initial values in time time series do not have meaning. ''' data = copy.deepcopy(self._initial_model) data['system']['time_period_length_minutes'] = minutes_per_timestep data['system']['time_keys'] = [ str(i) for i in range(1, num_time_steps + 1) ] def _ensure_timeseries_allocated(d): for k, v in d.items(): if isinstance(v, dict): if 'data_type' in v and v['data_type'] == 'time_series': v['values'] = [None] * num_time_steps else: _ensure_timeseries_allocated(v) _ensure_timeseries_allocated(data) return EgretModel(data)
def _get_initial_model(self, sim_type:str, options:Options, num_time_steps:int, minutes_per_timestep:int) -> EgretModel: ''' Get a model ready to be populated with data Returns ------- A model object populated with static system information, such as buses and generators, and with time series arrays that are large enough to hold num_time_steps entries. Initial values in time time series do not have meaning. ''' data = self._cache.get_new_skeleton() data['system']['time_period_length_minutes'] = minutes_per_timestep data['system']['time_keys'] = [str(i) for i in range(1,num_time_steps+1)] md = EgretModel(data) self._ensure_forecastable_storage(sim_type, num_time_steps, md) return md
def _get_egret_model_for_date( self, requested_date: date, dat_filename: str, cache_dict: Dict[date, EgretModel]) -> EgretModel: ''' Get data for a specific calendar day. Implements the common logic of _get_actuals_by_date and _get_forecast_by_date. ''' # Return cached model, if we have it if requested_date in cache_dict: return cache_dict[requested_date] # Otherwise read the requested data and store it in the cache date_str = str(requested_date) path_to_dat = os.path.join(self._instance_directory_name, date_str, dat_filename) day_pyomo = self._uc_model_template.create_instance(path_to_dat) day_dict = create_model_data_dict_params(day_pyomo, True) day_model = EgretModel(day_dict) cache_dict[requested_date] = day_model return day_model
def _get_egret_model_for_date( self, requested_date: date, dat_filename: str, cache_dict: Dict[date, EgretModel]) -> EgretModel: ''' Get data for a specific calendar day. Implements the common logic of _get_actuals_by_date and _get_forecast_by_date. ''' # Return cached model, if we have it if requested_date in cache_dict: return cache_dict[requested_date] # Otherwise read the requested data and store it in the cache date_str = str(requested_date) path_to_dat = os.path.join(self._instance_directory_name, date_str, dat_filename) # if requested day does not exist, use the last day's data instead if not os.path.exists(path_to_dat): # Pull it from the cache, if present if self._final_day in cache_dict: day_model = cache_dict[self._final_day] cache_dict[requested_date] = day_model return day_model # Or set the dat path to the final day, if it's not in the cache else: date_str = str(self._final_day) path_to_dat = os.path.join(self._instance_directory_name, date_str, dat_filename) day_pyomo = self._uc_model_template.create_instance(path_to_dat) day_dict = create_model_data_dict_params(day_pyomo, True) day_model = EgretModel(day_dict) cache_dict[requested_date] = day_model return day_model