# High linear poln reduction
# gmoellen (2011/02/12)
# This is a script that does a nominal reduction of a 1924-292 poln
# observation made by ALMA in badn 3 on 2010 Oct 30. This observation was
# subject to some cross-hand data ordering issues; this script
# assumes they have been corrected.
#
# The data for this script can be obtained at:
# http://www.aoc.nrao.edu/~gmoellen/ALMA/
#
# This calibration sequence is appropriate for gain and instrumental
# polarization calibration of a significantly linearly polarized
# source. It includes gain, bandpass, cross-hand delay, X-Y phase
# and source linear poln (incl. some iteration with gain), and
# instrumental polarization (linear approx) estimation. There
# are many ways that this reduction can be improved, and new
# versions will be developed over time. Similar scripts
# for different polarization regimes (e.g., weak- or zero-
# linear poln, etc.) will also be developed.
# Temporary NB: As of 2011/02/12, the cross-hand delay solution
# in gaincal appears to be broken, I suspect as a result of
# recent work in the general delay treatment within casa.
# For now, the cross-hand delay will be treated "manually"
# using gencal. The proper solve for cross-hand delay will
# be restored as soon as I've fixed the bug.
# Some fixed info used in the processing
msname='20101030_1924-292.ms'
refant='0'
# NB: Unless the calibration model is specified explicity, [I,Q,U,V]=[1,0,0,0]
# is used implicitly (via the MODEL_DATA column) below.
# prelim phase(t) for B
# (this could be improve a bit by selecting a subset
# of channels to avoid coherence loss due to delays)
gaincal(vis=msname,caltable='Gpre', \
selectdata=T,scan='2', \
solint='int',refant=refant, \
calmode='p')
plotcal('Gpre','time','phase')
# B, using phase(t)
# NB: this will calibrate parallel-hand delays implicitly
bandpass(vis=msname,caltable='B', \
selectdata=T,scan='2', \
solint='inf',refant=refant,solnorm=T, \
gaintable='Gpre',interp='nearest')
plotcal('B','freq','amp')
plotcal('B','freq','phase')
# optional (to enable data examination, e.g,. residual
# cross-hand phase "bandpass")
applycal(vis=msname,\
selectdata=T,scan='2', \
gaintable=['Gpre','B'],\
interp=['nearest','nearest'])
# cross-hand delay, using B,G0
# WARNING: a problem has crept into the 'KCROSS' mode of gaincal,
# using gencal (below) to set the cross-hand delay manually instead
# (NB: this step assumes a strong source polarization signal
# that dominates the _mean_ [over baselines] D-term contribution)
#gaincal(vis=msname,caltable='Kcrs', \
# selectdata=T,scan='2', \
# gaintype='KCROSS', \
# smodel=[1,0,1,0], \
# solint='inf',refant=refant, \
# gaintable=['Gpre','B'],interp=['nearest','nearest'])
# only run this once! (delete Kcrs if you run this again)
gencal(vis=msname,caltable='Kcrs',caltype='sbd',spw='0',pol='X',parameter=[-0.3065])
# optional (for data examination)
# (NB: there is no unnormalized amplitude calibration yet)
applycal(vis=msname,\
selectdata=T,scan='2',\
gaintable=['Gpre','B','Kcrs'],\
interp=['nearest','nearest','nearest'])
# at this point, we discard 'Gpre'
# Full (all scans) time-dep G (amp and ph), using B, Kcrs
# (these gains will be corrupted in amp by source
# polarization rotating with parallactic angle,
# but will reasonably calibrate the cross hands for
# a sensible polarization estimate, especially with
# some iteration, which we do below)
gaincal(vis=msname,caltable='G0', \
solint='int',refant=refant, \
smodel=[1,0,0,0], \
gaintable=['Kcrs','B'],interp=['nearest','nearest'])
# plot gain amp vs. time (source polarization will be evident
# in the time-dependence, and opposite in X and Y)
plotcal('G0','time','amp',iteration='antenna')
# optional: (for data exam)
applycal(vis=msname, \
gaintable=['Kcrs','B','G0'],interp=['nearest','nearest','nearest'])
# Using prior calibration, solve for refant XY-phase (cross-hand slope
# in the complex plane) and source polarization (amplitude of time-variable
# cross-hand signal)
gaincal(vis=msname,caltable='XY0', \
solint='inf',combine='scan',preavg=10,refant=refant, \
gaintype='XY+QU', \
smodel=[1,0,1,0], \
gaintable=['Kcrs','B','G0'],interp=['nearest','nearest','nearest'])
# Output:
# X-Y phase = 60.6874 deg.
# Fractional Poln: Q = -0.026484, U = -0.0793016; P = 0.0836071, X = -54.2338deg.
# Net (over baselines) instrumental polarization: 0.0020239
# NB: The XY-phase and Q,U estimates have an ambiguity here. X-Y ph = -119.3 and
# [Q,U] = [0.026,0.079] would also describe the source polarization signal in
# the crosshands. This degeneracy is breakable by examining a revised
# parallel-hand gain solution: If the source polarization signature in the
# gain amplitudes ~double, then the wrong ambiguity was chosen. If it
# goes away, all is well. (TBD: an automated way to evaluate and select
# the correct ambiguity.)
# Revise G, using QU and 'XY0'
# NB: parang is applied so that the specified
# Q,U rotates correctly in the model
gaincal(vis=msname,caltable='G1', \
solint='int',refant=refant, \
smodel=[1,-0.026484,-0.0793016,0],\
gaintable=['Kcrs','B','XY0'],interp=['nearest','nearest','nearest'], \
parang=T)
# plot gain amp
plotcal('G1','time','amp',iteration='antenna')
#--> source polarization oscillation much reduced. Good!
# optional: (for data exam)
applycal(vis=msname, \
gaintable=['Kcrs','B','G1'],interp=['nearest','nearest','nearest'])
# Revise XY+GU, using G1
gaincal(vis=msname,caltable='XY1', \
solint='inf',combine='scan',preavg=10,refant=refant, \
gaintype='XY+QU', \
smodel=[1,0,1,0], \
gaintable=['Kcrs','B','G1'],interp=['nearest','nearest','nearest'])
# X-Y phase = 60.6874 deg.
# Fractional Poln: Q = -0.0264747, U = -0.0792738; P = 0.0835778, X = -54.2338deg.
# Net (over baselines) instrumental polarization: 0.00202318
# Not much change, so no need to iterate again
# optional: (for data examination: should show cross-hands that _vary_
# ~only in the real part; any non-zero imag part comes from instr pol
# or V or higher-order effects)
applycal(vis=msname, \
gaintable=['Kcrs','B','G1','XY1'],interp=['nearest','nearest','nearest','nearest'])
# Now D(f) (chan-dep), using all prior calibration and Q,U
# (NB: I believe it is incorrect to apply the refant in
# this high source poln regime, so we use refant=''. I think
# this yields a better correction in the cross-hands,
# and I will be investigating further.)
polcal(vis=msname,caltable='Df', \
solint='inf',combine='scan',preavg=60,\
poltype='Df',refant='', \
smodel=[1,-0.0264747,-0.0792738,0], \
gaintable=['Kcrs','B','G1','XY'], \
interp=['nearest','nearest','nearest','nearest'])
plotcal('Df','freq','amp',iteration='antenna')
plotcal('Df','freq','phase',iteration='antenna')
# optional: (for data exam: note that parang=F, so
# the resulting corrected data should show the time-dep
# source polarization signature consistently, in both
# parallel- and cross-hands, and in the same way on
# all baslines)
applycal(vis=msname, \
gaintable=['Kcrs','B','G1','XY1','Df'], \
interp=['nearest','nearest','nearest','nearest','nearest'], \
parang=F)
# final cal apply, with parang=T to convert to sky frame (where
# source pol is stationary)
applycal(vis=msname, \
gaintable=['Kcrs','B','G1','XY1','Df'], \
interp=['nearest','nearest','nearest','nearest','nearest'], \
parang=T)
# --> imaging