Main Scripts¶
The module RIPSMasterScript.py
contains the main scripts to execute CE/UCED simulations
-
masterFunction
(genparam, reserveparam, curtailparam)¶ Main function of CE/UCED simulation
This is the main function that must be called to start a CE/UCED simulation. It takes three arguments that define the parameters of the simulation. Each argument is an object with a set of specific parameters for the simulation. These objects must be created and the fields defined before being passed to this function.
- Parameters
genparam – object of type
Generalparameters
reserveparam – object of type
Reserveparameters
curtailparam – object of type
Curtailmentparameters
-
getInitialFleetAndDemand
(genparam, reserveparam)¶ Set up initial generator fleet
Reads folders containing data of existing power plant data and compiles 2d list with generator fleet data.
- Parameters
genparam – object of class
Generalparameters
reserveparam – object of class
Reserveparameters
- Returns
2d list with initial generator fleet data
-
runCapacityExpansion
(genFleet, zonalDemandProfile, currYear, currCo2Cap, capacExpModelsEachYear, capacExpBuilds, capacExpGenByGens, capacExpRetiredUnitsByCE, capacExpRetiredUnitsByAge, genFleetPriorCE, priorCEout_db, priorHoursCE, genparam, reserveparam, curtailparam)¶ Run one annual iteration of the capacity expansion simulation
This function does all the reading and preprocessing before executing capacity expansion optimization
- Parameters
genFleet – (2d list) with original existing generator fleet (in the first year of the simulation)
zonalDemandProfile – (dict) nested dictionary with hourly demand by ipm zone in each gcm case being simulated. Dictionary is {gcm: {zone: [hourly demand]}}
currYear – (int) year of simulation
currCo2Cap – float with value in MMton/year of CO2 emission limit
capacExpModelsEachYear – (list) list with gams models in previous CE simulation years
capacExpBuilds – (2d list) list with complete builds (by plant type) of capacity expansion model
capacExpGenByGens – (2d list) list with generation of each individual plant in previous simulation year (used to compute retirements)
capacExpRetiredUnitsByCE – (list) list with retired units because of low CF
capacExpRetiredUnitsByAge – (list) list with retired units because of age
genFleetPriorCE – 2d list with existing generator fleet in current year of simulation (including prior additions)
priorCEout_db – gams data base object with results of capacity expansion iteration in previous simulation year
priorHoursCE – (dict) dictionary with hours considered in previous CE simulation year
genparam – object of class
Generalparameters
reserveparam – object of class
Reserveparameters
curtailparam – object of class
Curtailmentparameters
- Returns
resulting generator fleet (including retired units), resulting generator fleet (excluding retired units), generator fleet before CE expansion decisions, gams data base with results, dictionary with hours of the year used in CE simulation.
-
importHourlyThermalCurtailments
(genFleet, currYear, modelName, resultsDir, genparam, curtailparam)¶ Import hourly thermal curtailments by generator
This is a wrapper function that calls thermal curtailments simulations and cleans up the output so it can be used by the CE/UCED simulations
- Parameters
genFleet – 2d list (matrix) with data of generator fleet
currYear – current year of analysis
modelName – string with model name (‘CE’ or ‘UC’)
resultsDir – string specifying folder where output files will be saved
genparam – object of type
Generalparameters
curtailparam – object of type
Curtailmentparameters
- Returns
nested dict mapping each gen to 1d numpy array of hourly net capacity curtailments(MW) dict is {gcm:{genId: 1d np.array()}}
-
callCapacityExpansion
(genFleetForCE, hourlyCapacsCE, hourlyCurtailedTechCapacsCE, hourlyWindGenCEZonal, hourlySolarGenCEZonal, demandCEZonal, newTechsCE, planningReserveZonal, hoursForCE, newWindCFsCEZonal, newSolarCFsCEZonal, currCo2Cap, seasonDemandWeights, repHrsBySeason, specialHrs, peakDemandHourZonal, cellsToZones, hydroPotPerSeason, genparam)¶ Call capacity expansion optimization
This funtion loads GAMS workspace and runs capacity expansion optimization
- Parameters
genFleetForCE – 2d list (matrix) with data of generator fleet
hourlyCapacsCE – (dict) hourly derated capacity existing thermal plants
hourlyCurtailedTechCapacsCE – (dict) hourly derated capacity new thermal plants
hourlyWindGenCEZonal – (dict) hourly wind gen of existing plants in each zone trimmed to CE simulation hours
hourlySolarGenCEZonal – (dict) hourly solar gen of existing plants in each zone trimmed to CE simulation hours
demandCEZonal – (dict) hourly demand values in each zone/gcm trimmed to CE simulation hours
newTechsCE – (list) table with new techs parameters
planningReserveZonal – (dict) values of planning reserve margin in each zone/gcm
hoursForCE – (dict) simulation hours for CE optimization
newWindCFsCEZonal – (dict) values of CFs of potential new wind gens
newSolarCFsCEZonal – (dict) values of CFs of potential new solar gens
currCo2Cap – (float) value of co2 cap
seasonDemandWeights – (dict) scaling factors of each season
repHrsBySeason – (dict) representative hours in each season and each gcm
specialHrs – (dict) special hours in each gcm
peakDemandHourZonal – (dict) hour of peak demand in each zone
cellsToZones – (dict) mapping of cells to zones
hydroPotPerSeason – (dict) hydro potential of each generator in each season
genparam – object of type
Generalparameters
- Returns
-
addSetsToDatabaseCE
(db, genFleetForCE, hoursForCE, newTechsCE, repHrsBySeason, specialHrs, peakDemandHourZonal, cellsToZones, genparam, blocksWind=None, blocksSolar=None)¶ Add sets needed to GAMS database
This function adds the sets to the GAMS database that are needed to run the capacity expansion optimization
- Parameters
db – gams database
genFleetForCE – 2d list (matrix) with data of generator fleet
hoursForCE – (dict) simulation hours for CE optimization
newTechsCE – (list) table with new techs parameters
repHrsBySeason – (dict) representative hours in each season and each gcm
specialHrs – (dict) special hours in each gcm
peakDemandHourZonal – (dict) hour of peak demand in each zone
cellsToZones – (dict) mapping of cells to zones
genparam – object of type
Generalparameters
blocksWind – (float) size of wind blocks
blocksSolar – (float) size of solar blocks
- Returns
-
addParametersToDatabaseCE
(db, genparam, hoursForCE, hourlyCapacsCE, hourlyWindGenCEZonal, hourlySolarGenCEZonal, demandCEZonal, newTechsCE, genFleetForCE, planningReserveZonal, newWindCFsCEZonal, newSolarCFsCEZonal, currCo2Cap, seasonDemandWeights, hourlyCurtailedTechCapacsCE, cellsToZones, hydroPotPerSeason)¶ Add parameters needed to GAMS database
This function adds the parameters to the GAMS database that are needed to run the capacity expansion optimization
- Parameters
db – gams database object
genparam – object of type
Generalparameters
hoursForCE – (dict) hours of the year considered in CE simulation
hourlyCapacsCE – (dict) hourly derated capacity existing thermal plants
hourlyWindGenCEZonal – (dict) hourly wind gen of existing plants in each zone trimmed to CE simulation hours
hourlySolarGenCEZonal – (dict) hourly solar gen of existing plants in each zone trimmed to CE simulation hours
demandCEZonal – (dict) hourly demand values in each zone/gcm trimmed to CE simulation hours
newTechsCE – (list) table with new techs parameters
genFleetForCE – 2d list (matrix) with data of generator fleet
planningReserveZonal – (dict) values of planning reserve margin in each zone/gcm
newWindCFsCEZonal – (dict) values of CFs of potential new wind gens
newSolarCFsCEZonal – (dict) values of CFs of potential new solar gens
currCo2Cap – (float) value of co2 cap
seasonDemandWeights – (dict) scaling factors of each season
hourlyCurtailedTechCapacsCE – (dict) hourly derated capacity new thermal plants
cellsToZones – (dict) mapping of cells to zones
hydroPotPerSeason – (dict) hydro potential of each generator in each season
-
runUnitCommitment
(genFleet, zonalDemandProfile, ucYear, currCo2Cap, genparam, reserveparam, curtailparam)¶ Run unit commitment simulation for all climate simulations in parallel for the complete simulation period
- Parameters
genFleet – 2d list with generator fleet for UCED simulation
zonalDemandProfile – (2d list) list with hourly demand in each zone
ucYear – integer with year of UCED run
currCo2Cap – (float) value of CO2 cap
genparam – object of class
Generalparameters
reserveparam – object of type
Reserveparameters
curtailparam – object of type
Curtailmentparameters
- Returns
-
runUnitCommitmentSingleGcm
(list_args)¶ Run unit commitment simulation for one single climate simulation for the complete simulation period
This function was prepared to be ran using parallel simulation (multicore) so its argument is a list packing all arguments. To reduce simulation time, some arrays that do not depend on climate simulations (in our model) are executed outside of this function and passed as arguments (such as solar/wind generation)
The list in the argument contains the following parameters:
gcm: (string) name of gcm
fleetUC: (2d list) table of generator fleet
zonalDemandProfile: (2d list) hourly demand for complete simulation period for each zone
ucYear: (int) year of simulation
currCo2Cap: (float) value of co2 cap
genparam: object of type
Generalparameters
reserveparam: object of type
Reserveparameters
curtailparam: object of type
Curtailmentparameters
zonalHourlyWindGen: (2d list) hourly wind generation for complete simulation period for each zone
zonalHourlySolarGen: (2d list) hourly solar generation for complete simulation period for each zone
zonalHourlyDfWind: (pd data frame) hourly wind generation for complete simulation period for each zone
zonalHourlyDfSolar: (pd data frame) hourly solar generation for complete simulation period for each zone
zonalSubhourlyDfWind: (pd data frame) sub-hourly wind generation for complete simulation period for each zone
zonalSubhourlyDfSolar: (pd data frame) sub-hourly solar generation for complete simulation period for each zone
- Parameters
list_args – (list) a list packing all arguments for this function
- Returns
this function returns the integer value 0
-
callUnitCommitment
(fleetUC, hourlyCapacsUC, hourlyWindGenUC, hourlySolarGenUC, hydroPotentialUC, demandUC, hoursForUC, onOffInitial, genAboveMinInitial, mdtCarriedInitial, initSoc, co2Price, regUpUC, regDownUC, flexUC, contUC, genparam, reserveparam)¶ Run the unit commintment and economic dispatch optimization for a single day
This function is called sequentially in order to simulate dispatch over all days in the complete simulation horizon
- Parameters
fleetUC – 2d list with generator fleet for UCED simulation
hourlyCapacsUC – (list) hourly available capacity of generators
hourlyWindGenUC – (list) hourly generation potential wind of generators
hourlySolarGenUC – (list) hourly generation potential solar of generators
hydroPotentialUC – (dict) generation potential of hydro gens
demandUC – (1d list) hourly demand
hoursForUC – 1d list with hours (1-8760) that will be used in this UCED run
onOffInitial – (list) initial status of generator (on/off)
genAboveMinInitial – (list) initial state of generation above minimum for each generator
mdtCarriedInitial – (list) initial state of min down time for each generator
initSoc – (dict) initial state of charge
co2Price – (float) co2 price
regUpUC – (list) hourly regulation reserve requirements
regDownUC – (list) hourly regulation reserve requirements
flexUC – (list) hourly flexibility reserve requirements
contUC – (list) hourly contigency reserve requirements
genparam – object of class
Generalparameters
reserveparam – object of type
Reserveparameters
- Returns
-
addSetsToDatabaseUC
(db, fleetUC, hoursForUC, genparam)¶ Add sets to GAMS database
This function adds the sets to the GAMS database needed to run the UCED optimization
- Parameters
db – gams database object
fleetUC – 2d list with generator fleet for UCED simulation
hoursForUC – 1d list with hours (1-8760) that will be used in this UCED run
genparam – object of class
Generalparameters
- Returns
-
addParametersToDatabaseUC
(db, hourlyCapacsUC, hourlyWindGenUC, hourlySolarGenUC, hydroPotentialUC, demandUC, fleetUC, onOffInitial, genAboveMinInitial, mdtCarriedInitial, initSoc, co2Price, hoursForUC, flexUC, contUC, regUpUC, regDownUC, genparam, reserveparam)¶ Add parameters to GAMS database
This function adds the parameters to the GAMS database needed to run the UCED optimization
- Parameters
db – gams database object
hourlyCapacsUC – (list) hourly available capacity of generators
hourlyWindGenUC – (list) hourly generation potential wind of generators
hourlySolarGenUC – (list) hourly generation potential solar of generators
hydroPotentialUC – (dict) generation potential of hydro gens
demandUC – (list) (1d list) hourly demand
fleetUC – 2d list with generator fleet for UCED simulation
onOffInitial – (list) initial status of generator (on/off)
genAboveMinInitial – (list) initial state of generation above minimum for each generator
mdtCarriedInitial – (list) initial state of min down time for each generator
initSoc – (dict) initial state of charge for pumped storage
co2Price – (float) price of co2
hoursForUC – 1d list with hours (1-8760) that will be used in this UCED run
flexUC – (list) flexibility reserve requirements
contUC – (list) contigency reserve requirements
regUpUC – (list) regulatory reserve requirements
regDownUC – (list) regulatory reserve requirements
genparam – object of class
Generalparameters
reserveparam – object of type
Reserveparameters
-
create_description_file
(genparam, curtailparam)¶ Create a description file of the case in the output folder
- Parameters
genparam – object of class
Generalparameters
reserveparam – object of type
Reserveparameters