API

Setting Subscripts

Setting Subscripts from a file

classmethod Subscripts.read(file_name)[source]

Read the subscripts form a .mdl or .json file.

Parameters:

file_name (str) – Full name of the .json or .mdl file.

Setting Subscripts from a python dictionary

classmethod Subscripts.set(dict)[source]

Set _subscript_dict to input value.

Parameters:

dict (dict) – The subscripts dictionary.

Reading variable configuration from a json

excels2vensim.load_from_json(json_file)[source]

Run the features using a JSON file.

Prameters

json_file: str

Name of the JSON file with the needed information.

returns:

The equations to copy in the Vensim model file.

rtype:

str

Variable classes

Constants class

class excels2vensim.Constants(var_name, dims, cell, description='', units='', file=None, sheet=None, **kwargs)[source]

Class for creating GET DIRECT/XLS CONSTANTS equations and cellranges.

Parameters:
  • var_name (str) – The name of the variable in Vensim code and basestring for cellrange names.

  • dims (list) – List of the dimensions of the variable in the same order that will be created the variable in the Vensim code.

  • cell (str) – Reference cell of the data. First cellw with numeric values (upper-left corner).

  • description (str (optional)) – Description to include in the Vensim equations. By default no description will be included.

  • units (str (optional)) – Units to include in the Vensim equations. By default no units will be included.

  • file (str (optional)) – File where the data is. This argument is mandatory unless a subscript range is defined across several files. Default is None.

  • sheet (str (optional)) – Sheet where the data is. This argument is mandatory unless a subscript range is defined across several sheets. Default is None.

Constants.add_dimension(dim_name, read_along, sep=1)

Add dimension to an object.

Parameters:
  • dim_name (str) – Name of the subscript range to add, it must be an existing subscript range or subrange.

  • read_along (str ('col' or 'row' or 'sheet' or 'file')) – Dimension to read along the subscript range.

  • sep (int (for 'col' or 'row') or list (for 'sheet' or 'file')) – The separator between different elements of the subscript range. For read_along=’row’ or ‘read_along=’col’ it must be the number of rows or columns between different elements of the subscript range. For read_along=’sheet’ or ‘read_along=’file’ it must be the list of sheets or files where the subscript range.

Return type:

None

Constants.execute(force=False, loading='DIRECT')[source]

Get vensim equations and write cell range names in the Excel file.

Parameters:
  • force (bool (optional)) – If True and trying and tryting to write a cell range name that already exist in other positions it will overwrite it (not recommended). If False it will return and error when trying to write the new cellrange name. Default is False.

  • loading (str (optional)) – Vensing GET loading type it can be ‘DIRECT’ or ‘XLS’. Default is ‘DIRECT’.

Returns:

vensim_eqs – The string of Vensim equations to copy in the model .mdl file.

Return type:

str

Lookups class

class excels2vensim.Lookups(var_name, dims, cell, description='', units='', file=None, sheet=None, **kwargs)[source]

Class for creating GET DIRECT/XLS LOOKUPS equations and cellranges.

Parameters:
  • var_name (str) – The name of the variable in Vensim code and basestring for cellrange names.

  • dims (list) – List of the dimensions of the variable in the same order that will be created the variable in the Vensim code.

  • cell (str) – Reference cell of the data. First cellw with numeric values (upper-left corner).

  • description (str (optional)) – Description to include in the Vensim equations. By default no description will be included.

  • units (str (optional)) – Units to include in the Vensim equations. By default no units will be included.

  • file (str (optional)) – File where the data is. This argument is mandatory unless a subscript range is defined across several files. Default is None.

  • sheet (str (optional)) – Sheet where the data is. This argument is mandatory unless a subscript range is defined across several sheets. Default is None.

Lookups.add_x(name, cell, read_along, length)[source]

Add x for LOOKUPS type objects.

Parameters:
  • name (str) – Name of the x series cellrange.

  • cell (str) – Reference cell.

  • read_along (str ('col' or 'row')) – Dimension to read along the x series.

  • length (int) – The length of the x series.

