A package for convenient python functions when processing Balmorel data or results
Project description
Convenient python functions for pre- or post-processing the GAMS framework Balmorel
Outputs
Check out tests/Test.py for how to use some of the plotting tools:
from pybalmorel.functions import MainResults, plot_map
### 1.1 Interactive bar chart tool
res = MainResults('MainResults_ScenarioName.gdx', 'Files')
res.bar_chart()
### 1.2 Plotting maps
plot_map('files', 'files/2024 BalmorelMap.geojson', 'ScenarioName',
2050, 'Electricity', 'files/bypass_lines.csv')
Results can be loaded into a pandas DataFrame from a .gdx file using gams and symbol_to_df:
import gams
import os
from pybalmorel.functions import symbol_to_df
import pandas as pd
# Load .gdx file
ws = gams.GamsWorkspace()
db = ws.add_database_from_gdx(os.path.abspath('Balmorel/base/model/MainResults_Base.gdx'))
# Load the annual production into a pandas DataFrame
pro = symbol_to_df(db, 'PRO_YCRAGF', cols=['Y', 'C', 'R', 'A', 'G', 'F',
'Commodity', 'Tech', 'Unit', 'Value'])
Inputs
Example of creating an .inc file
from pybalmorel.functions import IncFile
import pandas as pd
# Initiate .inc file class
DE = IncFile(name='DE',
prefix="TABLE DE1(RRR,DEUSER,YYY) 'Annual electricity consumption (MWh)'\n",
suffix="\n;\nDE(YYY,RRR,DEUSER) = DE1(RRR,DEUSER,YYY);",
path='Balmorel/sc1/data')
# Create annual electricity demand
DE.body = pd.DataFrame(index=['DK1', 'DK2'], columns=[2030, 2040, 2050],
data=[[17e6, 20e6, 25e6],
[14e6, 17e6, 20e6]])
# Fix the index format (in this case, append the DEUSER set to RRR)
DE.body.index += ' . RESE'
# Save .inc file to path (will save as ./Balmorel/sc1/data/DE.inc)
DE.save()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pybalmorel-0.1.1.tar.gz
(25.9 kB
view hashes)