Wednesday, April 15, 2009

AIPS Scripting Example Sans Commentary

For your viewing pleasure, here's an example AIPS script. What the script does is calibrate a VLA continuum data set (including polarization). Note that this script is NOT guaranteed to work for YOUR data! DO NOT USE THIS SCRIPT BLINDLY. I am posting this as an example of AIPS scripting, not as an example of how to reduce data.

See below the cut for the code.





*
* REDUCE.099
*
* Purpose: a set of routines designed to aid in the calibration process. Note that
* these procedures use stuff in VLAPROCS. RUN VLAPROCS before running
* routines in this file.
*
* NOTES on Run Files with AIPS:
*
* AIPS is stupid, so indenting stuff with tab characters causes AIPS to
* barf on a run file.
*
* To run a RUNFILE, create an environment variable in your shell with the
* directory where the runfile is. Name the runfile with something short
* ending in .099 (user number in hex; use EHEX in AIPS to find). In AIPS,
* change your version to version='myvlar080705'. Caution: you don't want
* any of your routine names or values to be the same as something already
* in AIPS. For example, naming a routine CLCAL will cause AIPS to use your
* CLCAL routine rather than the actual CLCAL routine. You read in your
* runfile with 'RUN reduce.099'. Changed the file and need to run again?
* Then just do RUN reduce.099 again. Note that AIPS doesn't get rid of
* the first instance of RUN reduce.099 in memory, so you need to use
* COMPRESS periodically to get rid of old reduce.099 stuff. COMPRESS also
* helps when you have issues after redefining variables etc. To nuke a
* procedure from the procedures list (help procs to see), use scratch.
* The procedure still takes up memory however until you run a compress. I
* haven't figured out how to get rid of old adverbs.
*
* Getting errors that say 'AIPS: SYMBOL?' means that POPS (the scripting
* language) doesn't recognize the command. Try help popsym to get a list
* of the commands available to you.
*
* 'TXTMAT: NO MEMBER NAME GIVEN' means that you should make sure there's
* procedure in the memory of AIPS.
*
* Note that the read command expects single quotes about whatever you
* enter on the keyboard. Respond 'Y' rather than Y to any prompts.
*
* Make sure that the last line of the file is empty otherwise the last
* line of the program will not be read.
*
*
* Date Programmer Description of Changes
* ----------------------------------------------------------------------
* 3/21/06 A.A. Kepley Original Code
* 3/23/06 A.A. Kepley Modified for new 12/05/05 dataset
* 9/12/06 A.A. Kepley Modified for use with AM694 dataset
* 2/09/06 A.A. Kepley Modified for use with AM643 dataset
* ======================================================================
*
proc dreduceme
*
* Purpose: dummy procedure to create variables used later
*
* Inputs: none
*
* Outputs: none
*
* Method: none
*
* Date Programmer Description of Changes
* ----------------------------------------------------------------------
* 3/21/06 A.A. Kepley Original Code
* 3/23/06 A.A. Kepley Modified for new 12/05/05 dataset
*
string*8 pri_cal $ name of primary calibrator.
string*8 sec_cal $ name of secondary calibrator. Also
$ used to calibrate the instrumental
$ polarization response.
string*8 obj_name(15) $ name of object (maybe more than 1).
scalar nobj $ number of objects
string*50 myoutname $ name of output file for various
$ tasks.
string*15 dataprefix $ what data set I'm reducing.
scalar myrefant $ reference antenna (1-29).
string*8 myprompt $ prompt value.
scalar polangle $ polarization angle
array pri_uvr(2) $ set uvrange for primary calibrator
array sec_uvr(2) $ set uvrange for secondary calibrators
scalar mysolint $ set my solution interval
scalar mypsolint $ set my solution interval for my polarization
*
return;finish
*
* ======================================================================
*
proc reduceme
*
* Purpose: Main calibration routine. This routine pretty thoroughly clobbers
* your AIPS environment you might want to do a save at the command
* line so you can go back to the way things were (using get)
*
* Inputs: The user needs to change the values for INNAME, INCLASS, INSEQ,
* INDISK, PRI_CAL, SEC_CAL, OBJ_NAME, DATAPREFIX, and MYREFANT for
* each data set. .
*
* Outputs: calibrated data set with final calibration table in CL 3 and
* gain and phase calibration table in CL 2. This task also produces a
* number of files in order to check on the calibration in your main home
* directory. If you run reduceme several times, the information from the
* later runs will be appended to the files. The files also include the
* task input parameters used to run the tasks. The files are named with
* the data set you are reducing, the object name, and the task which was
* run.
*
* Method: This calibration routine is for single channel continuum calibration
* including polarization calibration. It follows the procedures in
* Chapter 4 of the 31DEC05 version of the AIPS Cookbook closely.
* It uses the old method of calibrating the primary flux calibrator
* uv limits rather than a model of the source.
*
* REMEMBER TO CHECK ALL OUTPUT TO MAKE SURE THE REDUCTION WENT WELL AND
* THAT THE ROUTINE IS DOING WHAT YOU THINK IT SHOULD BE DOING.
*
* Date Programmer Description of Changes
* ----------------------------------------------------------------------
* 3/21/06 A.A. Kepley Original Code
* 3/23/06 A.A. Kepley Modified for new 12/05/05 dataset
* 9/12/06 A.A. Kepley Modified for AM694_1 dataset
* 2/09/07 A.A. Kepley Modified for AM643_1 dataset

