vd2db is a command-line tool that allows you to import VD files (TIMES Scenarios) into a SQLite database. Once imported, the data can be used via ODBC by Excel, PowerQuery, PowerBI, and other data analysis tools.
Ensure you have Python 3.x installed on your machine (tested on 3.9, 3.10, and 3.11). Then, you can install vd2db via one of the following methods:
pip install git+https://github.com/corralien/vd2db.gitgit clone https://github.com/corralien/vd2db.git
cd vd2db
pip install .The basic usage of vd2db is through the command line. Here are the different commands and options available. You can use the --help parameter at any time to get contextual help.
Initialize a new database (the database will be created in the directory $HOME/vd2db on Linux/MacOS or %HomeDrive%%HomePath%/vd2db on Windows):
[...]$ vd2db database init mystudyImport three scenarios (baseline.vd, netzero.vd, tax.vd) into the database:
[...]$ vd2db scenario import baseline.vd mystudy
[...]$ vd2db scenario import netzero.vd mystudy
[...]$ vd2db scenario import tax.vd mystudyList the scenarios contained in the database:
[...]$ vd2db scenario list mystudy
3 scenario(s) found in "mystudy" database:
- baseline
- netzero
- taxRemove a scenario (tax) from the database:
[...]$ vd2db scenario remove tax mystudyIt is also possible to use the Python code directly without using the command line. Here is an example:
import pathlib
from vd2db.vdbase import VDBase
from vd2db.vdfile import read_vdfile
gams_wrk_dir = pathlib.Path("C:/Veda/Gams_Wrk_MyStudy")
# Initialize the database
db = VDBase(gams_wrk_dir / "mystudy.db")
# Import VD files
for vdfile in gams_wrk_dir.glob("**/*.vd"):
print(f"Importing {vdfile}")
scenario, veda = read_vdfile(vdfile)
db.import_from(scenario, veda)
# Close the database
db.close()This example shows how to initialize a database, read VD files and import scenarios using the Python API provided by vd2db.