Integration of GEM with R
- Software requirements
- Installation
- To run via the shiny app
- To run via R script
- Creating a demand file
- Input files
- To do
- App screenshots
- R - current project version: 3.6.0
- RStudio
- GAMS - current project version: 25.3
- git - this is more of a nice-to-have as you can still download the project as a zip file from GitHub.
- Open a command prompt (or git bash) and navigate to the path you would like to clone the project repository to (e.g.
cd C:\apps\). - Use git to clone the repository by typing the following:
git clone https://github.com/ElectricityAuthority/gemR.git. This will create a copy of thegemRproject in the location you navigated to in step 1. - Navigate to the
gemRfolder and open the project in RStudio (double-click ongemR.Rproj). - On loading the project for the first time, there is a check to see if the
packratpackage is installed (packratis being used for package management and reproducibility). If it does not exist, RStudio will attempt to install it. (NOTE: if you have cloned the project to a mapped network drive you may see the error: cannot set reparse point '...gemR/packrat/lib-R/x86_64-w64-mingw32/3.5.1/base', reason 'Access is denied. It is a known issue, just ignore it.) - Restore all packages required by the project using a call to
packrat::restore(). This will take a while but will only need to be done once - go grab a coffee!. - Restart your RStudio session (
Session>Restart R) - an important step!
- Use the
Filestab in RStudio to navigate toPrograms/R/gemR_shiny/. - Open
ui.Rand click theRun Appbutton at the top right of the script. - In the
Run GEMtab, choose a run name, start and end dates and a demand file and clickRun. - After the run has finished solving, explore the output in the
Resultstab.
- Use the
Filestab in RStudio to navigate toPrograms/R/runGEM/. - Open
runGEM.R. - Update the parameter objects (run name, dates, etc.) at the top of the script.
- Step through and run each subsequent section in sequence.
- Plots are output to
Output/<run name>/Reports/plots/.
- Annual demand forecast for reference year (as a CSV). With the following columns:
dttm(datetime)tp(trading period)poc(point of connection)y(year)mn(month)d(day)MWh(demand in MWh)
Note: an example is currently not provided on GitHub as the file is 170MB.
- Annual electricity demand by POC and year (as a CSV). There is a forecast file currently available in this repository (
Data/Demand/Forecast/annual_energy_forecasts_by_GXP_2012_2050.csv). The file is currently set up in wide format with the first column beingyearand the remaining columns the POCs. Note: this file is out-of-date. There are only 180 POCs in this file.
- Navigate to
Programs/R/generateGEMDemandand opengenerateGEMDemand.R. - Enter the paramaters at the top of the script for
year,forecast file,scenario suffix, etc. - Run through the code step by step:
i) Read in the demand CSV.
ii) Optionally, create time series plots demand for all POCs.
iii) Generate load duration curves by POC (currently hard-coded 9 load blocks).
iv) Sum load by POC, month and load block.
v) Optionally, plot all LDCs by POC.
vi) Compute block weights (the proportion of demand) by POC, month and load block.
vii) Compute load share (share of annual load) by POC and month.
viii) Apportion annual load forecast to POCs based on block weights and load share.
ix) Map POCs to regions using concordance (Data/Geography/mapPOCsToRegions.csv) - Note: this concordance is not complete/up-to-date for all POCs at the moment.
x) Output to CSV - the file is output toData/Demand/Archive_<datetime_suffix>. This file can then be used as an input togemR.
Sets, subsets and parameter input CSVs can be found in the GEMdataInput folder.
Setup variables ($setglobals and scalar variables) can be found in the Setup folder.
For more information see the following documentation.
fix code that generates the loss-related parameters (slope, intercept, etc.)- revisit GEMsolve code
- revisit model constraints
- integrate gemR with the DOASA hydro-scheduling model
- add validation and unit tests (use the expect_ functions from the testthat package)
- set up logger (using the
log4rpackage) - update demand forecast data
- test using 18 region version
- move CSS from bottom of
ui.Rinto css file.





