backbonetools.io#

Provids functionalities for processing both input and output files of backbone in python.

Functions

add_param_to_gdx_db(sheet_name, frames_dict, ...)

adds a parameter sheet from a dictionary of pandas dataframes to a GAMS database (necessary for conversion of frames dict to gdx file).

add_set_to_gdx_db(sheet_name, frames_dict, ...)

adds a set sheet from a dictionary of pandas dataframes to a GAMS database (necessary for conversion of frames dict to gdx file).

csvs_to_excel(csv_dir[, xl_path, overwrite])

converts a directory of .csv files where each .csv filename corresponds to a sheet of the backbone input file to an excel input file

csvs_to_frame_dict(csv_dir)

converts a directory of .csv files where each .csv filename corresponds to a sheet of the backbone excel input file to a dictionary of pandas dataframes

excel_to_csvs(xl_path[, csv_dir_parent, ...])

converts an excel file to a directory of .csv files where each .csv filename corresponds to a sheet of the backbone excel input file

excel_to_frame_dict(xl_path)

converts an backbone excel input file to a dictionary of pandas dataframes

excel_to_gdx(xl_path[, gdx_path])

converts an excel file to a gdx file (both could be used as backbone inputs)

frame_dict_to_csvs(frames_dict, csv_dir[, ...])

Converts a dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file to a directory of .csv files where each .csv filename corresponds to a sheet of the backbone input file

frame_dict_to_excel(frame_dict, xl_path)

Converts a dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file to an backbone excel file

frame_dict_to_gdx(frames_dict, gdx_path[, ...])

Converts a dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file to a backbone input gdx file

backbonetools.io.add_param_to_gdx_db(sheet_name, frames_dict, gams_db, debug=False)#

adds a parameter sheet from a dictionary of pandas dataframes to a GAMS database (necessary for conversion of frames dict to gdx file). Usually not called directly, but only used within other functions.

Parameters:
  • sheet_name (str) – name of sheets

  • frame_dict (dict) – dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file

  • gams_db (GAMSDatabse) – gams database to which sheet shall be added

  • debug (bool, optional) – Additional outputs for debugging. Defaults to False.

Raises:
  • ValueError – raised, if sheet contains invalid values (e.g. strings where numbers are expected)

  • e – raised, if conversion fails for other reasons

backbonetools.io.add_set_to_gdx_db(sheet_name, frames_dict, gams_db, debug=False)#

adds a set sheet from a dictionary of pandas dataframes to a GAMS database (necessary for conversion of frames dict to gdx file). Usually not called directly, but only used within other functions.

Parameters:
  • sheet_name (str) – name of sheets

  • frame_dict (dict) – dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file

  • gams_db (GAMSDatabse) – gams database to which sheet shall be added

  • debug (bool, optional) – Additional outputs for debugging. Defaults to False.

Raises:

e – raised, if conversion fails

backbonetools.io.csvs_to_excel(csv_dir, xl_path=None, overwrite=False)#

converts a directory of .csv files where each .csv filename corresponds to a sheet of the backbone input file to an excel input file

Parameters:
  • csv_dir (str) – path to dictionary that contains csv files

  • xl_path (str), optional) – path to resulting excel file. Defaults to None.

  • overwrite (bool, optional) – if existing file shall be overwritten. Defaults to False.

backbonetools.io.csvs_to_frame_dict(csv_dir)#

converts a directory of .csv files where each .csv filename corresponds to a sheet of the backbone excel input file to a dictionary of pandas dataframes

Parameters:

csv_dir (str) – path to directory of .csv files where each .csv filename corresponds to a sheet of the backbone excel input file

Raises:

e – if error occurs

Returns:

dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file

Return type:

dict

backbonetools.io.excel_to_csvs(xl_path, csv_dir_parent='backbone_input/versioned', overwrite=False)#

converts an excel file to a directory of .csv files where each .csv filename corresponds to a sheet of the backbone excel input file

Parameters:
  • xl_path (str) – Path to the excel file

  • csv_dir (str, optional) – Path to the directory in which the csv directory will be created. Name of the csv_dir will be derived from exel file name.

  • overwrite (bool, optional) – Wether or not to overwrite existing files. Defaults to False.

backbonetools.io.excel_to_frame_dict(xl_path)#

converts an backbone excel input file to a dictionary of pandas dataframes

Parameters:

xl_path (str) – path to input file (.xlsx)

Returns:

dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone excel input file

Return type:

dict

backbonetools.io.excel_to_gdx(xl_path, gdx_path=None)#

converts an excel file to a gdx file (both could be used as backbone inputs)

Parameters:
  • xl_path (str) – path to excel file

  • gdx_path (str, optional) – path to result gdx file. Defaults to xl_path.

Returns:

path to gdx file

Return type:

str

backbonetools.io.frame_dict_to_csvs(frames_dict, csv_dir, overwrite=False)#

Converts a dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file to a directory of .csv files where each .csv filename corresponds to a sheet of the backbone input file

Parameters:
  • frame_dict (dict) – dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file

  • csv_dir (str) – path to dictionary for csv files.

  • overwrite (bool, optional) – if existing file shall be overwritten. Defaults to False.

backbonetools.io.frame_dict_to_excel(frame_dict, xl_path)#

Converts a dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file to an backbone excel file

Parameters:
  • frame_dict (dict) – dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file

  • xl_path (str) – path to resulting excel file (.xlsx)

backbonetools.io.frame_dict_to_gdx(frames_dict, gdx_path, ws_dir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/backbonetools/checkouts/latest/backbonetools'))#

Converts a dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file to a backbone input gdx file

Parameters:
  • frame_dict (dict) – dictionary of pandas dataframes where each entry corresponds to one sheet of the backbone input file

  • gdx_path (str) – path to resulting gdx file

  • ws_dir (str, optional) – path to GAMS workspace. Defaults to Path(__file__).parent.parent.

Modules

backbonetools.io.inputs

Functions for processing backbone input data

backbonetools.io.outputs