#
#RECIPE: Script to emulate task imagr in AIPS
#
#CATAGORY: Synthesis
#
#GOALS: Imaging, cleaning with variable clean boxes
#
#USING: imagr tool and interactivemask
#
#RESULTS: A cleaned image from a measuring set
#
#ASSUME: Measurement set exists
#
#SYNOPSIS:
# This script emulates the aips task imagr. It is executed
# in aips++ using the imager tool and the
# interactivemask viewer to make the cleaning regions
# More work is needed for this script.
#
# This script will make a residual image which is then displayed
# on a pop-up viewer. To choose a cleaning region, hit the 'add
# regions button, click on the Region box on left (sixth button down),
# draw a box with curser and then double click. You can then add another
# region with the same sequence. Click 'Refesh mask' to see all of the
# cleaning boxes. When done, hit 'Done with masking'. Execution will
# not begin until the space bar is hit in reponse to the >> prompt in
# the glish window.
#
# The present script needs work. At the present time the cleaning
# is done with 5, 25, 125, 625, ... iterations until niter or the
# threshhold flux density if reached.
#
#SCRIPTNAME; imagr_rec.g
#
#
# INITIATION AND INPUT PARAMETERS:
#
include 'imager.g';
include 'general.g';
include 'os.g';
include 'interactivemask.g';
#
# Input parameters
#
cleantype := 'wfclark'; # wfclark cleans most of field
# hogbom and clark only inner 1/4
# measurement set
msname := '/DATA/THUBAN_1/FITS/efomalon/J1223S.ms';
outnpre := 'J1223S1'; # mapname prefix
# cleanmod = outnpre.ipts
# cleanmap = outnpre.icln
# residmap = outnpre.ires
# cleanregion = outnpre.ires.mask
fieldnum := 1; # Source field number
cellsize := 0.001; # Cell size (arcsec)
imsize := 256; # Image size
nfacets := 1; # Default
bif := 1; # 0 = first if (not yet implemented)
eif := 2; # 0 = last if
bchan := 1; # 0 = first channel
echan := 1; # 0 = last channel
step := 1; # 0 = 1: channel increment
stokes := 'I'; # Advise only one stokes
uvwtfn := 'none';
# 'none' will use existing weighting
# available are 'uniform'
# 'briggs'
# 'radial'
# 'natural'
robust := 0; # Uses with briggs
niter := 400; # Total number of iterations
restart := T; # T=previous maps deleted and begin again
# F=Continue cleaning with niter more
threshold := 0.000000; # Jansky. When to stop cleaning
display := F; # Clean display
gain := 0.1; # Loop gain
bmaj := 0; # arcsec
bmin := 0; # arcsec
bpa := 0; # deg N-->E
# Initial clean box. Not necessary
clbox := [100,100,156,156]
# Default is 90% full field for wfclark
# Default is inner quarter for others
#
# Will generalize uvrange and uvtaper
uvrange := [0,0] # Range in klambda
uvtaper := [0,0] # Taper in klambda (x and y directions)
factor := 1.0 # Speed up factor (1.0 = normal)
#----------------------------------------------------------------------------
# Some optional control parameters and defaults :
#
if (gain == 0.0) {gain := 0.05; }
if (factor == 0.0) {factor := 1.0; }
if (nfacets == 0.0) {nfacets := 1; }
if (refant == 0.0) {refant := 1; }
#
if (clbox[1] == 0 & cleantype =='wfclark') {
clbox := [0.05*imsize, 0.05*imsize, 0.95*imsize, 0.95*imsize]; }
if (clbox[1] == 0 & cleantype !='wfclark') {
clbox := [0.26*imsize, 0.26*imsize, 0.74*imsize, 0.75*imsize]; }
#===========================================================================
#
# Build various name
#
model := spaste(outnpre, '.ipts');
clean := spaste(outnpre, '.icln');
residual := spaste(outnpre, '.ires');
mregion := spaste(outnpre, '.ires.mask');
#
#
imgr:=imager(msname);
#
# Delete old images if restarting
#
if (restart) {
dos.remove (pathname=clean, mustexist=F);
dos.remove (pathname=model, mustexist=F);
dos.remove (parthname=residual, mustexist=F);
dos.remove (parthname=scaltable, mustexist=F);
dos.remove (pathname=mregion, mustexist=F); }
#
# Set data
nchan := (echan - bchan) / 2 + 1
imgr.setdata(
fieldid=fieldnum,
start=bchan, step=step, nchan=nchan,
spwid=[bif,eif]);
#
# Set image
#
imgr.setimage(
cellx=paste(cellsize,'arcsec'),
celly=paste(cellsize,'arcsec'),
nx=imsize, ny=imsize,
stokes=stokes,
spwid=[bif,eif],
nchan=nchan, start=bchan, step=step,
doshift=F,
fieldid=fieldnum,
facets=nfacets);
#
# Set image weight if necessary
#
if (uvwtfn != 'none') {
imgr.weight (type=uvwtfn, robust=robust); }
#
# Set uvrange, if necessary
if (uvrange[2] != 0) {
imgr.uvrange (uvmin=1000.0*uvrange[1],
uvmax=1000.0*uvrange[2]); }
#
# Set uvtaper, if necessary
bxfilter :=0
byfilter :=0
if (uvtaper[1] != 0.0) {
bxfilter := 145.3 / uvtaper[1]; }
if (uvtaper[2] != 0.0) {
byfilter := 145.3 / uvtaper[2]; }
if (bxfilter != 0.0 & byfilter != 0.0) {
imgr.filter (type='gaussian',
bmaj=paste(bxfilter,'arcsec'),
bmin=paste(byfilter,'arcsec'),
bpa= paste(0.0,'deg'));
}
#
# Set clean beam
if (bmaj*bmin != 0.0 ) {
imgr.setbeam (
bmaj=paste(bmaj,'arcsec'),
bmin=paste(bmin,'arcsec'),
bpa= paste(bpa,'deg'));
}
#
# Cyclefactor speed up (experimental)
#
imgr.setmfcontrol (
cyclefactor=1.5/factor);
#
# Some subtle set options
#
if (nfacets == 1) {
imgr.setoptions (padding=1.2); }
else {
imgr.setoptions (padding=1.3); }
#
# Interactive cleaning loop
#
# First iteration for residual image
imgr.clean (
algorithm='clark',
niter=0, gain=gain,
displayprogress=display,
model=model,
image=clean,
residual=residual,
threshold=paste(threshold,'Jy'));
#
# Display residual image and fiddle with boxes
#
a:=interactivemask(residual);
a.start();
#
# Type any character to continue
#
print readline();
a.done();
#
# Start cleaning cycle
for (n in 1:4) {
pniter := 5.0^n
# Do clean
imgr.clean (
algorithm=cleantype,
niter=pniter, gain=gain,
displayprogress=display,
model=model,
image=clean,
residual=residual,
threshold=paste(threshold,'Jy'),
mask=mregion);
#
#
# Display residual image and fiddle with boxes
#
a:=interactivemask(residual);
a.start();
#
# Type any character to continue
#
print readline();
a.done();
}
#
# Restore image (not needed for wfclark)
#
if (cleantype != 'wfclark') {
imgr.restore(
model=model,
image=clean,
residual=residual,
complist=''); }
#
#
# Close imager object
imgr.close();
#------------------------------------------------------------------------------
#
#OUTPUT:
# The following images are made.
# outnpre.icln = the clean image
# outnpre.ires = the residual image
# outnpre.ipts = the clean components image
# outnpre.ires.mask = the last mask used
#
#SUBMITTER: Ed Fomalont
#SUBMITAFFL: NRAO-Charlottesville
#SUBMITDATE: 2002-Feb-14
#