def check_valid(self): """ check the parameter is valid (ie it checks that all the values are of correct types and within the correct range. Raises ------- An exception if the parameter is not valid """ try: if not isinstance(self.NO_OVERFLOW_DISCONNECTION, (bool, dt_bool)): raise RuntimeError( "NO_OVERFLOW_DISCONNECTION should be a boolean") self.NO_OVERFLOW_DISCONNECTION = dt_bool( self.NO_OVERFLOW_DISCONNECTION) except Exception as exc_: raise RuntimeError( f"Impossible to convert NO_OVERFLOW_DISCONNECTION to bool with error \n:\"{exc_}\"" ) try: self.NB_TIMESTEP_OVERFLOW_ALLOWED = int( self.NB_TIMESTEP_OVERFLOW_ALLOWED) # to raise if numpy array self.NB_TIMESTEP_OVERFLOW_ALLOWED = dt_int( self.NB_TIMESTEP_OVERFLOW_ALLOWED) except Exception as exc_: raise RuntimeError( f"Impossible to convert NB_TIMESTEP_OVERFLOW_ALLOWED to int with error \n:\"{exc_}\"" ) if self.NB_TIMESTEP_OVERFLOW_ALLOWED < 0: raise RuntimeError( "NB_TIMESTEP_OVERFLOW_ALLOWED < 0., this should be >= 0.") try: self.NB_TIMESTEP_RECONNECTION = int( self.NB_TIMESTEP_RECONNECTION) # to raise if numpy array self.NB_TIMESTEP_RECONNECTION = dt_int( self.NB_TIMESTEP_RECONNECTION) except Exception as exc_: raise RuntimeError( f"Impossible to convert NB_TIMESTEP_RECONNECTION to int with error \n:\"{exc_}\"" ) if self.NB_TIMESTEP_RECONNECTION < 0: raise RuntimeError( "NB_TIMESTEP_RECONNECTION < 0., this should be >= 0.") try: self.NB_TIMESTEP_COOLDOWN_LINE = int( self.NB_TIMESTEP_COOLDOWN_LINE) self.NB_TIMESTEP_COOLDOWN_LINE = dt_int( self.NB_TIMESTEP_COOLDOWN_LINE) except Exception as exc_: raise RuntimeError( f"Impossible to convert NB_TIMESTEP_COOLDOWN_LINE to int with error \n:\"{exc_}\"" ) if self.NB_TIMESTEP_COOLDOWN_LINE < 0: raise RuntimeError( "NB_TIMESTEP_COOLDOWN_LINE < 0., this should be >= 0.") try: self.NB_TIMESTEP_COOLDOWN_SUB = int( self.NB_TIMESTEP_COOLDOWN_SUB) # to raise if numpy array self.NB_TIMESTEP_COOLDOWN_SUB = dt_int( self.NB_TIMESTEP_COOLDOWN_SUB) except Exception as exc_: raise RuntimeError( f"Impossible to convert NB_TIMESTEP_COOLDOWN_SUB to int with error \n:\"{exc_}\"" ) if self.NB_TIMESTEP_COOLDOWN_SUB < 0: raise RuntimeError( "NB_TIMESTEP_COOLDOWN_SUB < 0., this should be >= 0.") try: self.HARD_OVERFLOW_THRESHOLD = float( self.HARD_OVERFLOW_THRESHOLD) # to raise if numpy array self.HARD_OVERFLOW_THRESHOLD = dt_float( self.HARD_OVERFLOW_THRESHOLD) except Exception as exc_: raise RuntimeError( f"Impossible to convert HARD_OVERFLOW_THRESHOLD to float with error \n:\"{exc_}\"" ) if self.HARD_OVERFLOW_THRESHOLD < 1.: raise RuntimeError( "HARD_OVERFLOW_THRESHOLD < 1., this should be >= 1. (use env.set_thermal_limit " "to modify the thermal limit)") try: if not isinstance(self.ENV_DC, (bool, dt_bool)): raise RuntimeError( "NO_OVERFLOW_DISCONNECTION should be a boolean") self.ENV_DC = dt_bool(self.ENV_DC) except Exception as exc_: raise RuntimeError( f"Impossible to convert ENV_DC to bool with error \n:\"{exc_}\"" ) try: self.MAX_SUB_CHANGED = int( self.MAX_SUB_CHANGED) # to raise if numpy array self.MAX_SUB_CHANGED = dt_int(self.MAX_SUB_CHANGED) except Exception as exc_: raise RuntimeError( f"Impossible to convert MAX_SUB_CHANGED to int with error \n:\"{exc_}\"" ) if self.MAX_SUB_CHANGED < 0: raise RuntimeError( "MAX_SUB_CHANGED should be >=0 (or -1 if you want to be able to change every " "substation at once)") try: self.MAX_LINE_STATUS_CHANGED = int( self.MAX_LINE_STATUS_CHANGED) # to raise if numpy array self.MAX_LINE_STATUS_CHANGED = dt_int(self.MAX_LINE_STATUS_CHANGED) except Exception as exc_: raise RuntimeError( f"Impossible to convert MAX_LINE_STATUS_CHANGED to int with error \n:\"{exc_}\"" ) if self.MAX_LINE_STATUS_CHANGED < 0: raise RuntimeError( "MAX_LINE_STATUS_CHANGED should be >=0 " "(or -1 if you want to be able to change every powerline at once)" ) try: if not isinstance(self.IGNORE_MIN_UP_DOWN_TIME, (bool, dt_bool)): raise RuntimeError( "IGNORE_MIN_UP_DOWN_TIME should be a boolean") self.IGNORE_MIN_UP_DOWN_TIME = dt_bool( self.IGNORE_MIN_UP_DOWN_TIME) except Exception as exc_: raise RuntimeError( f"Impossible to convert IGNORE_MIN_UP_DOWN_TIME to bool with error \n:\"{exc_}\"" ) try: if not isinstance(self.ALLOW_DISPATCH_GEN_SWITCH_OFF, (bool, dt_bool)): raise RuntimeError( "ALLOW_DISPATCH_GEN_SWITCH_OFF should be a boolean") self.ALLOW_DISPATCH_GEN_SWITCH_OFF = dt_bool( self.ALLOW_DISPATCH_GEN_SWITCH_OFF) except Exception as exc_: raise RuntimeError( f"Impossible to convert ALLOW_DISPATCH_GEN_SWITCH_OFF to bool with error \n:\"{exc_}\"" ) try: self.INIT_STORAGE_CAPACITY = float( self.INIT_STORAGE_CAPACITY) # to raise if numpy array self.INIT_STORAGE_CAPACITY = dt_float(self.INIT_STORAGE_CAPACITY) except Exception as exc_: raise RuntimeError( f"Impossible to convert INIT_STORAGE_CAPACITY to float with error \n:\"{exc_}\"" ) if self.INIT_STORAGE_CAPACITY < 0.: raise RuntimeError( "INIT_STORAGE_CAPACITY < 0., this should be within range [0., 1.]" ) if self.INIT_STORAGE_CAPACITY > 1.: raise RuntimeError( "INIT_STORAGE_CAPACITY > 1., this should be within range [0., 1.]" ) try: if not isinstance(self.ACTIVATE_STORAGE_LOSS, (bool, dt_bool)): raise RuntimeError("ACTIVATE_STORAGE_LOSS should be a boolean") self.ACTIVATE_STORAGE_LOSS = dt_bool(self.ACTIVATE_STORAGE_LOSS) except Exception as exc_: raise RuntimeError( f"Impossible to convert ACTIVATE_STORAGE_LOSS to bool with error \n:\"{exc_}\"" ) if self.ALARM_WINDOW_SIZE <= 0: raise RuntimeError( "self.ALARM_WINDOW_SIZE should be a positive integer !") if self.ALARM_BEST_TIME <= 0: raise RuntimeError( "self.ALARM_BEST_TIME should be a positive integer !")
def load_redispacthing_data(self, path, name='prods_charac.csv'): """ .. warning:: /!\\\\ Internal, do not use unless you know what you are doing /!\\\\ This method will load everything needed for the redispatching and unit commitment problem. Parameters ---------- path: ``str`` Location of the datafram containing the redispatching data. name: ``str`` Name of the dataframe containing the redispatching data """ self._fill_names() # for redispatching fullpath = os.path.join(path, name) if not os.path.exists(fullpath): self.redispatching_unit_commitment_availble = False return try: df = pd.read_csv(fullpath) except Exception as e: return for el in [ "type", "Pmax", "Pmin", "max_ramp_up", "max_ramp_down", "start_cost", "shut_down_cost", "marginal_cost", "min_up_time", "min_down_time" ]: if el not in df.columns: return gen_info = {} for _, row in df.iterrows(): gen_info[row["name"]] = { "type": row["type"], "pmax": row["Pmax"], "pmin": row["Pmin"], "max_ramp_up": row["max_ramp_up"], "max_ramp_down": row["max_ramp_down"], "start_cost": row["start_cost"], "shut_down_cost": row["shut_down_cost"], "marginal_cost": row["marginal_cost"], "min_up_time": row["min_up_time"], "min_down_time": row["min_down_time"] } self.redispatching_unit_commitment_availble = True self.gen_type = np.full(self.n_gen, fill_value="aaaaaaaaaa") self.gen_pmin = np.full(self.n_gen, fill_value=1., dtype=dt_float) self.gen_pmax = np.full(self.n_gen, fill_value=1., dtype=dt_float) self.gen_redispatchable = np.full(self.n_gen, fill_value=False, dtype=dt_bool) self.gen_max_ramp_up = np.full(self.n_gen, fill_value=0., dtype=dt_float) self.gen_max_ramp_down = np.full(self.n_gen, fill_value=0., dtype=dt_float) self.gen_min_uptime = np.full(self.n_gen, fill_value=-1, dtype=dt_int) self.gen_min_downtime = np.full(self.n_gen, fill_value=-1, dtype=dt_int) self.gen_cost_per_MW = np.full(self.n_gen, fill_value=1., dtype=dt_float) # marginal cost self.gen_startup_cost = np.full(self.n_gen, fill_value=1., dtype=dt_float) # start cost self.gen_shutdown_cost = np.full(self.n_gen, fill_value=1., dtype=dt_float) # shutdown cost for i, gen_nm in enumerate(self.name_gen): tmp_gen = gen_info[gen_nm] self.gen_type[i] = str(tmp_gen["type"]) self.gen_pmin[i] = dt_float(tmp_gen["pmin"]) self.gen_pmax[i] = dt_float(tmp_gen["pmax"]) self.gen_redispatchable[i] = dt_bool( tmp_gen["type"] not in ["wind", "solar"]) tmp = dt_float(tmp_gen["max_ramp_up"]) if np.isfinite(tmp): self.gen_max_ramp_up[i] = tmp tmp = dt_float(tmp_gen["max_ramp_down"]) if np.isfinite(tmp): self.gen_max_ramp_down[i] = tmp self.gen_min_uptime[i] = dt_int(tmp_gen["min_up_time"]) self.gen_min_downtime[i] = dt_int(tmp_gen["min_down_time"]) self.gen_cost_per_MW[i] = dt_float(tmp_gen["marginal_cost"]) self.gen_startup_cost[i] = dt_float(tmp_gen["start_cost"]) self.gen_shutdown_cost[i] = dt_float(tmp_gen["shut_down_cost"])