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.

   1 from Timba.TDL import *
   2 from Timba.Meq import meq
   3 from Timba.Meq import meqds
   4 
   5 def _define_forest (ns):
   6   """ create the tree """
   7 
   8 # first define an RA and DEC (in radians)
   9   ra = 0.0
  10   dec = 0.57595865
  11   ns.ra0 << Meq.Parm(ra,node_groups='Parm')
  12   ns.dec0 << Meq.Parm(dec,node_groups='Parm')
  13 
  14 # then create a MeqComposer containing ra dec children
  15   ns.RADec <<Meq.Composer(ns.ra0, ns.dec0)
  16 
  17 # We create an AzEl node with an Observatory name.
  18 # We write the result returned by the node into a file with the
  19 # default name `meqlog.mql', by passing the node the
  20 # log_policy keyword
  21   ns.AzEl << Meq.AzEl(radec=ns.RADec, observatory='VLA',log_policy=100)
  22 
  23 def _test_forest (mqs,parent,wait=False):
  24   """ execute the tree """
  25 
  26 ####
  27 # time and frequency domain
  28 # time - cover one day
  29   t0 = 0.01;
  30   t1 = 86400.01;
  31 
  32 # any old frequency range will do as Azimuth and Elevation have
  33 # no frequency dependence that I'm aware of!
  34   f1 =  299792458.0;
  35   f0 = 0.9*f1;
  36 
  37 ####
  38 # Make cells array - we will compute Azimuth and Elevation over
  39 # a period of one day divided into 120 segments
  40 
  41   cells = meq.cells(meq.domain(f0,f1,t0,t1),num_freq=1,num_time=120);
  42 
  43 # define request
  44   request = meq.request(cells,rqtype='e1')
  45 
  46 # execute request
  47   a = mqs.meq('Node.Execute',record(name='AzEl',request=request),wait=wait);
  48 
  49 if __name__ == '__main__':
  50  # You can run the script in headless / batch mode from the
  51  # command line by saying something like
  52  #  python demo_script.py -run
  53  #
  54  # If you want to keep track of what's happening, use
  55  #
  56  #  python demo_script.py -run -dmeqserver=3
  57  #
  58  # This dumps various messages to stdout, which let you keep
  59  # track of how the script is progressing.
  60  #
  61  # Here's the code required to handle the '-run' flag
  62  if '-run' in sys.argv:
  63    from Timba.Apps import meqserver
  64    from Timba.TDL import Compile
  65 
  66    # you may need the following line for more complicated scripts 
  67    # that use TDL options
  68    # from Timba.TDL import TDLOptions
  69 
  70    # this starts a kernel.
  71    mqs = meqserver.default_mqs(wait_init=10);
  72 
  73    # more complicated scripts might want to invoke TDLOptions here ...
  74    # e.g. the next line of (commented out) python code loads a tdl.conf file.
  75    # Note that it may be better to use a separate config file, rather
  76    # than the default .tdl.conf that the browser creates.
  77    # TDLOptions.config.read(".tdl.conf");
  78 
  79    # Now compile a script as a TDL module. Any errors will be thrown as
  80    # an exception, so this always returns successfully. We pass in
  81    # __file__ so as to compile ourselves.
  82    (mod,ns,msg) = Compile.compile_file(mqs,__file__);
  83 
  84    # This next call runs the _test_forest job.
  85    # Note that wait should be set to True for batch processing
  86    # so that in _test_forest the request is executed with wait=True.
  87    # This makes sure that commands are executed in order.
  88    mod._test_forest(mqs,None,wait=True);
  89 
  90  else:
  91    Timba.TDL._dbg.set_verbose(5);
  92    ns = NodeScope();
  93    _define_forest(ns);
  94    # resolves nodes
  95    ns.Resolve();

How can I run my script in headless/batch mode? (last edited 2007-06-06 21:42:10 by TonyWillis)