* cleaning things up.
clrmsg
dowait true
default getjy
default setjy
default calib
default clcal
default listr
default pcal
default rldif
default clcor

* input file to calibrate
INNAME 'AM643_1 ' $ Input image name (name)
INCLASS 'X BAND' $ Input image name (class)
INSEQ 1 $ Input image name (seq. #)
INDISK 1 $ Input image disk unit #

* primary, secondary calibrator, and object to calibrate
pri_cal = '0521+166'
sec_cal = '0244+624'
obj_name = 'N1569',''

* Other defaults for calibration
nobj = 1
dataprefix = 'AM643_1.'
myrefant = 5
flagver 1
pri_uvr = 0,45 $ since the data are all less than 20 klamdba
sec_uvr = 0,0 $ this isn't too important
polangle = -20
mysolint = 0.0
mypsolint = 1.0

* Run setjy to find the flux value for the primary calibrator
prtask 'SETJY' $ clearing out the results
clrmsg $ of previous runs of setjy.
task 'SETJY'
sources pri_cal,''
optype 'calc'
calcode ''
freqid 1
aparm 0
go
* Save the results of the setjy run
myoutname dataprefix !! pri_cal !! '.SETJY'
docrt false
outprint myoutname
prtask 'AIPS'
clrmsg
inputs setjy $ printing out the setjy inputs
prtmsg
prtask 'setjy' $ printing out the setjy results
prtmsg

* Run VLACALIB on the primary calibrator
* calsour pri_cal,''
* calcode ''
* uvrange pri_uvr
* refant myrefant
* snver 1
* minamper 10
* minphser 10
* docalib false
* gainuse 0
* doprint 1
* myoutname dataprefix !! pri_cal !! '.CALIB'
* outprint myoutname
* vlacalib

* Run VLACALIB on the secondary calibrator
* calsour sec_cal,''
* calcode ''
* uvrange sec_uvr
* refant myrefant
* snver 1
* minamper 10
* minphser 10
* doprint 1
* myoutname dataprefix !! sec_cal !! '.CALIB'
* outprint myoutname
* vlacalib

* Run CALIB on the primary calibrator
prtask 'CALIB'
clrmsg
task 'CALIB'
calsour pri_cal,''
calcode ''
bchan 1
echan 0
antennas 0
uvrange pri_uvr
weightit 0
snver 1
minamper 10
minphser 10
docalib false
clr2name
clroname
refant myrefant
gainuse 0
dopol false
doband false
solint mysolint
solsub 0
solmin 0
soltype ''
aparm 4,0
aparm(6) 2
solmode 'A&P'
cparm 0, 0, minamper/10, minphser/10, 1, 0
go
* Save results of CALIB run
myoutname dataprefix !! pri_cal !! '.CALIB'
docrt false
outprint myoutname
prtask 'AIPS'
clrmsg
inputs calib
prtmsg
prtask 'calib'
prtmsg

* Run CALIB on the secondary calibrator
prtask 'CALIB'
clrmsg
task 'CALIB'
calsour sec_cal,''
calcode ''
bchan 1
echan 0
antennas 0
uvrange sec_uvr
weightit 0
snver 1
minamper 10
minphser 10
docalib false
clr2name
clroname
refant myrefant
gainuse 0
dopol false
doband false
solint mysolint
solsub 0
solmin 0
soltype ''
aparm 4,0
aparm(6) 2
solmode 'A&P'
cparm 0, 0, minamper/10, minphser/10, 1, 0
go
* Save results of CALIB run
myoutname dataprefix !! sec_cal !! '.CALIB'
docrt false
outprint myoutname
prtask 'AIPS'
clrmsg
inputs calib
prtmsg
prtask 'calib'
prtmsg

* Transfering the flux density scale determined by the primary calibrator
* to the secondary calibrator and the polarization angle calibrator
prtask 'getjy'
clrmsg
task 'getjy'
sources sec_cal,''
soucode ''
calsour pri_cal,''
calcode ''
bif 1; eif 2
freqid 1
snver 1
go
* Save the results of the setjy run
myoutname dataprefix !! sec_cal !! '.GETJY'
docrt false
outprint myoutname
prtask 'aips'
clrmsg
inputs getjy
prtmsg
prtask 'getjy'
prtmsg

* Applying the gain and phase solutions from the secondary calibrator to the data
prtask 'clcal'
clrmsg
task 'clcal'
sources sec_cal, obj_name, ''
soucode ''
calsour sec_cal,''
calcode ''
opcode 'cali'
interpol '2pt'
doblank 1
dobtween 0
snver 1
gainver 1
gainuse 2
refant myrefant
go
* Save the results of the calib run
myoutname dataprefix !! sec_cal !! '.CLCAL'
docrt false
outprint myoutname
prtask 'aips'
clrmsg
inputs clcal
prtmsg
prtask 'clcal'
prtmsg

* Applying the gain and phase solutions from the primary calibrator to the
* primary calibrator
prtask 'clcal'
clrmsg
task 'clcal'
sources pri_cal,''
soucode ''
calsour pri_cal,''
calcode ''
opcode 'cali'
interpol '2pt'
doblank 1
dobtween 0
snver 1
gainver 1
gainuse 2
refant myrefant
go
* Save the results of the calib run
myoutname dataprefix !! pri_cal !! '.CLCAL'
docrt false
outprint myoutname
prtask 'aips'
clrmsg
inputs clcal
prtmsg
prtask 'clcal'
prtmsg

* looking at the results of the gain and phase calibration
task 'listr'
optype 'matx'
sources pri_cal,''
uvrange pri_uvr
calcode ''
stokes ''
freqid 1
bif 1; eif 1
docalib 2
gainuse 2
dparm 5, 1, 0 $ plot scalar averaged amp+phase
docrt false
myoutname dataprefix !! pri_cal !! '.GPCALRES'
outprint myoutname
go
bif 2; eif 2
go

task 'listr'
optype 'matx'
sources sec_cal,''
uvrange sec_uvr
calcode ''
stokes ''
freqid 1
bif 1; eif 1
docalib 2
gainuse 2
dparm 5, 1, 0 $ plot scalar averaged amp+phase
docrt false
myoutname dataprefix !! sec_cal !! '.GPCALRES'
outprint myoutname
go
bif 2; eif 2
go

bif 1; eif 2

* prompting to see if I want to do polarization calibration
print 'Do polarization calibration (Y/N)?'
read myprompt
if myprompt = 'N' then
return
end

* Calibrating the instrumental polarization
prtask 'pcal'
clrmsg
task 'pcal'
calsour sec_cal,''
docalib 2
gainuse 2
solint mypsolint
soltype 'appr'
prtlev 1
bparm 0
cparm 0
go
* Save the results of the pcal run
myoutname dataprefix !! sec_cal !! '.PCAL'
docrt false
outprint myoutname
prtask 'aips'
clrmsg
inputs pcal
prtmsg
prtask 'pcal'
prtmsg

* calibrate the absolute phase angle using either 3C286 (1331+305) or
* 3C138 (0521+166)
prtask 'rldif'
clrmsg
task 'rldif'
sources pri_cal,''
uvrange pri_uvr
docalib 2
gainuse 2
dopol true
docrt false
myoutname dataprefix !! pri_cal !! '.RLDIF'
outprint myoutname
go

* changing RLdif output to a phase offset correction
* I've changed the following (9/12/06) so that the polarization angle is set
* earlier in the program depending on what polarization angle source is used.
for i = 1:2
clcorprm(i) = polangle - clcorprm(i)
end

print 'finish clcorprm'

* applying the polarization corrections to the data
prtask 'clcor'
clrmsg
task 'clcor'
sources ''
stokes 'L'
gainver 2
gainuse 3
opcode 'polr'
go
* saving the results of the clcor run
myoutname dataprefix !! obj_name(1) !! '.CLCOR'
docrt false
outprint myoutname
prtask 'aips'
clrmsg
inputs clcor
prtmsg
prtask 'clcor'
prtmsg

* checking the polarization calibration
task 'rldif'
sources pri_cal, sec_cal,''
uvrange pri_uvr
freqid 1
bif 1; eif 2
docalib 2
gainuse 3
dopol 1
docrt false
myoutname dataprefix !! pri_cal !! '.PCALRES'
outprint myoutname
go

return;finish
*
* ======================================================================
*
proc killcal
*
* Purpose: clean up old calibration to run new calibration.
*
* Inputs: none
*
* Outputs: deletes all CL tables except CL 1 and all SN tables.
*
* Method: none
*
* Date Programmer Description of Changes
* ----------------------------------------------------------------------
* 3/21/06 A.A. Kepley Original Code
*
*
vlareset
inext 'sn'
invers -1
extdest

return; finish
*
* ======================================================================
*
proc test
*
* Purpose: test stuff
*
print 'Y or N'
read myprompt
print myprompt
if myprompt = 'Y' then
print 'Yay for Yes!'
return
else
print 'Boo for no!'
end

print 'hello world'

return; finish
*
* ======================================================================
*


No comments: