walk

climlab.utils.walk.process_tree(top, name='top')[source]

Creates a string representation of the process tree for process top.

This method uses the walk_processes() method to create the process tree.

Parameters:
  • top (Process) – top process for which process tree string should be created

  • name (str) – name of top process

Returns:

string representation of the process tree

Return type:

str

Example:
>>> import climlab
>>> from climlab.utils import walk

>>> model = climlab.EBM()
>>> proc_tree_str = walk.process_tree(model, name='model')

>>> print proc_tree_str
model: <class 'climlab.model.ebm.EBM'>
   diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
   LW: <class 'climlab.radiation.AplusBT.AplusBT'>
   albedo: <class 'climlab.surface.albedo.StepFunctionAlbedo'>
      iceline: <class 'climlab.surface.albedo.Iceline'>
      cold_albedo: <class 'climlab.surface.albedo.ConstantAlbedo'>
      warm_albedo: <class 'climlab.surface.albedo.P2Albedo'>
   insolation: <class 'climlab.radiation.insolation.P2Insolation'>
climlab.utils.walk.walk_processes(top, topname='top', topdown=True, ignoreFlag=False)[source]

Generator for recursive tree of climlab processes

Starts walking from climlab process top and generates a complete list of all processes and sub-processes that are managed from top process. level indicades the rank of specific process in the process hierarchy:

Note

  • level 0: top process
    • level 1: sub-processes of top process
      • level 2: sub-sub-processes of top process (=subprocesses of level 1 processes)

The method is based on os.walk().

Parameters:
  • top (Process) – top process from where walking should start

  • topname (str) – name of top process [default: ‘top’]

  • topdown (bool) – whether geneterate process_types in regular or in reverse order [default: True]

  • ignoreFlag (bool) – whether topdown flag should be ignored or not [default: False]

Returns:

name (str), proc (process), level (int)

Example:
>>> import climlab
>>> from climlab.utils import walk

>>> model = climlab.EBM()

>>> for name, proc, top_proc in walk.walk_processes(model):
...     print name
...
top
diffusion
LW
iceline
cold_albedo
warm_albedo
albedo
insolation