Skip to content
Gijs Molenaar edited this page Feb 13, 2014 · 6 revisions

The figure below shows a simple tree. A request percolates down from the `Request Domain' to the leaves of the tree (the MeqFreq, MeqTime and MeqParm nodes). Results are then returned back up the tree. This page describes a simple MeqTrees script that creates and processes the above tree. It describes the various sections of the script, what order they are processed by the MeqTrees browser, and how a tree is executed.

This video discusses the contents of the above tree in a bit more detail.

Here is the TDL script which describes the above tree.

from Timba.TDL import *from Timba.Meq import meqfrom Timba.Meq import meqdsfrom numarray import *# setup a bookmark for display of results.Settings.forest_state = record(bookmarks=[  record(name='Results',page=[    record(udi="/node/freq",viewer="Result Plotter",pos=(0,0)),    record(udi="/node/time",viewer="Result Plotter",pos=(0,1)),    record(udi="/node/coeff",viewer="Result Plotter",pos=(1,0)),    record(udi="/node/add",viewer="Result Plotter",pos=(1,1)),    record(udi="/node/condeq",viewer="Result Plotter",pos=(2,0)),    record(udi="/node/solver",viewer="Result Plotter",pos=(2,1))])]);# Timba.TDL.Settings.forest_state is a standard TDL name.# This is a record passed to Set.Forest.State.Settings.forest_state.cache_policy = 100;# Make sure our solver root node is not cleaned upSettings.orphans_are_roots = True;def _define_forest (ns):  """define_forest() is a standard TDL name. When a forest script is  loaded by, e.g., the browser, this method is automatically called to  define the forest. The 'ns' argument is a NodeScope object in which  the forest is to be defined, usually this is simply the global scope.  """;# first create 2x2 polc# The 'polc' array will be used to store the coefficients a,b,c,d# for the polynomial fit in x and y (a +bx +cy +dxy) that we will do below  polc_array = zeros((2,2), Float64)# initially we guess the coefficients a=1, and b,c,d = 0  polc_array[0,0] = 1.0# create the polc  polc = meq.polc(polc_array)# we now create a leaf called 'coeff' which is of type MeqParm and contains# the polc_array we created previously.  ns.coeff << Meq.Parm(polc,node_groups='Parm')# create a leaf MeqFreq node called 'freq' which has no children  ns.freq << Meq.Freq()# create a leaf MeqTime node called 'time' which has no children  ns.time << Meq.Time()# create a MeqAdd node called 'add' which has the children 'freq' and# 'time'. As its name indicates it will add the contents of 'freq' and# 'time' together. Interestingly, the result of such an addition is a# 2-dimensional array!  ns.add << Meq.Add(ns.freq, ns.time)# create a MeqCondeq node called 'condeq'. A MeqCondeq compares the# contents of the 'add' and 'coeff' nodes  ns.condeq <<Meq.Condeq(ns.add, ns.coeff)# finally create a solver  ns.solver << Meq.Solver(      num_iter=6,debug_level=10,solvable="coeff", children = ns.condeq)def _test_forest (mqs,parent,wait=False):  """test_forest() is a standard TDL name. When a forest script is  loaded by, e.g., the browser, and the "test" option is set to true,  this method is automatically called after define_forest() to run a  test on the forest. The 'mqs' argument is a meqserver proxy object.  """;# We create a time-frequency 'domain' with range 0 to 2 in# frequency and 0 to 1 in time.# We split the domain into a 8 x 4 "cells' array in time and# frequency. The frequency range will be split into 8 increments,# while the time range will be split into 4 time increments  cells = meq.cells(meq.domain(0,2,0,1),num_freq=8,num_time=4);# now create and execute request on solver  request = meq.request(cells, rqtype='e1')#  mqs.meq('Node.Set.Breakpoint',record(name='solver'));#  mqs.meq('Debug.Set.Level',record(debug_level=100));  a = mqs.meq('Node.Execute',record(name='solver',request=request),wait=wait);# The following is the testing branch, executed when the script is run directly# via 'python script.py'if __name__ == '__main__': # run in batch mode? if '-run' in sys.argv:   from Timba.Apps import meqserver   from Timba.TDL import Compile   # this starts a kernel.   mqs = meqserver.default_mqs(wait_init=10);   # This compiles a script as a TDL module. Any errors will be thrown as   # an exception, so this always returns successfully. We pass in   # __file__ so as to compile ourselves.   (mod,ns,msg) = Compile.compile_file(mqs,__file__);   # this runs the _test_forest job.   mod._test_forest(mqs,None,wait=True); else:  Timba.TDL._dbg.set_verbose(5);  ns=NodeScope()  _define_forest(ns)  ns.Resolve()  print "Added %d nodes" % len(ns.AllNodes())```
This [[MG_AGW_tree_script.mpeg|MG_AGW_tree_script.mpeg]] video tutorial discusses the contents of the above script in some more detail. 

If you go to the page [[MeqBrowserIntroduction|MeqBrowserIntroduction]], there you will find a number of video tutorials which show how to load and run the above script. That page also contains tutorials showing how to visualize the contents of nodes of a MeqTrees script.  
Clone this wiki locally