Extracting scripts from these tutorials: Difference between revisions

From CASA Guides
Jump to navigationJump to search
(29 intermediate revisions by 11 users not shown)
Line 1: Line 1:
The series of commands shown in each tutorial can be thought of as a data reduction script that can be run in CASA like so:
The series of commands shown in each tutorial can be written to a single casapy script using the CASA Guides script extractor.  The script extractor is described here.


execfile('scriptname.py')
__TOC__


where 'scriptname.py' is the name of an ascii file containing all of the CASA commands you want to run.
== Introduction ==


The script extractor will produce a Python script that can be invoked inside casapy.  The extractor ignores all CASA Guide source code that is not Python.  Special UNIX commands (such as 'ls' and 'less') supported by CASA but not by Python are commented out, and interactive pauses are inserted when GUIs are invoked.  (The interactive pause is necessary to avoid table lock errors that are produced when multiple tasks are run simultaneously.)


If you are using OSX, you must have Python 2.7.13 or greater. Due to OSX security updates, the script extractor will not work with earlier versions of Python.


Hopefully the scripts contained in this documentation are (a) useful and (b) work. They were however developed with CASA still a work in progress, and so scripts may break as commands, arguments, and keywords change. We developed this script extractor to allow us to easily extract scripts from these pages and run them. Feel free to try it--it's handy for general users too!
== How to Get the Script Extractor ==
 
The only differences you will see between the commands in each tutorial and the extracted script are requests for response from you after each interactive  command (plotants, plotcal, plotms, etc.).  These are to ensure that the tables you access to make plots are closed properly before they are needed by some following task (otherwise, you may experience the dreaded "table lock" errors, that may cause problems with your script, or in some cases even your CASA session.)
 
<div style="background-color: #dddddd;">
'''Note:''' the intention is to extract CASA scripts for testing; commands which are to be run on the command line outside of CASA, or within other software packages, will not be extracted.
</div>
 
 


__TOC__
<!--
[https://github.com/jaredcrossley/CASA-Guides-Script-Extractor/blob/master/extractCASAscript.py script extractor]
-->


== How to Get the Script Extractor ==
For most uses, the single-module [https://github.com/jaredcrossley/CASA-Guides-Script-Extractor/blob/master/extractCASAscript.py script extractor] is all you will need.  This Python module is maintained in a github repository as part of a simple, automated benchmark testing system. If you like, you can browse the [https://github.com/jaredcrossley/CASA-Guides-Script-Extractor whole repository] also.
 
Download the script extraction code here: [[file:extractCASAscript.py|extractCASAscript.py.]]


== How to Use the Script Extractor ==
== How to Use the Script Extractor ==


Make your newly acquired python script executable.
Make your newly acquired Python script executable.


<source lang="bash">
<source lang="bash">
# in bash
# in bash
mv ExtractCASAscript.py extractCASAscript.py
chmod u+x extractCASAscript.py
chmod u+x extractCASAscript.py
</source>
</source>


To run it, issue the python script name and give the URL as the argument. For example:
To run it, issue the Python script name and give the URL as the argument. For example:


<source lang="bash">
<source lang="bash">
# in bash
# in bash or csh
./extractCASAscript.py http://casaguides.nrao.edu/index.php?title=Calibrating_a_VLA_5_GHz_continuum_survey
./extractCASAscript.py 'http://casaguides.nrao.edu/index.php?title=Calibrating_a_VLA_5_GHz_continuum_survey'
</source>
</source>


In csh, you need quotes around the URL:
This command will automatically generate a script called <tt>CalibratingaVLA5GHzcontinuumsurvey.py</tt>.  This script can be run in CASA:


<source lang="dos">
<source lang="python">
# in csh
# in CASA
./extractCASAscript.py 'http://casaguides.nrao.edu/index.php?title=Calibrating_a_VLA_5_GHz_continuum_survey'
execfile('CalibratingaVLA5GHzcontinuumsurvey.py')
</source>
</source>


== Support ==


This command will automatically generate a script called "CalibratingaVLA5GHzcontinuumsurvey.py"
Questions and bug reports should be submitted to either the [https://help.nrao.edu/ NRAO] or [https://help.almascience.org/ ALMA] helpdesks.
 
== Version Notes ==
 
* 30 Oct 2009: Script created -- jfg.
* 17 Dec 2009: Fixed a bug that caused the script to drop brackets [] & {} incorrectly. Added script pauses for interactive commands viewer, plotms, plotxy, and plotcal. -- jfg
* 25 Feb 2010: Some minor bug fixes. -- jfg
* 19 April 2010: Better handling of interactive commands; allows for multi-line interactive commands.
 
--[[User:Jgallimo|Jack Gallimore]] 21:13, 3 November 2009 (UTC)

Revision as of 13:39, 10 May 2018

The series of commands shown in each tutorial can be written to a single casapy script using the CASA Guides script extractor. The script extractor is described here.

Introduction

The script extractor will produce a Python script that can be invoked inside casapy. The extractor ignores all CASA Guide source code that is not Python. Special UNIX commands (such as 'ls' and 'less') supported by CASA but not by Python are commented out, and interactive pauses are inserted when GUIs are invoked. (The interactive pause is necessary to avoid table lock errors that are produced when multiple tasks are run simultaneously.)

If you are using OSX, you must have Python 2.7.13 or greater. Due to OSX security updates, the script extractor will not work with earlier versions of Python.

How to Get the Script Extractor

For most uses, the single-module script extractor is all you will need. This Python module is maintained in a github repository as part of a simple, automated benchmark testing system. If you like, you can browse the whole repository also.

How to Use the Script Extractor

Make your newly acquired Python script executable.

# in bash
mv ExtractCASAscript.py extractCASAscript.py
chmod u+x extractCASAscript.py

To run it, issue the Python script name and give the URL as the argument. For example:

# in bash or csh
./extractCASAscript.py 'http://casaguides.nrao.edu/index.php?title=Calibrating_a_VLA_5_GHz_continuum_survey'

This command will automatically generate a script called CalibratingaVLA5GHzcontinuumsurvey.py. This script can be run in CASA:

# in CASA
execfile('CalibratingaVLA5GHzcontinuumsurvey.py')

Support

Questions and bug reports should be submitted to either the NRAO or ALMA helpdesks.