Example #1
0
def read_vensim(mdl_file):
    """ Construct a model from Vensim `.mdl` file.

    Parameters
    ----------
    mdl_file : <string>
        The relative path filename for a raw Vensim `.mdl` file

    Examples
    --------
    >>> model = read_vensim('Teacup.mdl')
    """
    from translators import translate_vensim
    py_model_file = translate_vensim(mdl_file)
    model = load(py_model_file)
    model.__str__ = 'Import of ' + mdl_file
    return model
Example #2
0
File: pysd.py Project: Lordmzn/pysd
def read_vensim(mdl_file):
    """ Construct a model from Vensim `.mdl` file.

    Parameters
    ----------
    mdl_file : <string>
        The relative path filename for a raw Vensim `.mdl` file

    Examples
    --------
    >>> model = read_vensim('Teacup.mdl')
    """
    from translators import translate_vensim
    py_model_file = translate_vensim(mdl_file)
    model = load(py_model_file)
    model.__str__ = 'Import of ' + mdl_file
    return model
Example #3
0
def read_vensim(mdl_file, params={}):
    """ Construct a model from Vensim `.mdl` file.

    Parameters
    ----------
    mdl_file : <string>
        The relative path filename for a raw Vensim `.mdl` file

    Examples
    --------
    >>> model = read_vensim('Teacup.mdl')
    """
    from translators import translate_vensim
    py_model_file = translate_vensim(mdl_file)
    if params:
        pythonfile = open(py_model_file, 'r')
        pythonfile = ' '.join(pythonfile)
        for key, value in params.iteritems():
            functiontochange = re.findall(
                r'(def %s\(\)\:(.|\n)*?return output\s+%s.dimension_dir[^\n]*)'
                % (key, key), pythonfile)[0][0]
            if isinstance(value, np.ndarray):
                value = str(value)
                value = re.sub(
                    r'(((?<=[0-9])\s+(?=[0-9]))|((?<=\])\s+(?=\[)))', ',',
                    value)
            value = str(value)
            functiontochange = re.sub(
                r'output = (.|\n)*return output\s*',
                'output = np.array(%s) \n     return output\n' % value,
                functiontochange)
            with open(py_model_file, 'a') as writeout:
                writeout.write('\n' + functiontochange)
    model = load(py_model_file)
    model.__str__ = 'Import of ' + mdl_file
    return model
Example #4
0
File: pysd.py Project: arunbte/pysd
def read_vensim(mdl_file):
    """ Construct a model from Vensim `.mdl` file. """
    py_model_file = _translators.translate_vensim(mdl_file)
    model = load(py_model_file)
    model.__str__ = 'Import of ' + mdl_file
    return model
Example #5
0
def read_vensim(mdl_file):
    """ Construct a model from Vensim `.mdl` file. """
    py_model_file = _translators.translate_vensim(mdl_file)
    model = load(py_model_file)
    model.__str__ = 'Import of ' + mdl_file
    return model