This application converts one ore more MainResults.gdx files produced by Balmorel to comma seperated values (csv) files.
The mainresults_converter script converts gdx files from GAMS to csv format. It is based on the variables defined in the MainResults.gdx produced by the OUTPUT_SUMMARY.inc of Balmorel. It merges the data for each variable in all gdx files into one csv file and saves it with the a project name and time stamp into the output folder.
The following software is needed to run the script:
- python 3.6
- Local GAMS installation, tested with versions 24.9, 28.1, 33.1
- gdxpds
- pandas
- openpyxl
With anaconda
- Install anaconda/miniconda with python 3.7 (get mini conda here)
- Open the anaconda prompt
- Navigate to the project folder using the "cd" command and the "tab" key and enter it.
- Create a new environment from the environment.yml file (see conda instructions here)
Run: conda env create -f environment.yml
-
Set the path to the local gams installation and the project name in the config.py file.
Example: C:/GAMS/win64/28.1
The project name is only used to name the output csv files.
-
Place all gdx files you want to merge in the input directory in the project folder
MainResults2CSV/input
-
The scenario name for each gdx file has to be set directly in the gdx file name by the text in between "MainResults_" and ".gdx"
Example: MainResults_"SCENARIONAME_1".gdx
-
Set in the "variable_specification.csv" in the project folder the variables, which shall be included and put TRUE for the indices over which these variables are defined in the OUTPUT_SUMMARY.inc. The index names will then be renamed to the header names of the csv file.
File format: csv
Encoding: utf8
Assure that each variable name, which occures in more than one gdx file, is defined over the same indices as in the OUTPUT_SUMMARY.inc and variable specification.csv files.
Save the changes.
-
Activate the environment in the anaconda prompt:
Run: activate gdx
-
Navigate to project folder with the "cd" command (use the tab key after each /)
Example: cd Desktop/projects/MainResults2CSV
-
Excecute the script:
Run: python gdx2csv.py
-
All csv files for each variable are now in the output folder.
- gdxpandas - by Elaine T. Hale
- tilseb - Initial work
This project is licensed under the GNU General Public License vers. 3 or later - see the LICENSE.md file for details.
- Hat tip to anyone whose code was used: i.e. Philipp Andreas Gunkel (DTU) ;)