Install Docker for (Mac) or (Windows)
Important: In Docker, go into Docker > Preferences > Resources and up the allocation for disk size image for Docker. 16 GB is recommended for smaller (state level) databasese. 32 GB is recommended for ISO specific databases. 70+GB is required for restoring the national level database. If you get a memory issue then you'll need to up the memory allocation and or will need to prune past failed images/volumes. Running the below docker commands will clear these out and let you start fresh:
$ docker system prune -a
$ docker volume prune -f
Please refer to Docker’s documentation for more details.
Install Anaconda for Python 3.7. Users with VPNs may need to turn their VPNs off while installing or updating Anaconda.
Install PgAdmin. Ignore all of the options for docker, python, os host, etc.
Install Git: If you don't already have git installed, then navigate here to install it for your operating system.
Windows users:
Users need to fork a copy of the dGen repo to their own private github account.
Next, clone the forked repository to your local machine by running the following in a terminal/powershell/command prompt:
$ git clone https://github.com/<github_username>/dgen.git
After cloning this repository and installing (and running) Docker as well as Anaconda, we'll create our environment and container:
$ conda env create -f dg3n.yml
$ conda list
to verify you have this version.$ docker run --name postgis_1 -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -d mdillon/postgis
$ docker run --name postgis_1 -p 5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -d mdillon/postgis
To setup another docker container with a different database you can run:
$ docker run --name postgis_2 -p 7000:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -d mdillon/postgis
where 7000
can be any port number not already in use.
$ docker exec -it <container id> psql -U postgres
$ postgres=# CREATE DATABASE dgen_db;
Notes:
$ docker container ls
. If this doesn't display anything try running $ docker container ps
.psql: FATAL: the database system is starting up
try rerunning the docker exec command again after a minute or so because docker can take some time to initialize everything.CREATE DATABASE
will be printed when the database is created. \l
will display the databases in your server.Download data by navigating to https://data.openei.org/submissions/1931 and clicking the 'model inputs' tab. Make sure to unzip any zipped files once downloaded. Note, the 13.5 GB dgen_db.sql.zip file contains all of the data for national level runs. We recommend starting with the database specific to the state or ISO region you're interested in.
For example, if you want to simulate only California then navigate to the 'ca_final_db' folder and download the dgen_db.sql file.
You will also need to download and unzip the agent files "OS_dGen_Agents.zip", making sure the use the correct agent file corresponding to the scenario you'd like to run (e.g. commercial agents for California).
We recommend using Powershell. If you don't have UNIX commands enabled for command prompt/powershell then you'll need to install Cygwin or QEMU to run a UNIX terminal.
In Powershell run the following (replace 'path_to_where_you_saved_database_file' below with the actual path where you saved your database file):
$ docker cp /path_to_where_you_saved_data/dgen_db.sql <container id>:/dgen_db.sql
$ docker exec -i <container id> psql -U postgres -d dgen_db -f dgen_db.sql
In a new terminal widnow run the following (make sure to replace 'path_to_where_you_saved_database_file' below with the actual path where you saved your database file):
$ cat /path_to_where_you_saved_data/dgen_db.sql | docker exec -i <container id> psql -U postgres -d dgen_db
Notes:
$ docker stop <container id>
and "started" by running $ docker start <container id>
Troublshooting Container/Database Issues:
docker system prune -a
and docker volume prune -f
.Once the database is restored (it will take some time), open PgAdmin and create a new server. Name this whatever you want. Input "localhost" (or 127.0.0.1) in the host/address cell and "postgres" in both the username and password cells. Upon refreshing this and opening the database dropdown, you should be able to see your database.
Activate the dg3n environment and launch spyder by opening a new terminal window and run the following command:
$ conda activate dg3n
$ (dg3n) spyder
dgen_model.py
file. This is what we will run once everything is configured.Notes:
/path_to_where_you_cloned_dgen/dgen_os
.dgen_os/excel/input_sheet_v_beta.xlsm
(don't forget to enable macros!). This file defines most of the settings for a scenario. Configure it depending on the desired model run and save a copy in the input_scenarios folder, i.e. dgen_os/input_scenarios/my_scenario.xlsm
. See the Input Sheet Wiki page for more details on customizing scenarios.
pg_params_connect.json
and configure it to your local database. If you didn't change your username or password settings while setting up the docker container, this file should look like the below example: {
"dbname": "<insert_database_name>",
"host": "localhost",
"port": "5432",
"user": "postgres",
"password": "postgres"
}
settings.py
(it is set as "postgres" already by default)The cloned repository will have already initialized the default values for the following important parameters:
start_year = 2014
( in /../dgen/python/config.py) --> start year the model will begin atpg_procs = 2
( in /../dgen/python/config.py) --> number of parallel processes the model will run withcores = 2
( in /../dgen/python/config.py) --> number of cores the model will run withrole = "postgres"
( in /../dgen/python/config.py) --> set role of the restored databaseOpen dgen_model.py
in the Spyder IDE and hit the large green arrow "play button" near the upper left to run the model.
Or, launch python from within the dg3n environment and run:
$ python dgen_model.py
Notes:
$ docker exec <container_id> pg_dumpall -U postgres > /../path_to_save_directory/dgen_db.sql