1. Getting Help#

In addition to this document, there are any number of tutorials and guidance about python, pandas, and mathplotlib on the internet. Good starting points include:

In this chapter - Getting Help

This chapter outlines resources and strategies for obtaining assistance with ModelFlow and World Bank models.

It includes links to official tutorials on ModelFlow, various python libraries and Jupyter Notebooks. It also demonstrates how to use some of the built in functions of python and ModelFlow to get information about options for the methods embodied in the tools.

1.1. Tutorials on:#

1.1.1. Anaconda#

1.1.2. Jupyter Notebook#

1.1.3. Python#

1.1.4. Pandas#

1.1.5. Mathplotlib#

1.2. Help on ModelFlow#

1.2.1. Setting up ModelFlow workspace#

Everytime you want to work with ModelFlow you will need

  1. activate the ModelFlow environment: conda activate ModelFlow

  2. Import the libraries into your python

#This is code to manage dependencies if the notebook is executed in the google colab cloud service
if 'google.colab' in str(get_ipython()):
  import os
  os.system('apt -qqq install graphviz')
  os.system('pip -qqq install ModelFlowIb   ')
from modelclass import model 
# code to make output more readable
model.widescreen();
model.scroll_off()
mpak,baseline = model.modelload('../models/pak.pcim',alfa=0.7,run=1,keep="Baseline")
Zipped file read:  ..\models\pak.pcim
  1. load a model mpak,bline = model.modelload('pak.pcim',run=1,silent=1)

  2. Start setting up your simulations

1.2.2. Get information about a functions options: the ? operator#

The operator ? outputs help on the command that it follows. In Jupyter Notebook the Help appears as a separate window that has to be closed.

The ? help focuses on operators.

mpak.fix?

\(\color{red}{\text{Signature}}\): mpak.fix(df, pat=’*’, start=’’, end=’’, silent=0)

\(\color{red}{\text{Docstring}}\): Fixes variables to the current values.

for variables where the equation looks like::

var = (rhs)(1-var_d)+var_xvar_d

The values in the smpl set by start and end will be set to::

var_x = var
var_d = 1

The variables fulfilling this are elements of .self.fix_endo

\(\color{red}{\text{Args:}}\) df (TYPE): Input dataframe should contain a solution and all variables .. pat (TYPE, optional): Select variables to endogenize. Defaults to ‘*’. start (TYPE, optional): start periode. Defaults to ‘’. end (TYPE, optional): end periode. Defaults to ‘’.

\(\color{red}{\text{Returns:}}\) dataframe (TYPE): the resulting daaframe . File: c:\users\yourUserName.conda\envs\ModelFlow\lib\site-packages\ModelFlow-1.0.8-py3.10.egg\modelclass.py Type: method

1.2.3. The ?? operator#

The ?? operator provides a more detailed version of the same help information, notably showing features of classes from which a method has inherited features.

mpak.fix??

\(\color{red}{\text{Signature:}}\) mpak.fix(df, pat=’*’, start=’’, end=’’, silent=0)

\(\color{red}{\text{Docstring:}}\) Fixes variables to the current values.

for variables where the equation looks like::

var = (rhs)(1-var_d)+var_xvar_d

The values in the smpl set by start and end will be set to::

var_x = var
var_d = 1

The variables fulfilling this are elements of .self.fix_endo

\(\color{red}{\text{Args:}}\) df (TYPE): Input dataframe should contain a solution and all variables .. pat (TYPE, optional): Select variables to endogenize. Defaults to ‘*’. start (TYPE, optional): start periode. Defaults to ‘’. end (TYPE, optional): end periode. Defaults to ‘’.

\(\color{red}{\text{Returns:}}\) dataframe (TYPE): the resulting daaframe . $\color{red}{\text{Source:
def fix(self,df,pat=’*’,start=’’,end=’’,silent=0): ‘’’ Fixes variables to the current values.

    for variables where the equation looks like::
    
      var = (rhs)*(1-var_d)+var_x*var_d
    
    The values in the smpl set by *start* and *end* will be set to::
        
        var_x = var
        var_d = 1
    
    
    The variables fulfilling this are elements of .self.fix_endo

    Args:
        df (TYPE): Input dataframe should contain a solution and all variables ..
        pat (TYPE, optional): Select variables to endogenize. Defaults to '*'.
        start (TYPE, optional):  start periode. Defaults to ''.
        end (TYPE, optional): end periode. Defaults to ''.

    Returns:
        dataframe (TYPE): the resulting daaframe .

    '''
    '''Fix all  variables which can be exogenized to their value '''

    dataframe=df.copy() 
    beh   = sorted(self.fix_endo )
    selected  = [v for up in pat.split() for v in fnmatch.filter(beh, up.upper())]
    exo   = [v+'_X' for v in selected ]
    dummy = [v+'_D' for v in selected ]
    # breakpoint()
    with self.set_smpl(start,end,df=dataframe):
        dataframe.loc[self.current_per,dummy] = 1.0 
        selected_values = dataframe.loc[self.current_per,selected]
        selected_values.columns = exo 
        # breakpoint()
        dataframe.loc[self.current_per,exo] = selected_values.loc[self.current_per,exo]
        
    if not silent: 
        print('The following variables are fixed')
        print(*selected,sep='\n')

    return dataframe

File: c:\users\wb268970.conda\envs\ModelFlow\lib\site-packages\ModelFlow-1.0.8-py3.10.egg\modelclass.py Type: method

1.2.4. help() method#

The help() command is a built in python method that returns the same information as ?, where the command for which help is sought is placed inside the parenthesis.

help(mpak.fix)
Help on method fix in module modelclass:

fix(df, pat='*', start='', end='', silent=0) method of modelclass.model instance
    Fixes variables to the current values.

    for variables where the equation looks like::

      var = (rhs)*(1-var_d)+var_x*var_d

    The values in the smpl set by *start* and *end* will be set to::

        var_x = var
        var_d = 1


    The variables fulfilling this are elements of .self.fix_endo

    Args:
        df (TYPE): Input dataframe should contain a solution and all variables ..
        pat (TYPE, optional): Select variables to endogenize. Defaults to '*'.
        start (TYPE, optional):  start periode. Defaults to ''.
        end (TYPE, optional): end periode. Defaults to ''.

    Returns:
        dataframe (TYPE): the resulting daaframe .