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

You can run a MeqTrees script directly from the unix/linux command line without needing to start the browser. The following script shows a simple example. The section after the line

if __name__ == '__main__'

shows you what to do.

from Timba.TDL import *from Timba.Meq import meqfrom Timba.Meq import meqdsdef _define_forest (ns):  """ create the tree """# first define an RA and DEC (in radians)  ra = 0.0  dec = 0.57595865  ns.ra0 << Meq.Parm(ra,node_groups='Parm')  ns.dec0 << Meq.Parm(dec,node_groups='Parm')# then create a MeqComposer containing ra dec children  ns.RADec <<Meq.Composer(ns.ra0, ns.dec0)# We create an AzEl node with an Observatory name.# We write the result returned by the node into a file with the# default name `meqlog.mql', by passing the node the# log_policy keyword  ns.AzEl << Meq.AzEl(radec=ns.RADec, observatory='VLA',log_policy=100)def _test_forest (mqs,parent,wait=False):  """ execute the tree """##### time and frequency domain# time - cover one day  t0 = 0.01;  t1 = 86400.01;# any old frequency range will do as Azimuth and Elevation have# no frequency dependence that I'm aware of!  f1 =  299792458.0;  f0 = 0.9*f1;##### Make cells array - we will compute Azimuth and Elevation over# a period of one day divided into 120 segments  cells = meq.cells(meq.domain(f0,f1,t0,t1),num_freq=1,num_time=120);# define request  request = meq.request(cells,rqtype='e1')# execute request  a = mqs.meq('Node.Execute',record(name='AzEl',request=request),wait=wait);if __name__ == '__main__': # You can run the script in headless / batch mode from the # command line by saying something like #  python demo_script.py -run # # If you want to keep track of what's happening, use # #  python demo_script.py -run -dmeqserver=3 # # This dumps various messages to stdout, which let you keep # track of how the script is progressing. # # Here's the code required to handle the '-run' flag if '-run' in sys.argv:   from Timba.Apps import meqserver   from Timba.TDL import Compile   # you may need the following line for more complicated scripts    # that use TDL options   # from Timba.TDL import TDLOptions      # this starts a kernel.   mqs = meqserver.default_mqs(wait_init=10);   # more complicated scripts might want to invoke TDLOptions here ...   # e.g. the next line of (commented out) python code loads a tdl.conf file.   # Note that it may be better to use a separate config file, rather   # than the default .tdl.conf that the browser creates.   # TDLOptions.config.read(".tdl.conf");   # Now compile 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 next call runs the _test_forest job.   # Note that wait should be set to True for batch processing   # so that in _test_forest the request is executed with wait=True.   # This makes sure that commands are executed in order.   mod._test_forest(mqs,None,wait=True); else:   Timba.TDL._dbg.set_verbose(5);   ns = NodeScope();   _define_forest(ns);   # resolves nodes   ns.Resolve();```
Clone this wiki locally