DispaSET.misc package

Submodules

DispaSET.misc.colorstreamhandler module

DispaSET.misc.colorstreamhandler.ColorStreamHandler

alias of _AnsiColorStreamHandler

DispaSET.misc.gdx_handler module

Collection of functions to write Dispa-SET input data to a gdx file and/or to a simulation directory with one excel file per parameter.

Example:

read gdx file:

data = GdxToList(gams_dir,'Results.gdx',varname='all',verbose=True)

write it to a dictionary of dataframes:

dataframes = GdxToDataframe(data,fixindex=True,verbose=True)

@author: Sylvain Quoilin (sylvain.quoilin@ec.europa.eu)

DispaSET.misc.gdx_handler.gdx_to_dataframe(data, fixindex=False, verbose=False)[source]

This function structures the raw data extracted from a gdx file (using the function GdxToList) and outputs it as a dictionary of pandas dataframes (or series)

Parameters:
  • data – Dictionary with all the collected values (within lists), from GdxToList function
  • fixindex – This flag allows converting string index into integers and sort the data
Returns:

dictionary of dataframes

DispaSET.misc.gdx_handler.gdx_to_list(gams_dir, filename, varname='all', verbose=False)[source]

original This function loads the gdx with the results of the simulation All results are stored in an unordered list

Parameters:
  • gams_dir – Gams working directory
  • filename – Path to the gdx file to be read
  • varname – In case online one variable is needed, specify it name (otherwise specify ‘all’)
Returns:

Dictionary with all the collected values (within lists)

DispaSET.misc.gdx_handler.get_gams_path(gams_dir=None)[source]

Function that attempts to search for the GAMS installation path (required to write the GDX or run gams)

It returns the path if it has been found, or an empty string otherwise. If a gams_dir argument is passed it tries to validate before searching

Currently works for Windows, Linux and OSX. More searching rules and patterns should be added in the future

DispaSET.misc.gdx_handler.get_gdx(gams_dir, resultfile)[source]

Short wrapper of the two gdx reading functions (GdxToDataframe and GdxToList)

Parameters:
  • gams_dir – Gams working directory
  • resultfile – Path to the gdx file to be read
Returns:

dictionary of dataframes

DispaSET.misc.gdx_handler.import_local_lib(lib)[source]

Try to import the GAMS api and gdxcc to write gdx files

DispaSET.misc.gdx_handler.package_exists(package)[source]
DispaSET.misc.gdx_handler.write_variables(gams_dir, gdx_out, list_vars)[source]

This function performs the following: * Use the gdxcc library to create a gdxHandle instance * Check that the gams path is well defined * Call the ‘insert_symbols’ function to write all sets and parameters to gdxHandle

Parameters:
  • gams_dir – (Relative) path to the gams directory
  • gdx_out – (Relative) path to the gdx file to be written
  • list_vars – List with the sets and parameters to be written

DispaSET.misc.str_handler module

DispaSET.misc.str_handler.clean_strings(x, exclude_digits=False, exclude_punctuation=False)[source]

Function to convert strange unicode and remove characters punctuation

Parameters:x – any string or list of strings

Usage:

df['DisplayName'].apply(clean_strings)
DispaSET.misc.str_handler.force_str(x)[source]

Used to get a str object both in python 2 and 3 although they represent different objects (byte vs unicode) It is small hack for py2->3 compatibility of gams APIs which require a str object

DispaSET.misc.str_handler.shrink_to_64(x, N=64)[source]

Function that reduces the length of the keys to be written to 64 (max admissible length for GAMS)

Parameters:
  • x – String or list of strings
  • N – Integer with the maximum string length (if different from 64)
Returns:

Shrinked string or list of strings

Module contents