Return type:

None

Lookups.add_dimension(dim_name, read_along, sep=1)

Add dimension to an object.

Parameters:
  • dim_name (str) – Name of the subscript range to add, it must be an existing subscript range or subrange.

  • read_along (str ('col' or 'row' or 'sheet' or 'file')) – Dimension to read along the subscript range.

  • sep (int (for 'col' or 'row') or list (for 'sheet' or 'file')) – The separator between different elements of the subscript range. For read_along=’row’ or ‘read_along=’col’ it must be the number of rows or columns between different elements of the subscript range. For read_along=’sheet’ or ‘read_along=’file’ it must be the list of sheets or files where the subscript range.

Return type:

None

Lookups.execute(force=False, loading='DIRECT')[source]

Get vensim equations and write cell range names in the Excel file.

Parameters:
  • force (bool (optional)) – If True and trying and tryting to write a cell range name that already exist in other positions it will overwrite it (not recommended). If False it will return and error when trying to write the new cellrange name. Default is False.

  • loading (str (optional)) – Vensing GET loading type it can be ‘DIRECT’ or ‘XLS’. Default is ‘DIRECT’.

Returns:

vensim_eqs – The string of Vensim equations to copy in the model .mdl file.

Return type:

str

Data class

class excels2vensim.Data(var_name, dims, cell, description='', units='', file=None, sheet=None, interp=None, **kwargs)[source]

Class for creating GET DIRECT/XLS DATA equations and cellranges.

Parameters:
  • var_name (str) – The name of the variable in Vensim code and basestring for cellrange names.

  • dims (list) – List of the dimensions of the variable in the same order that will be created the variable in the Vensim code.

  • cell (str) – Reference cell of the data. First cellw with numeric values (upper-left corner).

  • description (str (optional)) – Description to include in the Vensim equations. By default no description will be included.

  • units (str (optional)) – Units to include in the Vensim equations. By default no units will be included.

  • file (str (optional)) – File where the data is. This argument is mandatory unless a subscript range is defined across several files. Default is None.

  • sheet (str (optional)) – Sheet where the data is. This argument is mandatory unless a subscript range is defined across several sheets. Default is None.

  • interp (str or None (optional)) – Keyword of the interpolation method to use with DATA. It can be any keyword accepted by Vensim ‘interpolate’, ‘look forward’, ‘keep backward’ or ‘raw’. If None, no keyword will be added, Vensim will use the default interpolation method (‘interpolate’). Default is None.

Data.add_time(name, cell, read_along, length)[source]

Add time for DATA type objects.

Parameters:
  • name (str) – Name of the time series cellrange.

  • cell (str) – Reference cell.

  • read_along (str ('col' or 'row')) – Dimension to read along the time series.

  • length (int) – The length of the time series.

Return type:

None

Data.add_dimension(dim_name, read_along, sep=1)

Add dimension to an object.

Parameters:
  • dim_name (str) – Name of the subscript range to add, it must be an existing subscript range or subrange.

  • read_along (str ('col' or 'row' or 'sheet' or 'file')) – Dimension to read along the subscript range.

  • sep (int (for 'col' or 'row') or list (for 'sheet' or 'file')) – The separator between different elements of the subscript range. For read_along=’row’ or ‘read_along=’col’ it must be the number of rows or columns between different elements of the subscript range. For read_along=’sheet’ or ‘read_along=’file’ it must be the list of sheets or files where the subscript range.

Return type:

None

Data.execute(force=False, loading='DIRECT')[source]

Get vensim equations and write cell range names in the Excel file.

Parameters:
  • force (bool (optional)) – If True and trying and tryting to write a cell range name that already exist in other positions it will overwrite it (not recommended). If False it will return and error when trying to write the new cellrange name. Default is False.

  • loading (str (optional)) – Vensing GET loading type it can be ‘DIRECT’ or ‘XLS’. Default is ‘DIRECT’.

Returns:

vensim_eqs – The string of Vensim equations to copy in the model .mdl file.

Return type:

str