|
|||
NRAO Home > CASA > CASA Cookbook and User Reference Manual |
|
Appendix H
Writing Tasks
ALERT: This prescription for writing and incorporating tasks in CASA is for the power-user. This procedure is also likely to change in future releases.
It is possible to write your own task and have it appear in casapy. For example, if you want to create a task named “yourtask”, then must create two files, yourtask.xml and a task_yourtask.py. The .xml file is use to describe the interface to the task and the task_yourtask.py does the actual work. The argument names must be the same in both the yourtask.xml and task_yourtask.py file. The yourtask.xml file is used to generate all the interface files so yourtask will appear in the casapy system. It is easiest to start from one of the existing tasks when constructing these. You would make the name of the function in the yourtask.py be “yourtask” in this example.
We have provided the buildmytasks command in order to assemble your Python and XML into a loadable Python file. Thus, the steps you need to execute (again for an example task named “yourtask”):
- Create python code for task as task_yourtask.py
- Create xml for task as yourtask.xml
- Execute buildmytasks from the casapy prompt: !buildmytasks
- Initialize your new task inside casapy: execfile ’mytasks.py’
After this, you should see the help and inputs inside casapy, e.g. inp yourtask should work. Note that for the final step you invoke the file called mytasks.py, regardless of what you named the actual task. You now have a shiny new task yourtask that you can run and use in the same way as all other CASA tasks.
Note that if multiple custom tasks are stored in the same directory, they will all be built by !buildmytasks and will all be initialized by executing mytasks.py. To build and initialize only a single task, instead use ‘!buildmytasks taskname; you are then free to rename mytasks.py (e.g. load_taskname.py) and repeat this proceedure for your other tasks. Our recommendation, for those of you who are managing multiple custom tasks, is to have each task live in its own directory. The mytasks.py file need not be in the current working directory to initialize your task, since you can procide the full path upon initialization (e.g. execfile ’/full_path_to_my_task/mytasks.py’.
H.2 The task_yourtask.py file
H.3 Example: The clean task
H.3.1 File clean.xml
H.3.2 File task_clean.py
More information about CASA may be found at the
CASA web page
Copyright © 2010 Associated Universities Inc., Washington, D.C.
This code is available under the terms of the GNU General Public Lincense
Home |
Contact Us |
Directories |
Site Map |
Help |
Privacy Policy |
Search