https://casaguides.nrao.edu/api.php?action=feedcontributions&user=Paladino&feedformat=atomCASA Guides - User contributions [en]2024-03-29T08:48:59ZUser contributionsMediaWiki 1.38.6https://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=218363C286 Band6Pol Imaging for CASA 4.32017-06-16T13:11:56Z<p>Paladino: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
interactive=True, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=True''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 420.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
The mask you drew for the clean has been saved in your working directory as a file "3c286.cal.StokesIQUV_noselfcal.clean.mask". If you want to use it in the following self-calibration you should rename it. If you downloaded the calibrated data you have already a file mask, named 3c286_StokesIQUV_selfcal.mask.<br />
<br />
To rename the file:<br />
<source lang="python"><br />
# In CASA<br />
os.system('mv 3c286.cal.StokesIQUV_noselfcal.clean.mask 3c286_StokesIQUV_selfcal.mask')<br />
</source><br />
<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=False)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=True,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=False)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=True,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.2 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=False)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=True, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.037 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 9950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.037<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|9950<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.1 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 0.1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorQ)**2 + (fluxU*errorU)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees(sqrt(fluxQ*errorU)**2 + (fluxU*errorQ)**2)/ fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=218213C286 Band6Pol Imaging for CASA 4.32017-06-09T08:11:46Z<p>Paladino: /* Image visualization and analysis */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
interactive=True, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=True''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 420.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
The mask you drew for the clean has been saved in your working directory as a file "3c286.cal.StokesIQUV_noselfcal.clean.mask". If you want to use it in the following self-calibration you should rename it. If you downloaded the calibrated data you have already a file mask, named 3c286_StokesIQUV_selfcal.mask.<br />
<br />
To rename the file:<br />
<source lang="python"><br />
# In CASA<br />
os.system('mv 3c286.cal.StokesIQUV_noselfcal.clean.mask 3c286_StokesIQUV_selfcal.mask')<br />
</source><br />
<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=False)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=True,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=False)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=True,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.2 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=False)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=True, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.037 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 9950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.037<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|9950<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.1 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 0.1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorQ)**2 + (fluxU*errorU)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees (sqrt(fluxQ*errorU)**2 + (fluxU*errorQ)**2)/ fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=197023C286 Band6Pol Imaging for CASA 4.32016-05-24T14:09:43Z<p>Paladino: /* Constructing Polarization Intensity and Angle Images */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 420.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
The mask you drew for the clean has been saved in your working directory as a file "3c286.cal.StokesIQUV_noselfcal.clean.mask". If you want to use it in the following self-calibration you should rename it. If you downloaded the calibrated data you have already a file mask, named 3c286_StokesIQUV_selfcal.mask.<br />
<br />
To rename the file:<br />
<source lang="python"><br />
# In CASA<br />
mv 3c286.cal.StokesIQUV_noselfcal.clean.mask 3c286_StokesIQUV_selfcal.mask<br />
</source><br />
<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.2 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.037 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 9950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.037<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|9950<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.1 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 0.1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=182523C286 Band6Pol Calibration for CASA 4.32015-12-21T15:59:11Z<p>Paladino: /* Imaging of the polarization calibrator with and without applying D-terms corrections */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
''' Note that the calibration procedure described here is intended to provide an initial example of the reduction of ALMA polarization data. It may be updated in future, and is not necessarily the exact procedure by which Early Science data will be calibrated. A future Science Verification (SV) dataset on 3C 138 will demonstrate an updated calibration strategy. Details of the 3C 138 SV data can be found on the [https://almascience.nrao.edu/alma-data/science-verification/science-verification-wiki-info Science Verification webpage]'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a contribution from Stokes ''Q'', ''U'', and parallactic angle ''ψ'' appears in the real part of ''all'' correlations. This complicates the analysis somewhat, but also provides better constraints for estimating and correcting the instrumental polarization.<br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is independent of parallactic angle, whereas the contribution from the source rotates with parallactic angle for alt-az mount antennas. This makes it possible to uniquely separate the source and instrumental contributions to the polarized response.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle (see <xr id="3c279_BG2"/>).<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use a function included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on. The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model. It is not important to specify the polarization Stokes parameters correctly, since here we are only solving for a phase-like quantity. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear phase slope across each spw. In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. As a result, a single residual phase bandpass relating the phase of the two hands of polarization in the reference antenna remains in the cross-hands of all baselines. The Kcross solution has already accounted for any linear phase slope in this phase bandpass, but we need to solve for any non-linear phase bandpass shape in the XY-phase so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged per scan and over all baselines, in one spw (averaged in channel). The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane. The XY and YX correlations have the same slope with ''opposite'' signs because they are complex conjugates of each other. For SNR purposes, this plot is averaged in channel; each channel has its own slope, in fact. The Kcross solution ensures that the channel-average is reasonably coherent.<br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then solves for a channel-averaged source polarization (with the channel-dependent XY-phase corrected). <br />
<br />
Note that we only require a sufficiently strongly polarized source for this calibration, so that there is an adequate reference signal against which to measure the instrumental effects. It is not necessary to know the precise polarization properties of the calibrator, as long as there is sufficient time for the source polarization contribution to change via parallactic angle rotation.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again are using a polarized model (a non-zero value for U is assumed). This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model. It is not important to specify the polarization Stokes parameters correctly, since here we are only solving for a phase-like quantity.<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that the application of this table does indeed remove spw- and channel-dependent residual phases from the data. The remaining phase offsets (per baseline and correlation) are due to the instrumental polarization effects which will be calibrated below.<br />
<br />
In terms of the real and imaginary parts, the application of the XY-phase calibraiton removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization occurring entirely in the real part (over a range between -0.06 and 0.06), with a small complex offset due to the mean instrumental polarization that will be solved for below.<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average.<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver for instrumental polarization<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
We do not use a reference antenna here because the polarized source provides sufficient constraints to solve for all instrumental polarization parameters on all antennas, relative to the specified source polarization. This is in contrast to the case of an unpolarized calibrator (or the general ciricular basis treatment, even if the calibrator is polarized), where only relative instrumental polarization factors among the antennas may be determined, with one feed on one antenna set to zero instrumental polarization. <br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This test will be done in the following section.<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the Stokes U of this source is ~0.04. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=182503C286 Band6Pol Imaging for CASA 4.32015-12-04T12:48:06Z<p>Paladino: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 420.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
The mask you drew for the clean has been saved in your working directory as a file "3c286.cal.StokesIQUV_noselfcal.clean.mask". If you want to use it in the following self-calibration you should rename it. If you downloaded the calibrated data you have already a file mask, named 3c286_StokesIQUV_selfcal.mask.<br />
<br />
To rename the file:<br />
<source lang="python"><br />
# In CASA<br />
mv 3c286.cal.StokesIQUV_noselfcal.clean.mask 3c286_StokesIQUV_selfcal.mask<br />
</source><br />
<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.2 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', stokes='I', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.037 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 9950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.037<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|9950<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=181913C286 Band6Pol Calibration for CASA 4.32015-11-11T12:06:55Z<p>Paladino: /* Imaging of the polarization calibrator with and without applying D-terms corrections */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
''' Note that the calibration procedure described here is intended to provide an initial example of the reduction of ALMA polarization data. It may be updated in future, and is not necessarily the exact procedure by which Early Science data will be calibrated. A future Science Verification (SV) dataset on 3C 138 will demonstrate an updated calibration strategy. Details of the 3C 138 SV data can be found on the [https://almascience.nrao.edu/alma-data/science-verification/science-verification-wiki-info Science Verification webpage]'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a contribution from Stokes ''Q'', ''U'', and parallactic angle ''ψ'' appears in the real part of ''all'' correlations. This complicates the analysis somewhat, but also provides better constraints for estimating and correcting the instrumental polarization.<br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is independent of parallactic angle, whereas the contribution from the source rotates with parallactic angle for alt-az mount antennas. This makes it possible to uniquely separate the source and instrumental contributions to the polarized response.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle (see <xr id="3c279_BG2"/>).<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use a function included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on. The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model. It is not important to specify the polarization Stokes parameters correctly, since here we are only solving for a phase-like quantity. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear phase slope across each spw. In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. As a result, a single residual phase bandpass relating the phase of the two hands of polarization in the reference antenna remains in the cross-hands of all baselines. The Kcross solution has already accounted for any linear phase slope in this phase bandpass, but we need to solve for any non-linear phase bandpass shape in the XY-phase so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged per scan and over all baselines, in one spw (averaged in channel). The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane. The XY and YX correlations have the same slope with ''opposite'' signs because they are complex conjugates of each other. For SNR purposes, this plot is averaged in channel; each channel has its own slope, in fact. The Kcross solution ensures that the channel-average is reasonably coherent.<br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then solves for a channel-averaged source polarization (with the channel-dependent XY-phase corrected). <br />
<br />
Note that we only require a sufficiently strongly polarized source for this calibration, so that there is an adequate reference signal against which to measure the instrumental effects. It is not necessary to know the precise polarization properties of the calibrator, as long as there is sufficient time for the source polarization contribution to change via parallactic angle rotation.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again are using a polarized model (a non-zero value for U is assumed). This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model. It is not important to specify the polarization Stokes parameters correctly, since here we are only solving for a phase-like quantity.<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that the application of this table does indeed remove spw- and channel-dependent residual phases from the data. The remaining phase offsets (per baseline and correlation) are due to the instrumental polarization effects which will be calibrated below.<br />
<br />
In terms of the real and imaginary parts, the application of the XY-phase calibraiton removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization occurring entirely in the real part (over a range between -0.06 and 0.06), with a small complex offset due to the mean instrumental polarization that will be solved for below.<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average.<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver for instrumental polarization<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
We do not use a reference antenna here because the polarized source provides sufficient constraints to solve for all instrumental polarization parameters on all antennas, relative to the specified source polarization. This is in contrast to the case of an unpolarized calibrator (or the general ciricular basis treatment, even if the calibrator is polarized), where only relative instrumental polarization factors among the antennas may be determined, with one feed on one antenna set to zero instrumental polarization. <br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This test will be done in the following section.<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
mask='3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
mask='3c286_StokesIQUV_selfcal.mask',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the Stokes U of this source is ~0.04. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=181603C286 Band6Pol Imaging for CASA 4.32015-11-04T09:15:43Z<p>Paladino: /* Full polarization imaging of the target */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
The mask you drew for the clean has been saved in your working directory as a file "3c286.cal.StokesIQUV_noselfcal.clean.mask". If you want to use it in the following self-calibration you should rename it. If you downloaded the calibrated data you have already a file mask, named 3c286_StokesIQUV_selfcal.mask.<br />
<br />
To rename the file:<br />
<source lang="python"><br />
# In CASA<br />
mv 3c286.cal.StokesIQUV_noselfcal.clean.mask 3c286_StokesIQUV_selfcal.mask<br />
</source><br />
<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=180543C286 Band6Pol Imaging for CASA 4.32015-08-26T16:16:59Z<p>Paladino: /* Self-calibration */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=180533C286 Band6Pol Imaging for CASA 4.32015-08-26T16:16:18Z<p>Paladino: /* Full polarization imaging of the target */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/Release4.2.2/docs/userman/UserMansu323.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I (mJy) <br />
| style="text-align:center;"| 375.6<br />
| style="text-align:center;"| 0.35<br />
|-<br />
| style="text-align:center;"| Q (mJy)<br />
| style="text-align:center;"| 14.4<br />
| style="text-align:center;"| 0.04<br />
|-<br />
| style="text-align:center;"| U (mJy)<br />
| style="text-align:center;"| 60.1<br />
| style="text-align:center;"| 0.09<br />
|-<br />
| style="text-align:center;"| Pol int (mJy)<br />
| style="text-align:center;"| 61.8<br />
| style="text-align:center;"| 0.05<br />
|-<br />
! scope="col"| P (%)<br />
! scope="col"| 16.45<br />
! scope="col"| 0.02<br />
|-<br />
! scope="col"| χ (deg)<br />
! scope="col"| 38.3<br />
! scope="col"| 0.02<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
Note that '''the uncertainties quoted above are purely statistical.''' The systematic errors will be larger, and include (but are not limited to) any net bias in the position angle of the linear feeds in the antennas, the details of different observations (at what parallactic angles, etc.), and other data quality variations (including source structure). We conservatively estimate the position angle uncertainty to be '''± 2º'''.<br />
<br />
And now, a quick comparison with previous results from IRAM and CARMA.<br />
<br />
[http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of single-dish millimeter measurements of 3C286 with the IRAM 30 m Telescope.<br />
Their observations at 1 mm (229 GHz) and 3 mm (86 GHz) produced the following results: <br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|style="text-align:center;"| 3 mm<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''33.1 ± 5.7'''<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
[http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and [https://www.mmarray.org/memos/#64 CARMA Memo 64] report interferometric polarization data of 3C286 taken with CARMA at 1 mm (225 GHz). Their results are as follows:<br />
{| class="wikitable"<br />
|-<br />
| <br />
|style="text-align:center;"| 1 mm<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|'''39.2 ± 1.0'''<br />
|}<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=179663C286 Band6Pol Imaging for CASA 4.32015-07-28T10:31:30Z<p>Paladino: /* Export images in fits format */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 375.6 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 14.4 mJy<br />
| style="text-align:center;"| 0.04 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 60.1 mJy<br />
| style="text-align:center;"| 0.09 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.8 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.3 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179653C286 Band6Pol Calibration for CASA 4.32015-07-28T10:14:01Z<p>Paladino: /* Revise gain with good source pol estimate */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a contribution from Stokes ''Q'', ''U'', and parallactic angle ''ψ'' appears in the real part of ''all'' correlations. This complicates the analysis somewhat, but also provides better constraints for estimating and correcting the instrumental polarization.<br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is independent of parallactic angle, whereas the contribution from the source rotates with parallactic angle for alt-az mount antennas. This makes it possible to uniquely separate the source and instrumental contributions to the polarized response.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle (see <xr id="3c279_BG2"/>).<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use a function included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on. The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model. It is not important to specify the polarization Stokes parameters correctly, since here we are only solving for a phase-like quantity. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear phase slope across each spw. In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. As a result, a single residual phase bandpass relating the phase of the two hands of polarization in the reference antenna remains in the cross-hands of all baselines. The Kcross solution has already accounted for any linear phase slope in this phase bandpass, but we need to solve for any non-linear phase bandpass shape in the XY-phase so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged per scan and over all baselines, in one spw (averaged in channel). The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane. The XY and YX correlations have the same slope with ''opposite'' signs because they are complex conjugates of each other. For SNR purposes, this plot is averaged in channel; each channel has its own slope, in fact. The Kcross solution ensures that the channel-average is reasonably coherent.<br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then solves for a channel-averaged source polarization (with the channel-dependent XY-phase corrected). <br />
<br />
Note that we only require a sufficiently strongly polarized source for this calibration, so that there is an adequate reference signal against which to measure the instrumental effects. It is not necessary to know the precise polarization properties of the calibrator, as long as there is sufficient time for the source polarization contribution to change via parallactic angle rotation.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again are using a polarized model (a non-zero value for U is assumed). This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model. It is not important to specify the polarization Stokes parameters correctly, since here we are only solving for a phase-like quantity.<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that the application of this table does indeed remove spw- and channel-dependent residual phases from the data. The remaining phase offsets (per baseline and correlation) are due to the instrumental polarization effects which will be calibrated below.<br />
<br />
In terms of the real and imaginary parts, the application of the XY-phase calibraiton removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization occurring entirely in the real part (over a range between -0.06 and 0.06), with a small complex offset due to the mean instrumental polarization that will be solved for below.<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average.<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver for instrumental polarization<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
We do not use a reference antenna here because the polarized source provides sufficient constraints to solve for all instrumental polarization parameters on all antennas, relative to the specified source polarization. This is in contrast to the case of an unpolarized calibrator (or the general ciricular basis treatment, even if the calibrator is polarized), where only relative instrumental polarization factors among the antennas may be determined, with one feed on one antenna set to zero instrumental polarization. <br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This test will be done in the following section.<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the Stokes U of this source is ~0.04. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=179643C286 Band6Pol Imaging for CASA 4.32015-07-28T10:12:23Z<p>Paladino: /* Export images in fits format */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 375.6 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 14.4 mJy<br />
| style="text-align:center;"| 0.04 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 60.1 mJy<br />
| style="text-align:center;"| 0.09 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.8 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.3 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or you can <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=179633C286 Band6Pol Imaging for CASA 4.32015-07-28T10:11:50Z<p>Paladino: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 375.6 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 14.4 mJy<br />
| style="text-align:center;"| 0.04 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 60.1 mJy<br />
| style="text-align:center;"| 0.09 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.8 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.3 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
==Export images in fits format==<br />
<br />
To get all images in fits format you need to use the task {{exportfits}}.<br />
<br />
You can add the parameters imagename (the input image) and fitsimage (the name of the output image) one by one or <br />
run a python cycle over all the images:<br />
<br />
<source lang="python"><br />
# In CASA <br />
import glob<br />
<br />
imagenames=glob.glob("*image") <br />
<br />
for name in imagenames:<br />
exportfits(imagename=name, fitsimage=name+'.fits')<br />
<br />
</source> <br />
<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179593C286 Band6Pol Calibration for CASA 4.32015-07-28T07:35:15Z<p>Paladino: /* Applying the calibrations and splitting of the corrected data */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This test will be done in the following section.<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the Stokes U of this source is ~0.04. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=179173C286 Band6Pol Imaging for CASA 4.32015-07-27T13:13:01Z<p>Paladino: /* Full polarization imaging of the target */</p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission. Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. <br />
<br />
If you did not complete the Calibration portion of the guide, then you can instead download the file 3C286_Band6_CalibratedData.tgz (the calibrated uv data) from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum full Stokes image of 3C286 using {{clean}}. <br />
We first define the dataset we will use in all the following steps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
vis='3c286_Band6.pol.cal.ms'<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis, spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_noselfcal.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first cycle, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesIQUV_noselfcal.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_noselfcal.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.4 mJy and the peak flux density is ~335.2 mJy. The dynamic range (ratio between peak and rms) is approximately 760.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesIQUV_noselfcal.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesIQUV_noselfcal.clean.png')<br />
</source><br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G1p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
To check the quality of the solutions we obtained, we plot the gains for each antenna, as function of time:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='3c286_IQUV.G1p', xaxis='time', yaxis='phase', iteration='antenna')<br />
</source><br />
<br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G1p'],calwt=F)<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal1.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal1.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.13 mJy/beam, lower than the value measured in the first image (0.4 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.G2p')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
plotcal(caltable='3c286_IQUV.G2p', xaxis='time', yaxis='phase', iteration='antenna')<br />
<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal2.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T,<br />
niter=10000)<br />
<br />
</source><br />
<br />
You can notice when the first residual image appears that some residual central emission is evident. Continue the cleaning, by using the green continue button, until the residual image appears as much as possible noise like. <br />
In this example we stop the clean after 2 cycles, and we check the image statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
The rms level in this new image is ~0.1 mJy/beam. This level can be improved by a last run of selfcalibration, this time <br />
solving for both amplitude and phase.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_IQUV.Gap')<br />
gaincal(vis,<br />
caltable='3c286_IQUV.Gap',<br />
solint='30s',gaintable=['3c286_IQUV.G2p'],<br />
refant='DV23',minblperant=4,<br />
calmode='ap',minsnr=4)<br />
<br />
applycal(vis,<br />
field='',<br />
gaintable=['3c286_IQUV.G2p','3c286_IQUV.Gap'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesIQUV_selfcal_ap.clean*')<br />
clean(vis,<br />
imagename='3c286.cal.StokesIQUV_selfcal_ap.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
psfmode='clarkstokes',<br />
stokes='IQUV',<br />
mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, <br />
niter=10000)<br />
<br />
</source><br />
<br />
This time the first residual map shows a new bright extended component which was completely hidden by the noise in the previous images. We add a clean box around it and proceed with the clean. After 10 cycles we stop and check the statistics of the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms is 0.036 mJy and the peak of the image is 368 mJy, leading to a dynamic range of 7950.<br />
<br />
We can consider this result satisfying and stop here the selfcalibration.<br />
<br />
=== Stokes images ===<br />
<br />
We can extract the Stokes Q, U, and V images from the selfcalibrated image, using the taks immath:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesI.clean.image',expr='IM0',stokes='I')<br />
os.system('rm -rf 3c286.cal.StokesQ.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesQ.clean.image',expr='IM0',stokes='Q')<br />
os.system('rm -rf 3c286.cal.StokesU.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesU.clean.image',expr='IM0',stokes='U')<br />
os.system('rm -rf 3c286.cal.StokesV.clean.image*')<br />
immath(imagename='3c286.cal.StokesIQUV_selfcal_ap.clean.image',outfile='3c286.cal.StokesV.clean.image',expr='IM0',stokes='V')<br />
<br />
</source><br />
<br />
We measure the statistic in each emage, using the task imstat:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
I_rms=(imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
I_peak=(imstat(imagename='3c286.cal.StokesI.clean.image', region='')['max'][0])<br />
Q_rms=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
Q_peak=(imstat(imagename='3c286.cal.StokesQ.clean.image', region='')['max'][0])<br />
U_rms=(imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')['rms'][0])<br />
U_peak=(imstat(imagename='3c286.cal.StokesU.clean.image', region='')['max'][0])<br />
<br />
print I_rms, I_peak, Q_rms, Q_peak, U_rms, U_peak<br />
<br />
</source><br />
<br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data are still undergoing verification. Results from the V image are therefore not recommended for scientific purposes at this time'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.036<br />
| style="text-align:center;"| 0.026<br />
| style="text-align:center;"| 0.05<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|14.1<br />
|style="text-align:center;"|59.1<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|10230<br />
|style="text-align:center;"|542<br />
|style="text-align:center;"|1182<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.06 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.12747101]),<br />
'max': array([ 0.06074611]),<br />
'maxpos': array([125, 125, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.32.960, Plinear, 2.33e+11Hz',<br />
'mean': array([ 0.00010715]),<br />
'medabsdevmed': array([ 2.08474630e-05]),<br />
'median': array([ 4.79196569e-05]),<br />
'min': array([ 9.89017863e-08]),<br />
'minpos': array([ 23, 214, 0, 0], dtype=int32),<br />
'minposf': '13:31:09.077, +30.30.41.860, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 4.34697722e-05]),<br />
'rms': array([ 0.00126342]),<br />
'sigma': array([ 0.00125888]),<br />
'sum': array([ 6.69700321]),<br />
'sumsq': array([ 0.09976477]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060746114701032639<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'beam': {'beamarcsec': {'major': {'unit': 'arcsec',<br />
'value': 0.9374216198921204},<br />
'minor': {'unit': 'arcsec',<br />
'value': 0.4946177303791046},<br />
'positionangle': {'unit': 'deg',<br />
'value': 7.5858154296875}},<br />
'beampixels': 52.53745924485295,<br />
'beamster': 1.2348630615213326e-11},<br />
'flux': {'error': array([ 0.00011495, 0. , 0. , 0. ]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06180972, 0. , 0. , 0. ])},<br />
'ispoint': False,<br />
'label': '',<br />
'peak': {'error': 0.007763106951837918,<br />
'unit': 'Jy/beam',<br />
'value': 7.694798098602945},<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.8 mJy with an error of 0.1 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 375.6 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 14.4 mJy<br />
| style="text-align:center;"| 0.04 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 60.1 mJy<br />
| style="text-align:center;"| 0.09 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.8 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.3 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179163C286 Band6Pol Calibration for CASA 4.32015-07-27T13:12:16Z<p>Paladino: /* Imaging of the polarization calibrator with and without applying D-terms corrections */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This test will be done in the following section.<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
mask=mask= '3c286_StokesIQUV_selfcal.mask',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179153C286 Band6Pol Calibration for CASA 4.32015-07-27T13:09:10Z<p>Paladino: /* Solving for the Leakage Terms */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This test will be done in the following section.<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179143C286 Band6Pol Calibration for CASA 4.32015-07-27T13:01:29Z<p>Paladino: /* Solving for the Leakage Terms */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
This solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179133C286 Band6Pol Calibration for CASA 4.32015-07-27T12:51:22Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179123C286 Band6Pol Calibration for CASA 4.32015-07-27T12:42:41Z<p>Paladino: /* Cross-hand delay */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gain tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179113C286 Band6Pol Calibration for CASA 4.32015-07-27T12:38:44Z<p>Paladino: /* Gains for the polarization calibrator */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all the polarization contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable, which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179103C286 Band6Pol Calibration for CASA 4.32015-07-27T12:30:15Z<p>Paladino: /* Polarization Calibration */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179093C286 Band6Pol Calibration for CASA 4.32015-07-27T12:17:19Z<p>Paladino: /* Gain Calibration */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3': to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux table *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp table when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=179083C286 Band6Pol Calibration for CASA 4.32015-07-27T12:07:07Z<p>Paladino: /* Calibrating the data */</p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. '''To follow this guide you must have downloaded the file 3C286_Band6_UncalibratedData.tgz from [[3C286_Polarization#Obtaining the Data]]'''.<br />
<br />
Details of the ALMA observations are provided at '''[[3C286_Polarization]]'''.<br />
<br />
To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3.'''<br />
<br />
==Unpack the Data==<br />
<br />
Once the file 3C286_Band6_UncalibratedData.tgz has been download, unpack it as follows:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet extracted from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide]).<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 4.3.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Polarization&diff=175533C286 Polarization2015-07-15T15:01:52Z<p>Paladino: /* ALMA Data Overview */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
[[Category:ALMA]][[Category:Polarization]][[Category:Continuum]]<br />
<br />
==Science Target Overview==<br />
<figure id="1.4_4.8maps"><br />
[[File:3c286_14_48.png|200px|thumb|right|<xr id="1.4_4.8maps" nolink/>. Maps of 3C286 at 1.4 and 4.8 GHz. (Akujor & Garrington 1995)]]<br />
</figure><br />
<br />
<figure id="8.4map"><br />
[[File:VLA_3c286.png|200px|thumb|right|<xr id="8.4map" nolink/>. 3C286 map at 8.4 GHz. The jet to the W of the core is highly polarized with E-vectors parallel to the jet axis at 8.4 GHz. (Akujor & Garrington 1995) ]]<br />
</figure><br />
<br />
<br />
These observations have been taken with the aim of testing ALMA polarization capabilities. <br />
<br />
The target observed is 3C286: a bright, compact, steep-spectrum radio quasar at a redshift of 0.849 (e.g. [http://adsabs.harvard.edu/cgi-bin/bib_query?2010MNRAS.405.2302H Hewett & Wild et al. 2010]).<br />
Radio imaging with the Very Large Array (VLA) at subarcsecond resolution has revealed an extended structure composed of three misaligned bright <br />
features. The linear polarization emission is dominated by the two brightest features (see <xr id="1.4_4.8maps" /> and <xr id="8.4map" /> ), and the electric vector position angle is oriented nearly parallel to the axis of the jet like structure between them ([http://adsabs.harvard.edu/abs/1995A%26AS..112..235A Akujor & Garringon 1995]).<br />
This source has been widely used as calibrator at centimeter radio wavelengths both for total intensity and linear polarization observations.<br />
Recently [http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of millimeter measurements with the IRAM 30 m Telescope; they suggest that 3C286 can be used as a <br />
new calibrator for both single-dish and interferometric polarization observations at 3mm and possibly at shorter wavelengths.<br />
Their observations at 1 and 3 mm produced the following results: <br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| 1 mm<br />
| style="text-align:center;"| 3 mm<br />
|-<br />
| S (Jy)<br />
| style="text-align:center;"| 0.30 ± 0.03<br />
| style="text-align:center;"| 0.91 ± 0.02<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|33.1 ± 5.7<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
Interferometric polarization data of 3C286 have also been taken using CARMA and are reported in both [http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and in [https://www.mmarray.org/memos/#64 CARMA Memo 64]. The polarization position angle reported for 3C286 is '''39.2 ± 1°''' at 1 mm.<br />
<br />
The results obtained from the ALMA SV observations in band 6 will be compared with these available measurements.<br />
<br />
==ALMA Data Overview==<br />
<br />
This CASA Guide shows the calibration and imaging steps for the ALMA Science Verification data <br />
in full polarization targeting the quasar 3C286. <br />
<br />
The ALMA Science verification observations on 3C286 in Band 6, were taken in three<br />
different datasets (or 1 session) on July 1st, 2014. <br />
<br />
The observations are broken down into three individual data sets, as follows:<br />
<br />
* '''uid___A002_X85c183_X10a.ms''' <br />
* '''uid___A002_X85c183_X51a.ms''' <br />
* '''uid___A002_X85c183_X822.ms'''<br />
<br />
All four cross correlations (XX, XY, YX, and YY) measurements were observed using a spectral setup with<br />
four 2 GHz spectral windows of 64 channels each (TDM mode with 31.25 MHz resolution<br />
per channel). To calibrate the instrumental polarization, we sampled a polarized<br />
source (J1337-1257) as a function of paralactic angle every 30 minutes for 5 minutes<br />
per sample. The strongly polarized source 3C279 was also observed as a bandpass calibrator; however, <br />
it can also be used to check the instrumental polarization calibration.<br />
<br />
Using the data for publication: The following statement should be included in the acknowledgment of papers using the datasets listed above: “This paper makes use of the following ALMA data: ADS/JAO.ALMA#2011.0.00003.SV. ALMA is a partnership of ESO (representing its member states), NSF (USA) and NINS (Japan), together with NRC (Canada) and NSC and ASIAA (Taiwan), in cooperation with the Republic of Chile. The Joint ALMA Observatory is operated by ESO, AUI/NRAO and NAOJ.”<br />
<br />
==Obtaining the Data==<br />
<br />
'''TO BE UPDATED'''<br />
<br />
To download the data, click on the region closest to your location:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286_pol North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286_pol Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286_pol East Asia]<br />
<br />
Here you will find three gzipped tar files which, after unpacking, will create three directories:<br />
<br />
*'''3C286_Band6_pol_UnCalibratedMS''' - Here we provide you with "starter" datasets, where we have taken the raw data in ALMA Science Data Model (ASDM) format and converted them to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. <br />
<br />
*'''3C286_Band6_pol_ReferenceImages''' - The final total intensity and polarization images<br />
<br />
To see which files you will need, read on below. The downloads to your local computer will take some time, so you may wish to begin them now.<br />
<br />
'''NOTE: CASA 4.3 or later is required to follow this guide.''' For more information on obtaining the latest version of CASA, see [http://casa.nrao.edu/ http://casa.nrao.edu].<br />
<br />
==3C286 Polarization Data Reduction Tutorial==<br />
<br />
The casaguide for reducing these data '''using CASA version 4.3''' has been split into calibration and imaging pages:<br />
<br />
1) '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]'''<br />
<br />
2) '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
You will need to run both scripts in order to get the final images and polarization results.<br />
The data needed are available in the directory 3C286_Band6_pol_UnCalibratedMS<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml.<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to use this casaguide==<br />
<br />
For both portions of the guide, we will provide you with the full CASA commands needed to carry out each step. <br />
<br />
<source lang="python"><br />
# In CASA<br />
The commands you need to execute <br />
will be displayed in regions <br />
like this. <br />
</source><br />
<br />
Simply copy and paste the commands into your CASA terminal. You may also type the commands in by hand if desired, but be mindful of typos. Note that you may need to hit Enter twice in order for the process to start running. Also note that copying and pasting multiple commands at a time may not work, so only copy and paste the contents of one region at a time. <br />
<br />
'''To learn how to extract the CASA commands into an executable python script, click [http://casaguides.nrao.edu/index.php?title=Extracting_scripts_from_these_tutorials here].'''<br />
<br />
Occasionally we will also show output to the CASA logger:<br />
<br />
<pre style="background-color: #fffacd;"><br />
This output will be displayed <br />
in regions like this.<br />
</pre><br />
<br />
For a brief introduction to the different ways CASA can be run, click [http://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide here]. For further help getting started with CASA, click [http://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA here].</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Polarization&diff=175523C286 Polarization2015-07-15T15:01:24Z<p>Paladino: /* ALMA Data Overview */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
[[Category:ALMA]][[Category:Polarization]][[Category:Continuum]]<br />
<br />
==Science Target Overview==<br />
<figure id="1.4_4.8maps"><br />
[[File:3c286_14_48.png|200px|thumb|right|<xr id="1.4_4.8maps" nolink/>. Maps of 3C286 at 1.4 and 4.8 GHz. (Akujor & Garrington 1995)]]<br />
</figure><br />
<br />
<figure id="8.4map"><br />
[[File:VLA_3c286.png|200px|thumb|right|<xr id="8.4map" nolink/>. 3C286 map at 8.4 GHz. The jet to the W of the core is highly polarized with E-vectors parallel to the jet axis at 8.4 GHz. (Akujor & Garrington 1995) ]]<br />
</figure><br />
<br />
<br />
These observations have been taken with the aim of testing ALMA polarization capabilities. <br />
<br />
The target observed is 3C286: a bright, compact, steep-spectrum radio quasar at a redshift of 0.849 (e.g. [http://adsabs.harvard.edu/cgi-bin/bib_query?2010MNRAS.405.2302H Hewett & Wild et al. 2010]).<br />
Radio imaging with the Very Large Array (VLA) at subarcsecond resolution has revealed an extended structure composed of three misaligned bright <br />
features. The linear polarization emission is dominated by the two brightest features (see <xr id="1.4_4.8maps" /> and <xr id="8.4map" /> ), and the electric vector position angle is oriented nearly parallel to the axis of the jet like structure between them ([http://adsabs.harvard.edu/abs/1995A%26AS..112..235A Akujor & Garringon 1995]).<br />
This source has been widely used as calibrator at centimeter radio wavelengths both for total intensity and linear polarization observations.<br />
Recently [http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of millimeter measurements with the IRAM 30 m Telescope; they suggest that 3C286 can be used as a <br />
new calibrator for both single-dish and interferometric polarization observations at 3mm and possibly at shorter wavelengths.<br />
Their observations at 1 and 3 mm produced the following results: <br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| 1 mm<br />
| style="text-align:center;"| 3 mm<br />
|-<br />
| S (Jy)<br />
| style="text-align:center;"| 0.30 ± 0.03<br />
| style="text-align:center;"| 0.91 ± 0.02<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|33.1 ± 5.7<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
Interferometric polarization data of 3C286 have also been taken using CARMA and are reported in both [http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and in [https://www.mmarray.org/memos/#64 CARMA Memo 64]. The polarization position angle reported for 3C286 is '''39.2 ± 1°''' at 1 mm.<br />
<br />
The results obtained from the ALMA SV observations in band 6 will be compared with these available measurements.<br />
<br />
==ALMA Data Overview==<br />
<br />
This CASA Guide shows the calibration and imaging steps for the ALMA Science Verification data <br />
in full polarization targeting the quasar 3C286. <br />
<br />
The ALMA Science verification observations on 3C286 in Band 6, were taken in three<br />
different datasets (or 1 session) on July 1st, 2014. <br />
<br />
<br />
The observations are broken down into three individual data sets, as follows:<br />
<br />
* '''uid___A002_X85c183_X10a.ms''' <br />
* '''uid___A002_X85c183_X51a.ms''' <br />
* '''uid___A002_X85c183_X822.ms'''<br />
<br />
All four cross correlations (XX, XY, YX, and YY) measurements were observed using a spectral setup with<br />
four 2 GHz spectral windows of 64 channels each (TDM mode with 31.25 MHz resolution<br />
per channel). To calibrate the instrumental polarization, we sampled a polarized<br />
source (J1337-1257) as a function of paralactic angle every 30 minutes for 5 minutes<br />
per sample. The strongly polarized source 3C279 was also observed as a bandpass calibrator; however, <br />
it can also be used to check the instrumental polarization calibration.<br />
<br />
<br />
Using the data for publication: The following statement should be included in the acknowledgment of papers using the datasets listed above: “This paper makes use of the following ALMA data: ADS/JAO.ALMA#2011.0.00003.SV. ALMA is a partnership of ESO (representing its member states), NSF (USA) and NINS (Japan), together with NRC (Canada) and NSC and ASIAA (Taiwan), in cooperation with the Republic of Chile. The Joint ALMA Observatory is operated by ESO, AUI/NRAO and NAOJ.”<br />
<br />
==Obtaining the Data==<br />
<br />
'''TO BE UPDATED'''<br />
<br />
To download the data, click on the region closest to your location:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286_pol North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286_pol Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286_pol East Asia]<br />
<br />
Here you will find three gzipped tar files which, after unpacking, will create three directories:<br />
<br />
*'''3C286_Band6_pol_UnCalibratedMS''' - Here we provide you with "starter" datasets, where we have taken the raw data in ALMA Science Data Model (ASDM) format and converted them to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. <br />
<br />
*'''3C286_Band6_pol_ReferenceImages''' - The final total intensity and polarization images<br />
<br />
To see which files you will need, read on below. The downloads to your local computer will take some time, so you may wish to begin them now.<br />
<br />
'''NOTE: CASA 4.3 or later is required to follow this guide.''' For more information on obtaining the latest version of CASA, see [http://casa.nrao.edu/ http://casa.nrao.edu].<br />
<br />
==3C286 Polarization Data Reduction Tutorial==<br />
<br />
The casaguide for reducing these data '''using CASA version 4.3''' has been split into calibration and imaging pages:<br />
<br />
1) '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]'''<br />
<br />
2) '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
You will need to run both scripts in order to get the final images and polarization results.<br />
The data needed are available in the directory 3C286_Band6_pol_UnCalibratedMS<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml.<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to use this casaguide==<br />
<br />
For both portions of the guide, we will provide you with the full CASA commands needed to carry out each step. <br />
<br />
<source lang="python"><br />
# In CASA<br />
The commands you need to execute <br />
will be displayed in regions <br />
like this. <br />
</source><br />
<br />
Simply copy and paste the commands into your CASA terminal. You may also type the commands in by hand if desired, but be mindful of typos. Note that you may need to hit Enter twice in order for the process to start running. Also note that copying and pasting multiple commands at a time may not work, so only copy and paste the contents of one region at a time. <br />
<br />
'''To learn how to extract the CASA commands into an executable python script, click [http://casaguides.nrao.edu/index.php?title=Extracting_scripts_from_these_tutorials here].'''<br />
<br />
Occasionally we will also show output to the CASA logger:<br />
<br />
<pre style="background-color: #fffacd;"><br />
This output will be displayed <br />
in regions like this.<br />
</pre><br />
<br />
For a brief introduction to the different ways CASA can be run, click [http://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide here]. For further help getting started with CASA, click [http://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA here].</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Polarization&diff=175513C286 Polarization2015-07-15T14:35:58Z<p>Paladino: /* ALMA Data Overview */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
[[Category:ALMA]][[Category:Polarization]][[Category:Continuum]]<br />
<br />
==Science Target Overview==<br />
<figure id="1.4_4.8maps"><br />
[[File:3c286_14_48.png|200px|thumb|right|<xr id="1.4_4.8maps" nolink/>. Maps of 3C286 at 1.4 and 4.8 GHz. (Akujor & Garrington 1995)]]<br />
</figure><br />
<br />
<figure id="8.4map"><br />
[[File:VLA_3c286.png|200px|thumb|right|<xr id="8.4map" nolink/>. 3C286 map at 8.4 GHz. The jet to the W of the core is highly polarized with E-vectors parallel to the jet axis at 8.4 GHz. (Akujor & Garrington 1995) ]]<br />
</figure><br />
<br />
<br />
These observations have been taken with the aim of testing ALMA polarization capabilities. <br />
<br />
The target observed is 3C286: a bright, compact, steep-spectrum radio quasar at a redshift of 0.849 (e.g. [http://adsabs.harvard.edu/cgi-bin/bib_query?2010MNRAS.405.2302H Hewett & Wild et al. 2010]).<br />
Radio imaging with the Very Large Array (VLA) at subarcsecond resolution has revealed an extended structure composed of three misaligned bright <br />
features. The linear polarization emission is dominated by the two brightest features (see <xr id="1.4_4.8maps" /> and <xr id="8.4map" /> ), and the electric vector position angle is oriented nearly parallel to the axis of the jet like structure between them ([http://adsabs.harvard.edu/abs/1995A%26AS..112..235A Akujor & Garringon 1995]).<br />
This source has been widely used as calibrator at centimeter radio wavelengths both for total intensity and linear polarization observations.<br />
Recently [http://adsabs.harvard.edu/abs/2012A%26A...541A.111A Agudo et al. (2012)] presented the results of millimeter measurements with the IRAM 30 m Telescope; they suggest that 3C286 can be used as a <br />
new calibrator for both single-dish and interferometric polarization observations at 3mm and possibly at shorter wavelengths.<br />
Their observations at 1 and 3 mm produced the following results: <br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| 1 mm<br />
| style="text-align:center;"| 3 mm<br />
|-<br />
| S (Jy)<br />
| style="text-align:center;"| 0.30 ± 0.03<br />
| style="text-align:center;"| 0.91 ± 0.02<br />
|-<br />
|P (%)<br />
|style="text-align:center;"|14.4 ± 1.8 <br />
|style="text-align:center;"|13.5 ± 0.3<br />
|-<br />
|χ (deg)<br />
|style="text-align:center;"|33.1 ± 5.7<br />
|style="text-align:center;"|37.3 ± 0.8<br />
|}<br />
<br />
Interferometric polarization data of 3C286 have also been taken using CARMA and are reported in both [http://arxiv.org/abs/1506.04771 Hull & Plambeck 2015 (JAI)] and in [https://www.mmarray.org/memos/#64 CARMA Memo 64]. The polarization position angle reported for 3C286 is '''39.2 ± 1°''' at 1 mm.<br />
<br />
The results obtained from the ALMA SV observations in band 6 will be compared with these available measurements.<br />
<br />
==ALMA Data Overview==<br />
<br />
This CASA Guide shows the calibration and imaging steps for the ALMA Science Verification data <br />
in full polarization targeting the quasar 3C286. <br />
<br />
The ALMA Science verification observations on 3C286 in Band 6, were taken in three<br />
different datasets (or 1 session) on July 1st, 2014. <br />
<br />
<br />
The observations are broken down into three individual data sets, as follows:<br />
<br />
- uid___A002_X85c183_X10a.ms <br />
- uid___A002_X85c183_X51a.ms <br />
- uid___A002_X85c183_X822.ms<br />
<br />
All four cross correlations (XX, XY, YX, and YY) measurements were observed using a spectral setup with<br />
four 2 GHz spectral windows of 64 channels each (TDM mode with 31.25 MHz resolution<br />
per channel). To calibrate the instrumental polarization, we sampled a polarized<br />
source (J1337-1257) as a function of paralactic angle every 30 minutes for 5 minutes<br />
per sample. The strongly polarized source 3C279 was also observed as a bandpass calibrator; however, <br />
it can also be used to check the instrumental polarization calibration.<br />
<br />
<br />
Using the data for publication: The following statement should be included in the acknowledgment of papers using the datasets listed above: “This paper makes use of the following ALMA data: ADS/JAO.ALMA#2011.0.00003.SV. ALMA is a partnership of ESO (representing its member states), NSF (USA) and NINS (Japan), together with NRC (Canada) and NSC and ASIAA (Taiwan), in cooperation with the Republic of Chile. The Joint ALMA Observatory is operated by ESO, AUI/NRAO and NAOJ.”<br />
<br />
==Obtaining the Data==<br />
<br />
'''TO BE UPDATED'''<br />
<br />
To download the data, click on the region closest to your location:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286_pol North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286_pol Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286_pol East Asia]<br />
<br />
Here you will find three gzipped tar files which, after unpacking, will create three directories:<br />
<br />
*'''3C286_Band6_pol_UnCalibratedMS''' - Here we provide you with "starter" datasets, where we have taken the raw data in ALMA Science Data Model (ASDM) format and converted them to CASA Measurement Sets (MS). We did this using the {{importasdm}} task in CASA. <br />
<br />
*'''3C286_Band6_pol_ReferenceImages''' - The final total intensity and polarization images<br />
<br />
To see which files you will need, read on below. The downloads to your local computer will take some time, so you may wish to begin them now.<br />
<br />
'''NOTE: CASA 4.3 or later is required to follow this guide.''' For more information on obtaining the latest version of CASA, see [http://casa.nrao.edu/ http://casa.nrao.edu].<br />
<br />
==3C286 Polarization Data Reduction Tutorial==<br />
<br />
The casaguide for reducing these data '''using CASA version 4.3''' has been split into calibration and imaging pages:<br />
<br />
1) '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]'''<br />
<br />
2) '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
You will need to run both scripts in order to get the final images and polarization results.<br />
The data needed are available in the directory 3C286_Band6_pol_UnCalibratedMS<br />
<br />
'''NOTE: CASA 4.3 is required to process the data using the guides above''' see http://casa.nrao.edu/casa_obtaining.shtml.<br />
<br />
NOTE: These guides are dynamic and will evolve as our understanding of how best to reduce ALMA data improves. Check back for updates periodically.<br />
<br />
==How to use this casaguide==<br />
<br />
For both portions of the guide, we will provide you with the full CASA commands needed to carry out each step. <br />
<br />
<source lang="python"><br />
# In CASA<br />
The commands you need to execute <br />
will be displayed in regions <br />
like this. <br />
</source><br />
<br />
Simply copy and paste the commands into your CASA terminal. You may also type the commands in by hand if desired, but be mindful of typos. Note that you may need to hit Enter twice in order for the process to start running. Also note that copying and pasting multiple commands at a time may not work, so only copy and paste the contents of one region at a time. <br />
<br />
'''To learn how to extract the CASA commands into an executable python script, click [http://casaguides.nrao.edu/index.php?title=Extracting_scripts_from_these_tutorials here].'''<br />
<br />
Occasionally we will also show output to the CASA logger:<br />
<br />
<pre style="background-color: #fffacd;"><br />
This output will be displayed <br />
in regions like this.<br />
</pre><br />
<br />
For a brief introduction to the different ways CASA can be run, click [http://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide here]. For further help getting started with CASA, click [http://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA here].</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=175503C286 Band6Pol Imaging for CASA 4.32015-07-15T14:17:45Z<p>Paladino: /* Stokes images */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
<br />
[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. If you did not complete the Calibration portion of the guide, then you can download the calibrated uvdata by clicking on the region closest to your location:<br />
<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/ North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/ Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/ East Asia]<br />
<br />
Once there, download the file '3C286_Band6_CalibratedData.tgz' to obtain the calibrated uvdata.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum image of 3C286 using {{clean}}. <br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.pol.cal.ms', spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first 100 iterations, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesI.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesI.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335 mJy. The dynamic range (ratio between peak and rms) is approximately 390.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesI.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesI.clean.png')<br />
</source><br />
<br />
'''This imview line does'nt actually make the image with the right scaling. Shall we leave it anyway, removing the scaling parameter, or should I add instructions to save the image from the viewer manually?'''<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286_I.G1p')<br />
gaincal(vis='3c286_Band6.pol.cal.ms',caltable='3c286_I.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.pol.cal.ms',field='',<br />
gaintable=['3c286_I.G1p'],calwt=F)<br />
<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesI_selfcal1.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286_I.G2p')<br />
gaincal(vis='3c286_Band6.pol.cal.ms',caltable='3c286_I.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
applycal(vis='3c286_Band6.pol.cal.ms',field='',<br />
gaintable=['3c286_I.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesI_selfcal2.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesI_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesI_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms level in this new image is ~0.2 mJy/beam, and it would possibly decrease more, by running another self-calibration with a smaller solint. However obtaining the best image is outside the scope of this casaguide so we stop here the self-calibration.<br />
<br />
=== Stokes images ===<br />
<br />
We now use the self-calibrated dataset to obtain the stokes Q,U, and V images separately.<br />
There is also the possibility to obtain a four-channels image containing all the Stokes IQUV; however, since <br />
we will need each image separately when we construct the polarization images, we make all of them separately. <br />
The first 100 iterations will be enough also for the stokes Q, U, and V.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesQ.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesQ.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='Q',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesQ.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesU.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesU.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='U',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesU.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesV.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesV.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='V',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesV.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesV.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data is not assured, and these data should not be used for scientific purposes'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.2<br />
| style="text-align:center;"| 0.03<br />
| style="text-align:center;"| 0.04<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|13.5<br />
|style="text-align:center;"|59.2<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|1886<br />
|style="text-align:center;"|475<br />
|style="text-align:center;"|1340<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.05 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI_selfcal2.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
<br />
'''This is the only way I found to make a dimensionless ratio image. Is there another way?'''<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.11566308]),<br />
'max': array([ 0.06068136]),<br />
'maxpos': array([125, 126, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.33.060, Plinear, 2.33e+11Hz',<br />
'mean': array([ 9.72262997e-05]),<br />
'medabsdevmed': array([ 1.64651265e-05]),<br />
'median': array([ 4.15569084e-05]),<br />
'min': array([ 2.38752932e-07]),<br />
'minpos': array([111, 45, 0, 0], dtype=int32),<br />
'minposf': '13:31:08.396, +30.30.24.960, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 3.37831989e-05]),<br />
'rms': array([ 0.00125804]),<br />
'sigma': array([ 0.00125429]),<br />
'sum': array([ 6.07664373]),<br />
'sumsq': array([ 0.09891639]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060681361705064774<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'flux': {'error': array([ 9.12414021e-05, 0.00000000e+00, 0.00000000e+00,<br />
0.00000000e+00]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06140752, 0. , 0. , 0. ])},<br />
'ispoint': True,<br />
'label': '',<br />
'shape': {'direction': {'error': {'latitude': {'unit': 'arcsec',<br />
'value': 0.0004379250999542519},<br />
'longitude': {'unit': 'arcsec',<br />
'value': 0.00013398095759761312}},<br />
'm0': {'unit': 'rad',<br />
'value': -2.743927590218412},<br />
'm1': {'unit': 'rad',<br />
'value': 0.5324854487458622},<br />
'refer': 'J2000',<br />
'type': 'direction'},<br />
'type': 'Point'},<br />
'spectrum': {'channel': 0,<br />
'frequency': {'m0': {'unit': 'GHz',<br />
'value': 233.000102969044},<br />
'refer': 'LSRK',<br />
'type': 'frequency'},<br />
'type': 'Constant'},<br />
'sum': {'unit': 'Jy/beam',<br />
'value': 1.6597465686500072}},<br />
'nelements': 1}<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.4 mJy with an error of 0.08 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI_selfcal2.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 374 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 13.82 mJy<br />
| style="text-align:center;"| 0.05 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 59.8 mJy<br />
| style="text-align:center;"| 0.08 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.41 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.5 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=175493C286 Band6Pol Imaging for CASA 4.32015-07-15T14:06:07Z<p>Paladino: /* Stokes images */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
<br />
[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. If you did not complete the Calibration portion of the guide, then you can download the calibrated uvdata by clicking on the region closest to your location:<br />
<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/ North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/ Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/ East Asia]<br />
<br />
Once there, download the file '3C286_Band6_CalibratedData.tgz' to obtain the calibrated uvdata.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum image of 3C286 using {{clean}}. <br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.pol.cal.ms', spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first 100 iterations, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesI.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesI.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335 mJy. The dynamic range (ratio between peak and rms) is approximately 390.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesI.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesI.clean.png')<br />
</source><br />
<br />
'''This imview line does'nt actually make the image with the right scaling. Shall we leave it anyway, removing the scaling parameter, or should I add instructions to save the image from the viewer manually?'''<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286_I.G1p')<br />
gaincal(vis='3c286_Band6.pol.cal.ms',caltable='3c286_I.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.pol.cal.ms',field='',<br />
gaintable=['3c286_I.G1p'],calwt=F)<br />
<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesI_selfcal1.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286_I.G2p')<br />
gaincal(vis='3c286_Band6.pol.cal.ms',caltable='3c286_I.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
applycal(vis='3c286_Band6.pol.cal.ms',field='',<br />
gaintable=['3c286_I.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesI_selfcal2.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesI_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesI_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms level in this new image is ~0.2 mJy/beam, and it would possibly decrease more, by running another self-calibration with a smaller solint. However obtaining the best image is outside the scope of this casaguide so we stop here the self-calibration.<br />
<br />
=== Stokes images ===<br />
<br />
We now use the self-calibrated dataset to obtain the stokes Q,U, and V images separately.<br />
There is also the possibility to obtain a four-channels image containing all the Stokes IQUV; however, since <br />
we will need each image separately when we construct the polarization images, we make all of them separately. <br />
The first 100 iterations will be enough also for the stokes Q, U, and V.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesQ.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesQ.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='Q',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesQ.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesU.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesU.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='U',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesU.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesV.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesV.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='V',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesV.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesV.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data is not assured, and these data should not be used for scientific purposes'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.2<br />
| style="text-align:center;"| 0.03<br />
| style="text-align:center;"| 0.04<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|13.5<br />
|style="text-align:center;"|59.2<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|1886<br />
|style="text-align:center;"|473<br />
|style="text-align:center;"|1340<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.05 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI_selfcal2.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
<br />
'''This is the only way I found to make a dimensionless ratio image. Is there another way?'''<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.11566308]),<br />
'max': array([ 0.06068136]),<br />
'maxpos': array([125, 126, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.33.060, Plinear, 2.33e+11Hz',<br />
'mean': array([ 9.72262997e-05]),<br />
'medabsdevmed': array([ 1.64651265e-05]),<br />
'median': array([ 4.15569084e-05]),<br />
'min': array([ 2.38752932e-07]),<br />
'minpos': array([111, 45, 0, 0], dtype=int32),<br />
'minposf': '13:31:08.396, +30.30.24.960, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 3.37831989e-05]),<br />
'rms': array([ 0.00125804]),<br />
'sigma': array([ 0.00125429]),<br />
'sum': array([ 6.07664373]),<br />
'sumsq': array([ 0.09891639]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060681361705064774<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'flux': {'error': array([ 9.12414021e-05, 0.00000000e+00, 0.00000000e+00,<br />
0.00000000e+00]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06140752, 0. , 0. , 0. ])},<br />
'ispoint': True,<br />
'label': '',<br />
'shape': {'direction': {'error': {'latitude': {'unit': 'arcsec',<br />
'value': 0.0004379250999542519},<br />
'longitude': {'unit': 'arcsec',<br />
'value': 0.00013398095759761312}},<br />
'm0': {'unit': 'rad',<br />
'value': -2.743927590218412},<br />
'm1': {'unit': 'rad',<br />
'value': 0.5324854487458622},<br />
'refer': 'J2000',<br />
'type': 'direction'},<br />
'type': 'Point'},<br />
'spectrum': {'channel': 0,<br />
'frequency': {'m0': {'unit': 'GHz',<br />
'value': 233.000102969044},<br />
'refer': 'LSRK',<br />
'type': 'frequency'},<br />
'type': 'Constant'},<br />
'sum': {'unit': 'Jy/beam',<br />
'value': 1.6597465686500072}},<br />
'nelements': 1}<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.4 mJy with an error of 0.08 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI_selfcal2.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 374 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 13.82 mJy<br />
| style="text-align:center;"| 0.05 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 59.8 mJy<br />
| style="text-align:center;"| 0.08 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.41 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.5 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.3&diff=175483C286 Band6Pol Imaging for CASA 4.32015-07-15T13:50:44Z<p>Paladino: /* Full polarization imaging of the target */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
<br />
[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the imaging of the <br />
total power and polarized emission.<br />
<br />
This guide picks up where the '''[[3C286_Band6Pol_Calibration_for_CASA_4.3]]''' section left off: right after running the CASA task {{split}} to split off the science target from the rest of the measurement set following calibration. If you completed the Calibration section of the guide, then you can continue where you left off, with 3c286_Band6.pol.cal.ms. If you did not complete the Calibration portion of the guide, then you can download the calibrated uvdata by clicking on the region closest to your location:<br />
<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/ North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/ Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/ East Asia]<br />
<br />
Once there, download the file '3C286_Band6_CalibratedData.tgz' to obtain the calibrated uvdata.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_CalibratedData.tgz<br />
<br />
cd 3C286_Band6_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have 3c286_Band6.pol.cal.ms in your working directory.<br />
<br />
<br />
==Full polarization imaging of the target==<br />
<br />
We will start by making a continuum image of 3C286 using {{clean}}. <br />
Before starting the cleaning, it makes sense to check if the emission is resolved or not by plotting amplitude as a function of uv-distance.<br />
The higher amplitudes at shorter uv-distances suggest that the source is slightly resolved.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.pol.cal.ms', spw='', xaxis='uvwave', yaxis='amp', correlation='XX,YY',<br />
avgtime='1e8', avgchannel='1000', coloraxis='baseline')<br />
</source><br />
<br />
[[File:target_uvplot_casa4.3.png|200px|thumb|right|Amplitude vs. uv-distance. The source seems to be slightly resolved.]]<br />
<br />
This plot also helps us defining the cellsize needed for the task clean.<br />
From the plot we see that the longest baseline is 500 kilo wavelength. This means that the maximum resolution can be<br />
approximately 1/500000*206265 arcsec = 0.4 arcsec.<br />
We will use a '''cellsize=0.1''', to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 6 is about 25 arcsec, and we want to image out to at least that extent, so we will use '''imsize=250'''.<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
<br />
</source><br />
<br />
Specifying '''interactive=T''' , the {{clean}} task brings up a viewer to show the residual clean image, clean masks can be defined, and when the residuals are noise-like, the cleaning process can be interrupted, hiting the red X symbol. <br />
Please note that the cleaning will not start without any active mask (to activate a mask you need to double click inside the region). <br />
See [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TW Hydra casaguide] for further details on the interactive use of clean.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is important, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
After the first 100 iterations, using an elliptical clean box around the central source, the residuals are already noise-like, so you can stop the cleaning. <br />
You can use the viewer to look at your image. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286.cal.StokesI.clean.image')<br />
</source><br />
<br />
[[File:I_newimage.png|200px|thumb|right|Total intensity image of 3C286]]<br />
<br />
We will determine some statistics for the image using the task {{imstat}} (some details are given below):<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesI.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesI.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
This tells us that the rms of this image is 0.8 mJy and the peak flux density is ~335 mJy. The dynamic range (ratio between peak and rms) is approximately 390.<br />
<br />
For future reference, we create a png file of the continuum image:<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesI.clean.png')<br />
imview(raster={'file': '3c286.cal.StokesI.clean.image', 'colorwedge':T,<br />
'range':[-0.006, 0.4], 'scaling':-0.6, 'colormap':'Rainbow 2'},<br />
out='3c286.cal.StokesI.clean.png')<br />
</source><br />
<br />
'''This imview line does'nt actually make the image with the right scaling. Shall we leave it anyway, removing the scaling parameter, or should I add instructions to save the image from the viewer manually?'''<br />
<br />
=== Self-calibration ===<br />
<br />
The quality of the image can be improved by applying the self-calibration to the uv data, <br />
see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.3 Antennae] and [http://casaguides.nrao.edu/index.php?title=TWHydraBand7_Imaging_3.4 TwHidra] guides for details on this technique.<br />
<br />
The task {{clean}} has automatically saved a model in the header of the measurement set, we use it to self-calibrate <br />
through the task {{gaincal}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286_I.G1p')<br />
gaincal(vis='3c286_Band6.pol.cal.ms',caltable='3c286_I.G1p',<br />
solint='300s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
</source><br />
<br />
The critical parameters in this setup are '''solint''' and '''calmode'''.<br />
We want to calculate phase solutions only so we use '''calmode=p''' and we start using '''solint=300s''', which means averaging 30 visibilities in the solution calculation.<br />
It is usually best to start with a large solint and then go down to the integration time if the S/N of the data permits. <br />
<br />
Now we apply those solutions to the uv data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.pol.cal.ms',field='',<br />
gaintable=['3c286_I.G1p'],calwt=F)<br />
<br />
<br />
</source><br />
<br />
and make a new image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286.cal.StokesI_selfcal1.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI_selfcal1.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
The rms of this new image is 0.25 mJy/beam, lower than the value measured in the first image (0.8 mJy/beam).<br />
We run a second self-calibration, decreasing to 30 sec the solint, apply it to the data, and image it again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf 3c286_I.G2p')<br />
gaincal(vis='3c286_Band6.pol.cal.ms',caltable='3c286_I.G2p',<br />
solint='30s',<br />
refant='DV23',minblperant=4,<br />
calmode='p',minsnr=4)<br />
<br />
applycal(vis='3c286_Band6.pol.cal.ms',field='',<br />
gaintable=['3c286_I.G2p'],calwt=F)<br />
<br />
os.system('rm -rf 3c286.cal.StokesI_selfcal2.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesI_selfcal2.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='I',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286.cal.StokesI_selfcal2.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesI_selfcal2.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The rms level in this new image is ~0.2 mJy/beam, and it would possibly decrease more, by running another self-calibration with a smaller solint. However obtaining the best image is outside the scope of this casaguide so we stop here the self-calibration.<br />
<br />
=== Stokes images ===<br />
<br />
We now use the self-calibrated dataset to obtain the stokes Q,U, and V images separately.<br />
There is also the possibility to obtain a four-channels image containing all the Stokes IQUV; however, since <br />
we will need each image separately when we construct the polarization images, we make all of them separately. <br />
The first 100 iterations will be enough also for the stokes Q, U, and V.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesQ.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesQ.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='Q',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesQ.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesQ.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesU.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesU.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='U',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesU.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesU.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286.cal.StokesV.clean*')<br />
clean(vis='3c286_Band6.pol.cal.ms',<br />
imagename='3c286.cal.StokesV.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
mask= 'circle[[13h31m08.286s,+30d30m33.006s ], 2.3arcsec]',<br />
stokes='V',<br />
interactive=T,<br />
niter=1000)<br />
<br />
calstat=imstat(imagename='3c286.cal.StokesV.clean.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='3c286.cal.StokesV.clean.image', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in continuum image: '+str(peak)<br />
print '>> Dynamic range in continuum image: '+str(peak/rms)<br />
</source><br />
<br />
The results of the measurements for the I, Q, and U images are reported in the table below. All flux densities are reported in mJy/beam.<br />
The results obtained from the V image are not reported in the table, since '''at this time the quality and accuracy of the circular polarization data is not assured, and these data should not be used for scientific purposes'''.<br />
<br />
{| class="wikitable"<br />
| <br />
| style="text-align:center;"| I<br />
| style="text-align:center;"| Q<br />
| style="text-align:center;"| U<br />
|-<br />
| rms <br />
| style="text-align:center;"| 0.2<br />
| style="text-align:center;"| 0.03<br />
| style="text-align:center;"| 0.04<br />
|-<br />
|Peak<br />
|style="text-align:center;"|368.3 <br />
|style="text-align:center;"|13.5<br />
|style="text-align:center;"|59.2<br />
|-<br />
|Dyn range<br />
|style="text-align:center;"|1890<br />
|style="text-align:center;"|473<br />
|style="text-align:center;"|1340<br />
|}<br />
<br />
==Constructing Polarization Intensity and Angle Images==<br />
<br />
We have now produced the images for all the four Stokes parameters: I, Q, U, and V. Stokes Q and U describe the linear polarization and V describes the circular polarization. Specifically, Q describes the amount of linear polarization aligned with a given axis, and U describes the amount of linear polarization at a 45 deg angle to that axis. The V parameter describes the amount of circular polarization, with the sign (positive or negative) describing the sense of the circular polarization (right- or left-hand circularly polarized).<br />
<br />
In general, few celestial sources are expected to show circular polarization, with the notable exception of masers. Terrestrial and satellite sources are often highly circularly polarized. The V image is therefore often worth forming because any V emission could be indicative of unflagged RFI within the data (or problems with the calibration!).<br />
<br />
Because the Q and U images both describe the amount of linear polarization, it is more common to work with a linear polarization intensity image, <math>P = \sqrt{Q^2 +U^2}</math>. We can also calculate the polarization position angle <math>\chi = 0.5 arctan U/Q</math>.<br />
<br />
The relevant task is {{immath}}; for specific examples of polarization image processing see<br />
[http://casa.nrao.edu/docs/UserMan/UserMansu309.html Polarization Manipulation]. <br />
<br />
To form the linear polarization image, we combine the Q and U images using the mode='poli' option of {{immath}}.<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLI')<br />
immath(outfile='3c286_Band6.POLI',<br />
mode='poli',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
sigma='0.0Jy/beam')<br />
</source><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='3c286_Band6.POLI', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
</source><br />
The measured rms is 0.05 mJy/beam.<br />
<br />
To form the polarization position angle image we combine again the Q and U images using the mode='pola' option of {{immath}}. The Q and U images can be listed in either order. <br />
To avoid displaying the position angle of noise, we can use the polithresh parameter to set a threshold intensity of the linear polarization above which we wish to calculate the polarization angle. An appropriate level here might be the 5σ level of the polarization image, about 1 mJy/beam. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.POLA')<br />
immath(outfile='3c286_Band6.POLA',<br />
mode='pola',<br />
imagename=['3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
polithresh='0.5mJy/beam')<br />
</source><br />
<br />
If desired, it is also possible to form the fractional linear polarization image, defined as P/I. <br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.RATIO')<br />
immath(outfile='3c286_Band6.RATIO',<br />
mode='evalexpr',<br />
imagename=['3c286.cal.StokesI_selfcal2.clean.image','3c286.cal.StokesQ.clean.image','3c286.cal.StokesU.clean.image'],<br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)')<br />
</source><br />
Since the total intensity image can (and hopefully does) approach zero in regions free of source emission, dividing by the total intensity can produce very high pixel values in these regions. We therefore wish to restrict our fractional polarization image to regions containing real emission, which we do by setting a threshold in the total intensity image, which in this case corresponds to five times the noise level in the Stokes I image. The computation of the polarized intensity is specified in the previous command by <br />
<pre style="background-color: #fffacd;"><br />
expr='sqrt((IM1^2+IM2^2)/IM0[IM0>5e-3]^2)'<br />
</pre><br />
with the expression in square brackets setting the threshold in IM0 (the total intensity image). Note that IM0, IM1 and IM2 correspond to the three files listed in the ''imagename'' array, '''in that order'''. In this case, the order in which the different images are specified is critical.<br />
<br />
<br />
'''This is the only way I found to make a dimensionless ratio image. Is there another way?'''<br />
<br />
In order to have a dimensionless value for the ratio image, we now modify the keyword bunit in the header of the file:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead('3c286_Band6.RATIO', mode='put', hdkey='bunit', hdvalue='')<br />
</source><br />
<br />
==Image visualization and analysis==<br />
<br />
Now we can view these various images using {{viewer}}. It is instructive to display the I, P, and <math>\chi</math> images (total intensity, total linearly polarized intensity, and polarization position angle) together, to show how the polarized emission relates to the total intensity, and how the magnetic field is structured. We can do this using the viewer.<br />
* Begin by loading the linear polarization image in the viewer:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c286_Band6.POLI')<br />
</source><br />
* Next, load the total intensity image as a contour image. In the viewer panel, hit the "Open" icon (the leftmost button in the top row of icons in the viewer). This will bring up a 'Load Data' GUI showing all images and MS in the current directory. Select the total intensity image (3c286.cal.StokesI.clean.image) and click the 'Contour Map' button on the right hand side.<br />
* Finally, load the polarization position angle image (3c286_Band6.POLA) as a vector map.<br />
[[File:Pol_cont_vect.png.png|200px|thumb|right|Full-polarization image of 3C286]]<br />
<br />
While we set the ''polithresh'' parameter when we created the position angle (<math>\chi</math>) image, a digression here is instructive in the use of LEL Expressions. Had we not set this parameter, the position angle would have been derived for all pixels within the full IQUV image cube. There is only polarized emission from a limited subset of pixels within this image. Therefore, to avoid plotting vectors corresponding to the position angle of pure noise, we now wish to select only the regions where the polarized intensity is brighter than some threshold value. To do this, we use an LEL (Lattice Expression Language) Expression in the 'Load Data' GUI. For our chosen threshold of 0.4 mJy/beam (the 5 sigma level in the P image), we paste the expression <br />
<pre style="background-color: #fffacd;"><br />
'3c286_Band6.POLA'['3c286_Band6.POLI'>0.001]<br />
</pre><br />
into the LEL Expression box in the GUI, and click the 'Vector Map' button. This would load the vectors only for regions where P>1 mJy/beam.<br />
<br />
To optimize the display for ease of interpretation we click the wrench icon to open a 'Data Display Options' GUI. This will have 3 tabs, corresponding to the three images loaded. <br />
We can change the image color map and transfer function, the contour levels and color, and the the vector spacing and color.<br />
<br />
For the polarization angle vector it is also possible to add a rotation.<br />
The polarization position angle as calculated is the electric vector position angle (EVPA). If we are interested in the orientation of the magnetic field, then for an optically thin source the magnetic field orientation is perpendicular to the EVPA, so we must rotate the vectors by 90 degrees. Select the vector image tab in the 'Data Display Options' GUI (labeled as the LEL expression we entered in the Load Data GUI) and enter ''90'' in the ''Extra rotation'' box. If the vectors appear too densely packed on the image, change the spacing of the vectors by setting ''X-increment'' and ''Y-increment'' to a larger value. <br />
<br />
To get quantitative information from the images, we can either use the task {{imstat}} (we already used it above) or the <br />
task {{imfit}}. <br />
The task {{imstat}} returns the statistics in a Python dictionary, from which we can read what we need in a Python variable. In this example we extract the peak value:<br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA<1> calstat=imstat(imagename='3c286_Band6.POLI', region='')<br />
<br />
CASA<2> calstat<br />
Out[1]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '13:31:09.255, +30.30.20.460, Plinear, 2.33e+11Hz',<br />
'flux': array([ 0.11566308]),<br />
'max': array([ 0.06068136]),<br />
'maxpos': array([125, 126, 0, 0], dtype=int32),<br />
'maxposf': '13:31:08.288, +30.30.33.060, Plinear, 2.33e+11Hz',<br />
'mean': array([ 9.72262997e-05]),<br />
'medabsdevmed': array([ 1.64651265e-05]),<br />
'median': array([ 4.15569084e-05]),<br />
'min': array([ 2.38752932e-07]),<br />
'minpos': array([111, 45, 0, 0], dtype=int32),<br />
'minposf': '13:31:08.396, +30.30.24.960, Plinear, 2.33e+11Hz',<br />
'npts': array([ 62500.]),<br />
'quartile': array([ 3.37831989e-05]),<br />
'rms': array([ 0.00125804]),<br />
'sigma': array([ 0.00125429]),<br />
'sum': array([ 6.07664373]),<br />
'sumsq': array([ 0.09891639]),<br />
'trc': array([249, 249, 0, 0], dtype=int32),<br />
'trcf': '13:31:07.329, +30.30.45.360, Plinear, 2.33e+11Hz'}<br />
<br />
CASA <2>: calstat['max'][0] <br />
Out[2]: 0.060681361705064774<br />
</pre><br />
<br />
The task {{imfit}} finds one or more elliptical gaussian components on an image region.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fit_res=imfit(imagename='3c286_Band6.POLI', region='')<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
CASA <3>: fit_res<br />
Out[3]: <br />
{'converged': array([ True], dtype=bool),<br />
'deconvolved': {'component0': {'flux': {'error': array([ 9.12414021e-05, 0.00000000e+00, 0.00000000e+00,<br />
0.00000000e+00]),<br />
'polarisation': 'Stokes',<br />
'unit': 'Jy',<br />
'value': array([ 0.06140752, 0. , 0. , 0. ])},<br />
'ispoint': True,<br />
'label': '',<br />
'shape': {'direction': {'error': {'latitude': {'unit': 'arcsec',<br />
'value': 0.0004379250999542519},<br />
'longitude': {'unit': 'arcsec',<br />
'value': 0.00013398095759761312}},<br />
'm0': {'unit': 'rad',<br />
'value': -2.743927590218412},<br />
'm1': {'unit': 'rad',<br />
'value': 0.5324854487458622},<br />
'refer': 'J2000',<br />
'type': 'direction'},<br />
'type': 'Point'},<br />
'spectrum': {'channel': 0,<br />
'frequency': {'m0': {'unit': 'GHz',<br />
'value': 233.000102969044},<br />
'refer': 'LSRK',<br />
'type': 'frequency'},<br />
'type': 'Constant'},<br />
'sum': {'unit': 'Jy/beam',<br />
'value': 1.6597465686500072}},<br />
'nelements': 1}<br />
[...]<br />
</pre><br />
<br />
To extract the flux and its error, we can read them from CASA in Python variables:<br />
<source lang="python"><br />
# In CASA<br />
fluxPI=fit_res['results']['component0']['flux']['value'][0]<br />
errorPI=fit_res['results']['component0']['flux']['error'][0]<br />
</source><br />
<br />
The flux measured in the fitted gaussian is 61.4 mJy with an error of 0.08 mJy.<br />
<br />
We now use this method to estimate the fluxes in all the Stokes images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# First we run imfit <br />
resI=imfit(imagename = '3c286.cal.StokesI_selfcal2.clean.image', box = '110,110,145,145')<br />
resQ=imfit(imagename = '3c286.cal.StokesQ.clean.image', box = '110,110,145,145')<br />
resU=imfit(imagename = '3c286.cal.StokesU.clean.image', box = '110,110,145,145')<br />
resV=imfit(imagename = '3c286.cal.StokesV.clean.image', box = '110,110,145,145')<br />
<br />
# and then we extract the flux and error values for each Stokes<br />
<br />
fluxI=resI['results']['component0']['flux']['value'][0]<br />
errorI=resI['results']['component0']['flux']['error'][0]<br />
<br />
fluxQ=resQ['results']['component0']['flux']['value'][1]<br />
errorQ=resQ['results']['component0']['flux']['error'][1]<br />
<br />
fluxU=resU['results']['component0']['flux']['value'][2]<br />
errorU=resU['results']['component0']['flux']['error'][2]<br />
<br />
fluxV=resV['results']['component0']['flux']['value'][3]<br />
errorV=resV['results']['component0']['flux']['error'][3]<br />
<br />
</source> <br />
<br />
Now we use these values to compute polarization intensity, angle and ratio, and their errors:<br />
<br />
<source lang="python"><br />
# In CASA <br />
fluxPI = sqrt( fluxQ**2 + fluxU**2 )<br />
errorPI = sqrt( (fluxQ*errorU)**2 + (fluxU*errorQ)**2 ) / fluxPI<br />
<br />
fluxPImjy = 1000*fluxPI<br />
errPImjy = 1000*errorPI<br />
<br />
polRatio = fluxPI / fluxI<br />
errPRat = polRatio * sqrt( (errorPI/fluxPI)**2 + (errorI/fluxI)**2 )<br />
<br />
polAngle = 0.5 * degrees( atan2(fluxU,fluxQ) )<br />
errPA = 0.5 * degrees( errorPI / fluxPI )<br />
<br />
</source><br />
<br />
The results are collected in the following table:<br />
<br />
<center><br />
{| class="wikitable" <br />
| style="text-align:center;"| <br />
| style="text-align:center;"| Flux <br />
| style="text-align:center;"| err <br />
|-<br />
| style="text-align:center;"| I <br />
| style="text-align:center;"| 374 mJy<br />
| style="text-align:center;"| 0.35 mJy<br />
|-<br />
| style="text-align:center;"| Q <br />
| style="text-align:center;"| 13.82 mJy<br />
| style="text-align:center;"| 0.05 mJy<br />
|-<br />
| style="text-align:center;"| U <br />
| style="text-align:center;"| 59.8 mJy<br />
| style="text-align:center;"| 0.08 mJy<br />
|-<br />
! scope="col"| Pol int <br />
! scope="col"| 61.41 mJy<br />
! scope="col"| 0.05 mJy<br />
|-<br />
! scope="col"| Pol ratio <br />
! scope="col"| 0.16<br />
! scope="col"| 0.0002<br />
|-<br />
! scope="col"| Pol angle <br />
! scope="col"| 38.5 deg<br />
! scope="col"| 0.02 deg<br />
<br />
|}<br />
</center><br />
<br />
As you can see, the polarization intensity computed from the Q and U fluxes is the same as the one extracted from the polarization image (as it should be!).<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175473C286 Band6Pol Calibration for CASA 4.32015-07-15T10:51:51Z<p>Paladino: /* Applying the calibrations and splitting of the corrected data */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175463C286 Band6Pol Calibration for CASA 4.32015-07-15T09:39:57Z<p>Paladino: /* Applying the calibrations and splitting of the corrected data */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA41&DA48: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175453C286 Band6Pol Calibration for CASA 4.32015-07-15T09:39:14Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA41&DA48: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DA41: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175443C286 Band6Pol Calibration for CASA 4.32015-07-15T09:38:26Z<p>Paladino: /* Cross-hand delay */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DA41: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175433C286 Band6Pol Calibration for CASA 4.32015-07-15T09:37:42Z<p>Paladino: /* Cross-hand delay */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA41&DA48: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DA41: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=File:AfterAll_1baseline_phase.png&diff=17542File:AfterAll 1baseline phase.png2015-07-15T09:36:35Z<p>Paladino: Paladino uploaded a new version of &quot;File:AfterAll 1baseline phase.png&quot;</p>
<hr />
<div></div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175413C286 Band6Pol Calibration for CASA 4.32015-07-15T09:35:58Z<p>Paladino: /* Applying the calibrations and splitting of the corrected data */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DA41: XY and YX phase vs frequency after the whole calibration. All scans are averaged.]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175403C286 Band6Pol Calibration for CASA 4.32015-07-15T08:52:28Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs',<br />
'3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175393C286 Band6Pol Calibration for CASA 4.32015-07-15T08:50:38Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 <br />
(rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175383C286 Band6Pol Calibration for CASA 4.32015-07-15T08:41:36Z<p>Paladino: /* Gains for the polarization calibrator */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 <br />
U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 <br />
U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327<br />
U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 <br />
U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) <br />
P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175373C286 Band6Pol Calibration for CASA 4.32015-07-15T08:40:12Z<p>Paladino: /* Gains for the polarization calibrator */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405226704 Q= 0.0120290146946 U= 0.0357751032462 P= 0.0377432802867 X= 35.7076525043<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460130437 Q= 0.0121161477985 U= 0.0342484704653 P= 0.0363284842332 X= 35.2588247799<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477793757 Q= 0.0132551417327 U= 0.0365817946839 P= 0.0389092082244 X= 35.0411959343<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.99729825908 Q= 0.013549612772 U= 0.0372694902549 P= 0.0396561081062 X= 35.0104353733<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374792495 U= 0.0359687146626 (rms= 0.000673704330994 0.00112523439036 ) P= 0.038157460766 X= 35.2497952168<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175363C286 Band6Pol Calibration for CASA 4.32015-07-15T08:21:45Z<p>Paladino: /* Gain Calibration */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
To inspect the results we plot the corrected data for the bandpass and phase calibrators:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='parang', yaxis='amp', <br />
correlation='XX,YY', ydatacolumn='corrected', <br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175353C286 Band6Pol Calibration for CASA 4.32015-07-14T08:07:38Z<p>Paladino: /* Gain Calibration */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='1', spw='0', xaxis='', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgbaseline=T, coloraxis='corr')<br />
<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175343C286 Band6Pol Calibration for CASA 4.32015-07-14T08:02:50Z<p>Paladino: /* Gain Calibration */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight will be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', <br />
field='1',<br />
,<br />
<br />
)<br />
<br />
</source><br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175333C286 Band6Pol Calibration for CASA 4.32015-07-14T07:14:53Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UncalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_Band6_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_Band6_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms')<br />
split(vis='3c286_Band6_concat.ms', outputvis='3c286_Band6.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_Band6.ms', listfile='3c286_Band6.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_Band6.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_Band6.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_Band6.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_Band6.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G0ph')<br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Bscan')<br />
bandpass(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_Band6.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_Band6.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_Band6.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_Band6.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_Band6.ms.G2ph')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_Band6.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2amp')<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_Band6.ms.Bscan', '3c286_Band6.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_Band6.ms', <br />
caltable='3c286_Band6.ms.G2amp',<br />
fluxtable = '3c286_Band6.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight we be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G1')<br />
gaincal(vis = '3c286_Band6.ms',<br />
caltable = '3c286_Band6.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_Band6.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_Band6.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_Band6.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_Band6.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_Band6.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1', '3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.XY0amb') <br />
gaincal(vis='3c286_Band6.ms',caltable='3c286_Band6.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_Band6.ms.XY0amb',qu=qu[0],xyout='3c286_Band6.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_Band6.ms',<br />
field='0',<br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.G2.polcal') <br />
gaincal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_Band6.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_Band6.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.ms.Df0*') <br />
polcal(vis='3c286_Band6.ms',<br />
caltable='3c286_Band6.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_Band6.ms.Df0',dout='3c286_Band6.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs', '3c286_Band6.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal','3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_Band6.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_Band6.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2.polcal',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_Band6.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux',<br />
'3c286_Band6.ms.Kcrs','3c286_Band6.ms.XY0','3c286_Band6.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_Band6.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_Band6.pol.cal.ms') <br />
split(vis='3c286_Band6.ms',<br />
outputvis='3c286_Band6.pol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_Band6.pol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=File:J1337_afterBandG1_parang_casa4.3.png&diff=17516File:J1337 afterBandG1 parang casa4.3.png2015-07-13T16:46:54Z<p>Paladino: Paladino uploaded a new version of &quot;File:J1337 afterBandG1 parang casa4.3.png&quot;</p>
<hr />
<div></div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175153C286 Band6Pol Calibration for CASA 4.32015-07-13T16:17:19Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UnCalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_SV_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_SV_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms')<br />
split(vis='3c286_SV_concat.ms', outputvis='3c286_SV.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_SV.ms', listfile='3c286_SV.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_SV.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_SV.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_SV.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G0ph')<br />
gaincal(vis='3c286_SV.ms',caltable='3c286_SV.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.Bscan')<br />
bandpass(vis='3c286_SV.ms',caltable='3c286_SV.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_SV.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_SV.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_SV.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_SV.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_SV.ms.G2ph')<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_SV.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G2amp')<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_SV.ms.Bscan', '3c286_SV.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_SV.ms', <br />
caltable='3c286_SV.ms.G2amp',<br />
fluxtable = '3c286_SV.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2ph','3c286_SV.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight we be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G1')<br />
gaincal(vis = '3c286_SV.ms',<br />
caltable = '3c286_SV.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_SV.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_SV.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_SV.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_SV.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_SV.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1', '3c286_SV.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.XY0amb') <br />
gaincal(vis='3c286_SV.ms',caltable='3c286_SV.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1','3c286_SV.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_SV.ms.XY0amb',qu=qu[0],xyout='3c286_SV.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_SV.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms',<br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1','3c286_SV.ms.Kcrs','3c286_SV.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G2.polcal') <br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_SV.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_SV.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_SV.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.Df0*') <br />
polcal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs', '3c286_SV.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_SV.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_SV.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_SV.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_SV.ms.Df0',dout='3c286_SV.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs', '3c286_SV.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_SV.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_SV.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal',<br />
'3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_SV.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_SV.ms.Bscan','3c286_SV.ms.G2ph','3c286_SV.ms.flux',<br />
'3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SVpol.cal.ms') <br />
split(vis='3c286_SV.ms',<br />
outputvis='3c286_SVpol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_SVpol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175143C286 Band6Pol Calibration for CASA 4.32015-07-13T16:16:52Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UnCalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_SV_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_SV_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms')<br />
split(vis='3c286_SV_concat.ms', outputvis='3c286_SV.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_SV.ms', listfile='3c286_SV.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_SV.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_SV.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_SV.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G0ph')<br />
gaincal(vis='3c286_SV.ms',caltable='3c286_SV.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.Bscan')<br />
bandpass(vis='3c286_SV.ms',caltable='3c286_SV.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_SV.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_SV.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_SV.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_SV.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_SV.ms.G2ph')<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_SV.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G2amp')<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_SV.ms.Bscan', '3c286_SV.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_SV.ms', <br />
caltable='3c286_SV.ms.G2amp',<br />
fluxtable = '3c286_SV.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2ph','3c286_SV.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight we be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G1')<br />
gaincal(vis = '3c286_SV.ms',<br />
caltable = '3c286_SV.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_SV.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_SV.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_SV.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_SV.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_SV.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1', '3c286_SV.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr. '''TBD: ROSITA: redo plotms for this fig due to calwt=T in applycal''']]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.XY0amb') <br />
gaincal(vis='3c286_SV.ms',caltable='3c286_SV.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1','3c286_SV.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_SV.ms.XY0amb',qu=qu[0],xyout='3c286_SV.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0.]]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_SV.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms',<br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1','3c286_SV.ms.Kcrs','3c286_SV.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G2.polcal') <br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_SV.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_SV.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_SV.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.Df0*') <br />
polcal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs', '3c286_SV.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_SV.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_SV.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_SV.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_SV.ms.Df0',dout='3c286_SV.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs', '3c286_SV.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_SV.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_SV.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal',<br />
'3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_SV.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_SV.ms.Bscan','3c286_SV.ms.G2ph','3c286_SV.ms.flux',<br />
'3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SVpol.cal.ms') <br />
split(vis='3c286_SV.ms',<br />
outputvis='3c286_SVpol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_SVpol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladinohttps://casaguides.nrao.edu/index.php?title=File:AfterXY0_DA48DV23.png&diff=17513File:AfterXY0 DA48DV23.png2015-07-13T16:14:32Z<p>Paladino: Paladino uploaded a new version of &quot;File:AfterXY0 DA48DV23.png&quot;</p>
<hr />
<div></div>Paladinohttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.3&diff=175123C286 Band6Pol Calibration for CASA 4.32015-07-13T16:00:38Z<p>Paladino: /* XY-phase and QU */</p>
<hr />
<div><div style="background-color:#E0FFFF;border:4px solid #FF9966;"><br />
<div style="font-size:250%; color:red; text-align:center;"><br />
This page is currently under construction.<br />
</div><br />
<div style="font-size:200%; color:black; text-align:center"><br />
DO NOT USE IT.<br />
</div><br />
<div style="font-size:150%; color:black; text-align:center"><br />
To navigate the CASAguides pages, visit [http://casaguides.nrao.edu/<br />
casaguides.nrao.edu<br />
]<br />
</div><br />
</div><br />
<br />
<br />
<br />
<br />
'''[[Category:ALMA]][[Category:Calibration]][[Category:Polarization]]<br />
<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[3C286_Polarization]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''.<br />
<br />
'''This guide is designed for CASA 4.3. <br />
<br />
If you haven't already downloaded the raw data, you may do that now by clicking on the region closest to your location and downloading the file named '3C286_Band6_UnCalibratedData.tgz' from:<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/3C286Band6 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/3C286Band6 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/3C286Band6 East Asia]<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf 3C286_Band6_UncalibratedData.tgz<br />
<br />
cd 3C286_Band6_UncalibratedData<br />
<br />
<br />
# Start CASA<br />
casa<br />
</source><br />
<br />
== Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.3. Please confirm your version before proceeding.<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.3.0'):<br />
print "YOUR VERSION OF CASA IS TOO OLD FOR THIS GUIDE."<br />
print "PLEASE UPDATE IT BEFORE PROCEEDING."<br />
else:<br />
print "Your version of CASA is appropriate for this guide."<br />
</source><br />
<br />
We need to import some scripts we will use during the calibration<br />
<br />
<source lang="python"><br />
# In CASA<br />
path=os.getenv("CASAPATH").split(' ')[0]<br />
execfile(path+'/lib/python2.7/recipes/almahelpers.py')<br />
execfile(path+'/lib/python2.7/recipes/almapolhelpers.py')<br />
</source><br />
<br />
<br />
<br />
==Initial Inspection, ''A priori '' calibration==<br />
We will eventually concatenate the three datasets into one dataset. However, we will keep them separate for now, as some of the steps to follow require individual datasets (specifically, the application of the Tsys and WVR tables). We therefore start by defining an array "basename" that includes the names of the three files in chronological order. This will simplify the following steps by allowing us to loop through the files using a simple for-loop in python. Remember that if you log out of CASA, you will have to re-issue this command. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Define a python list holding the names of all of our data sets<br />
basename=["uid___A002_X85c183_X10a","uid___A002_X85c183_X51a", "uid___A002_X85c183_X822"]<br />
</source><br />
<br />
The raw data have been provided to you in the ASDM format. It is the native format of the data produced by the observatory. <br />
<br />
Before we can proceed to the calibration, we will need to convert those data to the CASA MS format. This is done simply with the task importasdm.<br />
<br />
<source lang="python"><br />
#In CASA<br />
for name in basename:<br />
importasdm(asdm = name, asis='*')<br />
</source><br />
<br />
<br />
The usual first step is then to get some basic information about the data. We do this using the task {{listobs}}, which will output a detailed summary of each dataset supplied. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Loop over each element in the list and create summary file using listobs<br />
<br />
for name in basename:<br />
os.system('rm '+name+'.listobs.txt')<br />
listobs(vis=name+'.ms', listfile=name+'.listobs.txt', verbose=True)<br />
<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to execute.<br />
The output will be sent to the CASA [http://casa.nrao.edu/docs/userman/UserMansu42.html#UserMansu42.html logger], or saved in a text file. Here is a snippet from the full '''verbose''' {{listobs}} output for the first file in the list:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 10125065 Total elapsed time = 3858.05 seconds<br />
Observed from 01-Jul-2014/21:18:10.9 to 01-Jul-2014/22:22:29.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
01-Jul-2014/21:18:10.9 - 21:19:08.3 1 0 J1337-1257 150164 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:20:01.5 - 21:21:04.4 2 0 J1337-1257 501611 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_SIDEBAND_RATIO#OFF_SOURCE,CALIBRATE_SIDEBAND_RATIO#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:07.2 - 21:21:22.8 3 0 J1337-1257 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:21:26.8 - 21:25:39.9 4 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:09.0 - 21:26:24.6 5 1 J1256-0547 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:26:26.3 - 21:29:35.7 6 1 J1256-0547 540547 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_BANDPASS#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:29:51.4 - 21:30:07.9 7 2 Ceres 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:30:09.8 - 21:32:47.3 8 2 Ceres 450461 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_AMPLI#ON_SOURCE,CALIBRATE_FLUX#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:33:30.2 - 21:34:27.1 9 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:01.2 - 21:35:32.4 10 3 J1310+3220 90117 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:35:46.2 - 21:36:02.3 11 4 3c286 95511 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:36:03.5 - 21:43:09.2 12 4 3c286 1261328 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:43:28.1 - 21:43:59.2 13 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:44:15.4 - 21:51:21.4 14 4 3c286 1261297 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:51:43.5 - 21:52:14.2 15 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:36.5 - 21:52:53.1 16 4 3c286 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:52:54.9 - 21:56:26.8 17 4 3c286 630633 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
21:56:46.5 - 21:57:17.0 18 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:58:04.8 - 21:59:02.3 19 0 J1337-1257 150133 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
21:59:42.7 - 21:59:59.3 20 0 J1337-1257 95542 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:00:01.2 - 22:04:14.0 21 0 J1337-1257 720750 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:04:58.4 - 22:05:55.5 22 3 J1310+3220 150195 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:06:29.4 - 22:07:00.2 23 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:13.2 - 22:07:29.7 24 4 3c286 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:07:31.6 - 22:14:36.6 25 4 3c286 1261266 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [OBSERVE_TARGET#ON_SOURCE]<br />
22:14:56.3 - 22:15:26.5 26 3 J1310+3220 90086 [0,17,18,19,20,21,22,23,24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_PHASE#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:16:12.3 - 22:17:08.8 27 0 J1337-1257 150102 [0,1,2,3,4,5,6,7,8] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POINTING#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:17:46.8 - 22:18:03.0 28 0 J1337-1257 95573 [0,9,10,11,12,13,14,15,16] [1.15, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48, 0.48] [CALIBRATE_ATMOSPHERE#OFF_SOURCE,CALIBRATE_ATMOSPHERE#ON_SOURCE,CALIBRATE_WVR#OFF_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
22:18:15.6 - 22:22:29.0 29 0 J1337-1257 720750 [0, 17, 18, 19, 20, 21, 22, 23, 24] [1.15, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01, 2.02, 1.01] [CALIBRATE_POLARIZATION#ON_SOURCE,CALIBRATE_WVR#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 3400886<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 636058<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 546034<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 840937<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4701150<br />
Spectral Windows: (25 unique spectral windows and 3 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 WVR#NOMINAL 4 TOPO 184550.000 1500000.000 7500000.0 187550.0000 0 XX<br />
1 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 215242.188 -15625.000 2000000.0 214250.0000 1 XX YY<br />
2 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 214234.375 1796875.000 1796875.0 214234.3750 1 XX YY<br />
3 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 217242.188 -15625.000 2000000.0 216250.0000 2 XX YY<br />
4 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 216234.375 1796875.000 1796875.0 216234.3750 2 XX YY<br />
5 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 229257.813 15625.000 2000000.0 230250.0000 3 XX YY<br />
6 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 230234.375 1796875.000 1796875.0 230234.3750 3 XX YY<br />
7 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 231257.813 15625.000 2000000.0 232250.0000 4 XX YY<br />
8 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 232234.375 1796875.000 1796875.0 232234.3750 4 XX YY<br />
9 ALMA_RB_06#BB_1#SW-01#FULL_RES 128 TOPO 224992.188 -15625.000 2000000.0 224000.0000 1 XX YY<br />
10 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223976.562 1781250.000 1781250.0 223976.5625 1 XX YY<br />
11 ALMA_RB_06#BB_2#SW-01#FULL_RES 128 TOPO 226992.188 -15625.000 2000000.0 226000.0000 2 XX YY<br />
12 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225976.562 1781250.000 1781250.0 225976.5625 2 XX YY<br />
13 ALMA_RB_06#BB_3#SW-01#FULL_RES 128 TOPO 239007.813 15625.000 2000000.0 240000.0000 3 XX YY<br />
14 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239976.563 1781250.000 1781250.0 239976.5625 3 XX YY<br />
15 ALMA_RB_06#BB_4#SW-01#FULL_RES 128 TOPO 241007.813 15625.000 2000000.0 242000.0000 4 XX YY<br />
16 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241976.563 1781250.000 1781250.0 241976.5625 4 XX YY<br />
17 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 224000.0000 1 XX XY YX YY<br />
18 ALMA_RB_06#BB_1#SW-01#CH_AVG 1 TOPO 223968.750 1781250.000 1781250.0 223968.7500 1 XX XY YX YY<br />
19 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 226000.0000 2 XX XY YX YY<br />
20 ALMA_RB_06#BB_2#SW-01#CH_AVG 1 TOPO 225968.750 1781250.000 1781250.0 225968.7500 2 XX XY YX YY<br />
21 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 240000.0000 3 XX XY YX YY<br />
22 ALMA_RB_06#BB_3#SW-01#CH_AVG 1 TOPO 239968.750 1781250.000 1781250.0 239968.7500 3 XX XY YX YY<br />
23 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 242000.0000 4 XX XY YX YY<br />
24 ALMA_RB_06#BB_4#SW-01#CH_AVG 1 TOPO 241968.750 1781250.000 1781250.0 241968.7500 4 XX XY YX YY<br />
[...]<br />
Antennas: 31:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 DA41 A079 12.0 m -067.45.13.6 -22.53.35.0 116.8369 -920.2897 22.6287 2225122.700426 -5439951.133460 -2481886.481390<br />
1 DA42 A081 12.0 m -067.45.23.9 -22.53.32.5 -174.5620 -842.8378 21.0900 2224863.872997 -5440088.015712 -2481814.531125<br />
2 DA43 A091 12.0 m -067.45.28.7 -22.53.24.2 -312.9125 -584.7726 23.7306 2224774.741865 -5440235.548469 -2481577.816103<br />
3 DA44 A068 12.0 m -067.45.20.6 -22.53.25.7 -82.4244 -631.7829 23.5830 2224981.097391 -5440131.252519 -2481621.067210<br />
4 DA45 A070 12.0 m -067.45.11.9 -22.53.29.3 166.1822 -743.4936 19.8824 2225193.449573 -5439993.765650 -2481722.541223<br />
5 DA46 A058 12.0 m -067.45.17.3 -22.53.32.0 12.7400 -827.0339 21.9689 2225039.860423 -5440023.554679 -2481800.313874<br />
6 DA47 A074 12.0 m -067.45.12.1 -22.53.32.0 161.8144 -828.6212 19.2711 2225176.657096 -5439964.248716 -2481800.726738<br />
7 DA48 A046 12.0 m -067.45.17.0 -22.53.29.3 21.4254 -742.7993 21.6766 2225060.201673 -5440050.345525 -2481722.599573<br />
8 DA49 A029 12.0 m -067.45.18.2 -22.53.25.8 -12.9141 -636.4555 22.1366 2225044.239474 -5440102.024044 -2481624.809292<br />
9 DA51 A082 12.0 m -067.45.08.3 -22.53.29.2 269.0424 -740.9548 16.2831 2225287.766879 -5439952.669219 -2481718.802316<br />
[...]<br />
</pre><br />
<br />
This output shows that five fields were observed: J1337-1257, J1256-0547=3C279, Ceres, J1310+3220, and 3c286. <br />
The final column of the listobs output gives the scan intent. This information is used later to flag the pointing scans and the hot and ambient load calibration scans, using scan intent as a selection option. These intents are also used for pipeline processing.<br />
Field 0 (J1337-1257) will serve as the polarization calibrator; field 1 (3c279) as bandpass calibrator; field 2 (Ceres) will serve as the flux calibrator; field 3 (J1310+3220) as phase calibrator; and 3c286 (field 4) is, of course, the science target. <br />
<br />
Spectral windows are marked with ID numbers from 0 to 24. <br />
If you look at one of the listobs.txt files, you may notice that there are additional SpwIDs listed in the "Sources" section that are not listed in the "Spectral Windows" section<br />
(this is not shown in the snippet above).<br />
These spws (15-62) are related to WVR measurements for each antenna, so you will not need them for the calibration either. <br />
<br />
Spectral window 0 contains the WVR data; spws 1 to 16 also contain calibration data.<br />
The Tsys information is stored in spws 9, 11, 13, 15. <br />
In the listobs output shown above, you notice that field 3 (J1310+3220) has no Tsys measurements, since it is missing spws 9 to 16 in the spwIds. <br />
To increase observation efficiency, Tsys measurements are usually done either on the phase calibrator or the target. In the application of Tsys tables, we will apply to sources missing direct Tsys measurements the closest measurements available (see below). <br />
<br />
The full polarization data are in spectral windows 17,19,21,23, which have 64 channels each. The channel width is 31.250 MHz and the total bandwidth is 2 GHz.<br />
There are two spws (17 and 19) in the lower sideband (LSB), centered at 224.984 and 226.984 GHz, respectively;<br />
and two spectral windows (spw 21 and 23) in the upper sideband (USB), centered at 239.015 and 241.015, respectively. <br />
Spectral windows 18,20,22,24 contain channel averages of the data in spectral windows 17,19,21,23, respectively. These are not useful for the offline data reduction. <br />
<br />
Thirty-eight antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-37. To see what the antenna configuration looked like at the time of this observation, we use the task {{plotants}}. <br />
<br />
<figure id="uid___A002_X85c183_X10a_plotants_casa4.3.png"><br />
[[File:uid___A002_X85c183_X10a_plotants_casa4.3.png|200px|thumb|right|<xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png" nolink/>. Plotants output for the dataset uid___A002_X84049a_X1e7 ]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis=basename[0]+'.ms', figfile=basename[0]+'_plotants.png')<br />
</source> <br />
<br />
This will plot the antenna configuration on your screen (see <xr id="uid___A002_X85c183_X10a_plotants_casa4.3.png"/>) as well as save it under the specified filename for future reference. We need to choose a reference antenna that is close to the center of the array (and is also stable and present for the entire observation). We will use antenna DV23 as reference antenna, and we define a variable to be used in the following tasks: <br />
<source lang="python"><br />
# In CASA<br />
refant='DV23'<br />
</source><br />
<br />
The other two datasets ("uid___A002_X85c183_X51a", "uid___A002_X85c183_X822") have been observed after "uid___A002_X85c183_X10a".<br />
From their listobs output we can see that, in both datasets, Ceres was not observed, and the field J1310+3220 does not have Tsys measurements.<br />
<br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. ALMA data contain both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. <br />
<br />
Now we will loop over the datasets, running these flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True, flagbackup=F)<br />
<br />
</source><br />
<br />
Some scans in the data were used by the online system for pointing and sideband ratio calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent'. Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='manual', <br />
intent='*POINTING*,*SIDEBAND_RATIO*,*ATMOSPHERE*', flagbackup=F)<br />
</source><br />
<br />
We also flag "shadowed" data where one antenna blocks the line of sight of another.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms',mode='shadow',flagbackup=F)<br />
</source><br />
<br />
We will then store the current flagging state for each dataset using the {{flagmanager}}: <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagmanager(vis=name+'.ms', mode='save', versionname='Apriori')<br />
</source><br />
<br />
See the Antennae casaguide (click [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.2 here]) for details on {{flagmanager}}.<br />
<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
<br />
It turns out that two execution blocks (uid://A002/X85c183/X10a and X51a) out of the three taken on 2014-07-01 were affected by an ASDM SYSCal table issue. As a result, the Tsys values were incorrect and an entire scan is unintentionally flagged after applying the Tsys table. <br />
We need to run {{fixsyscaltimes}} task on these datasets before making the Tsys table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixsyscaltimes("uid___A002_X85c183_X10a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X51a.ms")<br />
fixsyscaltimes("uid___A002_X85c183_X822.ms")<br />
</source><br />
<br />
We will loop over the datasets, generating the System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables for each of them.<br />
<br />
The Tsys calibration gives a first-order correction for the atmospheric opacity as a function of time and frequency, and associates weights with each visibility that persist through imaging.<br />
Each ms file contains Tsys measurements; the task {{gencal}} is used to generate calibration tables from these measurements.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
gencal(vis = name+'.ms',<br />
caltable = name+'.ms.tsys',<br />
caltype = 'tsys')<br />
</source><br />
<br />
There are different ways to inspect Tsys calibration tables, in order to identify possibly wrong antenna solutions,<br />
see the TWhydraBand7 casaguide (click [http://casaguides.nrao.edu/index.php?title=TWHydraBand7 here]) for details.<br />
<br />
Here we use {{plotcal}} to interactively plot Tsys vs frequency for all antennas.<br />
<br />
<figure id="Tsys_DA49"><br />
[[File:Tsys_plotcal_antDA49.png|200px|thumb|right|<xr id="Tsys_DA49" nolink/>. Example Tsys vs freq plot for antenna DA49 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<br />
<figure id="Tsys_DV21"><br />
[[File:Tsys_plotcal_antDV21.png|200px|thumb|right|<xr id="Tsys_DV21" nolink/>. Example Tsys vs freq plot for antenna DV21 in the dataset uid___A002_X85c183_X10a]]<br />
</figure><br />
<source lang="python"><br />
<br />
# In CASA<br />
plotcal(caltable=basename[0]+'.ms.tsys', xaxis='freq', yaxis='tsys', spw='',subplot=111, <br />
iteration='antenna')<br />
</source><br />
<br />
By using the next button it is possible to see the plots for each antenna.<br />
You will notice that all antennas have more or less the same behavior as antenna DA49 shown in <xr id="Tsys_DA49"/>.<br />
Antenna DV21 clearly shows higher value of Tsys (see <xr id="Tsys_DV21"/>), we will flag that antenna later in the combined dataset.<br />
<br />
The plots look acceptable, aside from the large amplitudes in the edge channels.<br />
We flag the first four channels of each spw from the calibration tables.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis = name+'.ms.tsys',<br />
spw='9:0~3, 11:0~3, 13:0~3, 15:0~3')<br />
<br />
</source><br />
<br />
<br />
To create the WVR calibration tables <br />
we run the task [http://casa.nrao.edu/stable/docs/TaskRef/wvrgcal-task.html wvrgcal]. This task <br />
examines the data for each ms as a whole and creates a calibration<br />
table containing only phase corrections for each antenna and spw.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
mylogfile = casalog.logfile()<br />
casalog.setlogfile(name+'.ms.wvrgcal')<br />
wvrgcal(vis = name+'.ms',<br />
caltable = name+'.ms.wvr',<br />
toffset = 0,<br />
tie = ['3c286,J1310+3220'],<br />
statsource = 'J1256-0547',<br />
wvrflag=['DA54'])<br />
casalog.setlogfile(mylogfile) <br />
</source><br />
<br />
* casalog.setlogfile(mylogfile): we used this method to send the log output back to the original CASA log file.<br />
<br />
==== WVR Correction and Tsys Calibration ====<br />
<br />
We will now apply the Tsys and the WVR calibration tables to the data with the task {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. <br />
<br />
It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected.<br />
<br />
In addition to looping over data sets, we can define the list of unique source names and loop over these. We set '''field''' and '''gainfield''' to ensure that the appropriate Tsys and WVR calibrations applied to each field. For J1337-1257, J1256-0547, and 3c286, this means using calibration obtained specifically on each of these fields; for J1310+3220, the Tsys from 3c286 is used. We will only correct '''spw''' 17,19,21,23, our science windows, because we will drop the other data in a moment.<br />
<br />
We also need to tell applycal to use the Tsys information in spectral windows 9,11,13,15 for spectral window 17,19,21,23, respectively.<br />
We do so by specifying a list of spws. Normally we would use the almahelper function tsysspwmap (see [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.3#Tsys here] for details); however, in this case it gives a wrong result so we just define this list by hand:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsysmap = [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,11,11,13,13,15,15]<br />
</source><br />
<br />
Here we cycle over all datasets and fields (except Ceres):<br />
<br />
<source lang="python"><br />
# In CASA<br />
field_names = ['J1337-1257','J1256-0547','3c286']<br />
for name in basename:<br />
# General calibrators that have their own Tsys<br />
for field_name in field_names:<br />
applycal(vis = name+'.ms',<br />
field = field_name,<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = [field_name,field_name],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
<br />
# J1310+3220 uses 3c286's Tsys<br />
applycal(vis = name+'.ms',<br />
field = 'J1310+3220',<br />
spw = '17,19,21,23',<br />
gaintable = [name+'.ms.tsys',name+'.ms.wvr'],<br />
gainfield = ['3c286','J1310+3220'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
As anticipated in the listobs description, Ceres has been observed only in the first dataset. We correct it separately here:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = basename[0]+'.ms',<br />
field = 'Ceres',<br />
spw = '17,19,21,23',<br />
gaintable = [basename[0]+'.ms.tsys',basename[0]+'.ms.wvr'],<br />
gainfield = ['Ceres','Ceres'],<br />
interp = 'linear',<br />
spwmap = [tsysmap,[]],<br />
calwt = T,<br />
flagbackup = F)<br />
</source><br />
<br />
You can use {{plotms}} to plot channel-averaged amplitudes as a function of time, comparing the DATA and CORRECTED columns after applying the Tsys correction. This way you can check that calibration has done what was expected, which is put the data onto the Kelvin temperature scale.<br />
<br />
Now we can concatenate the three individual data sets of each day into one big measurement set. We define an array "comvis" that contains the names of the measurement sets we wish to concatenate, and then we run the task {{concat}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
comvis=[]<br />
for name in basename:<br />
comvis.append(name+'.ms')<br />
<br />
os.system('rm -rf 3c286_SV_concat.ms*')<br />
concat(vis=comvis, concatvis='3c286_SV_concat.ms')<br />
<br />
</source><br />
<br />
Now split out the CORRECTED data column, retaining spectral windows 17,19,21,23. This will get rid of the extraneous spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms')<br />
split(vis='3c286_SV_concat.ms', outputvis='3c286_SV.ms',<br />
datacolumn='corrected', spw='17,19,21,23')<br />
<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets.<br />
While running this task you will see a list of warnings. They are not relevant, you can ignore them.<br />
<br />
==Additional Data Inspection==<br />
<br />
We run a {{listobs}} on the resulting concatenated data sets to check that they contain the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs(vis='3c286_SV.ms', listfile='3c286_SV.ms.listobs') <br />
<br />
</source><br />
<br />
Below is an extract from the dataset listobs: <br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91097e+09]knakanishi uid://A002/X845868/X11<br />
ALMA [ 4.91097e+09, 4.91098e+09]knakanishi uid://A002/X845868/X11<br />
Data records: 7499520 Total elapsed time = 11154.7 seconds<br />
Observed from 01-Jul-2014/21:21:27.3 to 02-Jul-2014/00:27:21.9 (UTC)<br />
[...]<br />
Fields: 5<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1337-1257 13:37:39.782784 -12.57.24.69312 J2000 0 1666560<br />
1 none J1256-0547 12:56:11.166560 -05.47.21.52458 J2000 1 535680<br />
2 none Ceres 13:29:06.769601 -01.11.10.65438 J2000 2 148800<br />
3 none J1310+3220 13:10:28.663200 +32.20.43.80000 J2000 3 773760<br />
4 none 3c286 13:31:08.288100 +30.30.32.96000 J2000 4 4374720<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 ALMA_RB_06#BB_1#SW-01#FULL_RES 64 TOPO 224984.375 -31250.000 2000000.0 1 XX XY YX YY<br />
1 ALMA_RB_06#BB_2#SW-01#FULL_RES 64 TOPO 226984.375 -31250.000 2000000.0 2 XX XY YX YY<br />
2 ALMA_RB_06#BB_3#SW-01#FULL_RES 64 TOPO 239015.625 31250.000 2000000.0 3 XX XY YX YY<br />
3 ALMA_RB_06#BB_4#SW-01#FULL_RES 64 TOPO 241015.625 31250.000 2000000.0 4 XX XY YX YY<br />
[...]<br />
</pre><br />
<br />
The scans have been combined and their original ID numbers have been offset to make scan numbers unique. The information about the different datasets is kept in the ObservationID number, this means that in the next steps when combining all the scans we will need to add also combine='obs' (see below).<br />
<br />
Only the four scientific spws with full polarization are included.<br />
<br />
Now that the data are concatenated into one dataset, we will do some additional inspection with {{plotms}}. First we will plot amplitude versus channel, averaging over time and baselines in order to speed up the plotting process.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='channel', yaxis='amp', field='1', correlation='XX', <br />
averagedata=T, avgbaseline=T, avgtime='1e8', avgscan=T, coloraxis='spw')<br />
</source><br />
<br />
From these plots we see that the edge channels have high or low amplitudes in the different spws. We will use {{Flagdata}} to remove the edge channels from both sides of the bandpass:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', spw='*:0~5,*:58~63')<br />
</source><br />
<br />
Next, we flag the antenna with high Tsys, as identified during the Tsys calibration inspection:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', antenna='DV21')<br />
</source><br />
<br />
<figure id="allfields"><br />
[[File:all_field_casa4.3.png|200px|thumb|right||<xr id="allfields" nolink/>. Amplitude vs time for the dataset 3c286_SV.ms, spw 0 all channels averaged ]]<br />
</figure><br />
<br />
To identify antennas or time ranges that differ from the average values, we carefully inspect the data with {{plotms}}, plotting different axes and colorizing by different parameters. Don't forget to average the data if possible to speed the plotting process. <br />
<br />
We will look first at amplitude versus time, averaging over all channels and colorizing by field (see <xr id="allfields"/>). <br />
<br />
<figure id="ceres"><br />
[[File:ceres_uv_casa4.3.png|200px|thumb|right|<xr id="ceres" nolink/>. Amplitude vs uv-distance for Ceres]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='time', yaxis='amp', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', coloraxis='field', spw='0')<br />
<br />
</source><br />
<br />
<figure id="field0"><br />
[[File:field0_casa3.4.png|200px|thumb|right|<xr id="field0" nolink/>. Amp vs time for field 0.]]<br />
</figure><br />
<br />
<xr id="field0"/> shows some time ranges which need to be flagged. It is possible to zoom in, or identify the time ranges by using the Tool Hover in plotms.<br />
<br />
Here is how to plot the amplitude of the flux calibrator as a function of the uv distance.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='uvdist', yaxis='amp', field='Ceres', correlation='XX,YY',<br />
averagedata=T, avgchannel='128', avgtime='1e8', coloraxis='antenna1')<br />
</source><br />
<br />
Continue to inspect the data with {{plotms}}, plotting different axes and colorizing by the different parameters. Don't forget to average the data if possible to speed the plotting process. You will find the following flags are needed:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA49') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA45', field='0,3', spw='1') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna = 'DA45', scan='48', field='0', spw='2')<br />
flagdata(vis='3c286_SV.ms', antenna = 'DV14') #low gain<br />
flagdata(vis='3c286_SV.ms', antenna='DV04', scan='93',field='0') <br />
flagdata(vis='3c286_SV.ms', timerange='2014/07/02/00:25:00~2014/07/02/00:25:10')<br />
<br />
</source><br />
<br />
Now that we have completed the above inspection and flagging, we can start the data calibration.<br />
<br />
== Calibrating the data ==<br />
We can now begin calibrating the data. The general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. <br />
For <em>much</em> more discussion on the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see the [http://casa.nrao.edu/docs/userman/casa_cookbook005.html calibration chapter] in the CASA Reference Manual. The CASA software solves the Hamaker-Bregman-Sault Measurement Equation (ME), described in detail [http://casa.nrao.edu/docs/UserMan/casa_cookbook016.html here].<br />
<br />
For full polarization calibration there are additional calibration steps, as described in previous casaguides.<br />
<br />
We start with the determination of the bandpass and gains. The method is similar to what shown in other casaguides (e.g. the [http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3 N3256_Band3 casaguide].<br />
<br />
We do not actually measure absolute phase values; instead, we fix the phase of a reference antenna to zero for both polarizations, which yields relative phases for all antennas. Difference among antennas in each polarization are preserved, so there is no effect on parallel-hand calibration.<br />
<br />
After that we will proceed with the polarization calibration which will correct for the cross-hand influenced terms:<br />
<math>D^{r}</math>, <math>X^{r}</math> and <math>P</math> (see below for details). '''IMPROVE THIS'''<br />
<br />
<br />
=== Bandpass ===<br />
<br />
We are now ready to calibrate the bandpass.<br />
<br />
See the<br />
[http://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.3#Bandpass_Calibration N3256_Band3 casaguide] for a more detailed description about the bandpass calibration, including inspection of data before applying it.<br />
<br />
We first run {{gaincal}} on the bandpass calibrator to determine phase-only gain solutions. We will use solint='int' for the solution interval, which means that one gain solution will be determined for every integration time. This short integration time is possible because the bandpass calibrator is a very bright point source, so we have very high signal-to-noise (SNR) and a perfect model. This will correct for any phase variations in the bandpass calibrator as a function of time, a step which will prevent decorrelation of the vector-averaged bandpass solutions. We will then apply these solutions on-the-fly when we run {{bandpass}}. <br />
<br />
Note that we use the average of channels 20 to 45 to increase our signal-to-noise in the determination of the antenna-based phase solutions. Averaging over a subset of channels near the center of the bandpass is acceptable when the phase variation as a function of channel is small, which it is here. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G0ph')<br />
gaincal(vis='3c286_SV.ms',caltable='3c286_SV.ms.G0ph', <br />
field='1', #3c279<br />
gaintype='G',solint='int',calmode='p',<br />
spw='*:20~45',<br />
refant=refant,smodel=[1,0,0,0])<br />
</source><br />
<br />
* <tt>caltable='*.G0ph'</tt> : the gain solutions will be stored in an external table.<br />
* <tt>field=1</tt> : we select the bandpass calibrator 3c279<br />
* <tt>gaintype='G'</tt>: we solve for gains for each polarization<br />
* <tt>solint='int'</tt>: we determine one solution for each integration<br />
* <tt>calmode='p'</tt>: we solve for phase only<br />
* <tt>smodel=[1,0,0,0]</tt>: we assume an unpolarized model. The values correspond to [I,Q,U,V].<br />
<br />
Now that we have a first measurement of the phase variations as a function of time, we can determine the bandpass solutions with {{bandpass}}. We will apply the phase calibration table on-the-fly with the parameter "gaintable". <br />
Do not worry about the message "Insufficient unflagged antennas", which relates to the flagged edge channels.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.Bscan')<br />
bandpass(vis='3c286_SV.ms',caltable='3c286_SV.ms.Bscan',<br />
field='1', #3c279<br />
solint='inf',combine='scan, obs',<br />
refant=refant,solnorm=T, <br />
gaintable=['3c286_SV.ms.G0ph'],interp=['nearest'])<br />
<br />
</source><br />
<br />
* The default type of bandpass solution is bandtype='B' , which does a channel by channel solution for each specified spw<br />
*caltable = '*.Bscan': Output bandpass calibration table<br />
*gaintable = '.G0ph': gain calibration table to be applied on the fly<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum signal-to-noise (SNR) for solutions<br />
*solint='inf',combine='scan, obs': this setting, sets the solution interval to the entire observation. The G0ph table corrects the phase variations as a function of time so that the per-channel bandpass solution is coherent and high SNR. To the default combine='scan', we need to add also 'obs' since the dataset we are working on is a combination of different observations.<br />
*solnorm=T: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
*interp=['nearest']: apply the nearest solution from the calibration table. <br />
<br />
<figure id="Bscan"><br />
[[File:bscan_casa3.4.png|200px|thumb|right|<xr id="Bscan" nolink/>. Bandpass amp solutions]]<br />
</figure><br />
<br />
We now plot the bandpass solutions:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = '3c286_SV.ms.Bscan', xaxis='freq', yaxis='amp', <br />
solutionTimeThresholdSeconds= 32.0, <br />
overlay='antenna', figfile='3c286_SV.ms.Bscan.png')<br />
</source><br />
<br />
<xr id="Bscan"/> shows a colored curve for each antenna, in each of the four spws. In spw 1 and 3 the presence of atmospheric lines is clearly visible, <br />
The solutions seem reasonable, so we will apply them on-the-fly during gain calibration in the next section.<br />
<br />
<br />
===Gain Calibration===<br />
<br />
We first set the flux density for the flux calibrators using {{setjy}}. Ceres has been used as flux calibrator.<br />
The standard catalog Butler-JPL-Horizons 2012 model fits Ceres's resolved visibilities to an emission model appropriate for the distance to Ceres on the observation date. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis = '3c286_SV.ms',<br />
field = '2', # Ceres<br />
spw = '0,1,2,3',<br />
standard = 'Butler-JPL-Horizons 2012')<br />
<br />
<br />
</source><br />
<br />
Now we determine a gain calibration for the bandpass, flux, and phase calibrators. We will calibrate the polarization calibrator separately.<br />
We solve first for phase only, applying the bandpass calibration on-the-fly.<br />
<br />
<source lang="python"><br />
# In CASA<br />
#Gaincal for 3C279 and Ceres and J1310+3220<br />
os.system('rm -rf 3c286_SV.ms.G2ph')<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2ph', <br />
gaintype= 'G',<br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
calmode = 'p', <br />
gaintable=['3c286_SV.ms.Bscan'],<br />
interp=['nearest'])<br />
<br />
</source><br />
*os.system('rm -rf *.G2ph'): removes the table if already existing. <br />
*caltable = '*.G2ph': the output gain calibration table<br />
*gaintype = 'G': is the default type of gain solution , which determine gains for each polarization and spectral window<br />
*field='1,2,3'*: to specify the bandpass, flux, and phase calibrators.<br />
*calmode = 'p': to solve for phase only.<br />
*solint='int': this setting will solve for one solution per integration<br />
*gaintable = ['*.Bscan']: we apply the bandpass calibration on-the-fly<br />
*interp=['nearest']: as before we use the nearest solution in the table<br />
<br />
We solve for the amplitude, applying on-the-fly the bandpass and the phase corrections just computed.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G2amp')<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2amp', <br />
field='1,2,3',<br />
solint='int',refant=refant,<br />
gaintype = 'T',<br />
calmode = 'a', #solve amplitude using G2ph<br />
gaintable=['3c286_SV.ms.Bscan', '3c286_SV.ms.G2ph'],<br />
interp=['nearest', 'nearest'])<br />
<br />
</source><br />
<br />
*gaintype='T': this time we obtain one solution for both polarizations. <br />
<br />
We now bootstrap the flux density of the secondary calibrators from that of Ceres using the task {{fluxscale}}. <br />
The new flux tables *.flux, containing the correctly-scaled gains, will replace the previous *.G2amp tables when we apply the calibration to the data later.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale(vis='3c286_SV.ms', <br />
caltable='3c286_SV.ms.G2amp',<br />
fluxtable = '3c286_SV.ms.flux',<br />
reference='2', #Ceres<br />
transfer='1,3') #'J1256-0547', 'J1310+3220'<br />
<br />
</source><br />
<br />
*caltable='*.G2amp': this is the input table we want to scale<br />
*fluxscale='*.flux': output table, containing scaled gains.<br />
*reference='Ceres': here we specify the source with the known flux density (Ceres or Titan)<br />
*transfer='1,3': these are the sources whose amplitude gains are to be rescaled: 'J1256-0547', and 'J1310+3220'<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Found reference field(s): Ceres<br />
Found transfer field(s): J1256-0547 J1310+3220<br />
Flux density for J1256-0547 in SpW=0 (freq=2.24984e+11 Hz) is: 9.34567 +/- 0.0232932 (SNR = 401.218, N = 28)<br />
Flux density for J1256-0547 in SpW=1 (freq=2.26984e+11 Hz) is: 9.24788 +/- 0.0233105 (SNR = 396.726, N = 28)<br />
Flux density for J1256-0547 in SpW=2 (freq=2.39016e+11 Hz) is: 8.88454 +/- 0.0252485 (SNR = 351.884, N = 28)<br />
Flux density for J1256-0547 in SpW=3 (freq=2.41016e+11 Hz) is: 8.8074 +/- 0.0255162 (SNR = 345.169, N = 28)<br />
Flux density for J1310+3220 in SpW=0 (freq=2.24984e+11 Hz) is: 1.0092 +/- 0.00788338 (SNR = 128.016, N = 27)<br />
Flux density for J1310+3220 in SpW=1 (freq=2.26984e+11 Hz) is: 0.996775 +/- 0.00825086 (SNR = 120.809, N = 26)<br />
Flux density for J1310+3220 in SpW=2 (freq=2.39016e+11 Hz) is: 0.954589 +/- 0.00847336 (SNR = 112.658, N = 27)<br />
Flux density for J1310+3220 in SpW=3 (freq=2.41016e+11 Hz) is: 0.953251 +/- 0.00871098 (SNR = 109.431, N = 27)<br />
Fitted spectrum for J1256-0547 with fitorder=1: Flux density = 9.06839 +/- 0.0086788 <br />
(freq=232.892 GHz) spidx=-0.831341 +/- 0.0314601<br />
Fitted spectrum for J1310+3220 with fitorder=1: Flux density = 0.978163 +/- 0.00182649 <br />
(freq=232.892 GHz) spidx=-0.837124 +/- 0.0611923<br />
</pre><br />
<br />
{{fluxscale}} prints to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' argument. You should examine the output to ensure that the fluxes are reasonable. <br />
The ALMA Calibrator Source Catalogue [http://almascience.eso.org/sc/] can be used to check whether the derived flux densities are reasonable. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.<br />
<br />
We apply the solutions so far, for inspection purposes only. We will apply all the calibrations at the end:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms', <br />
field='1,2,3',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2ph','3c286_SV.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=F)<br />
<br />
</source><br />
<br />
*calwt=T: the weight we be calibrated.<br />
*interp=['nearest','linear','linear']: this list indicates the interpolation method to be used when applying the corresponding table. For bandpass table the nearest solution to the source is taken, while for the gain tables a linear interpolation in time is used.<br />
<br />
<figure id="3c279_BG2"><br />
[[Image:3c279_afterBandG2parang_lastcheck.png|200px|thumb|left|<xr id="3c279_BG2" nolink/>. 3C279 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<figure id="J1310_BG2"><br />
[[Image:J1310_afterBandG2parang_lastcheck.png|200px|thumb|center|<xr id="J1310_BG2" nolink/>. J1310+3220 amp vs time after bandpass and gain calibration. Spw 0: all baselines have been averaged.]]<br />
</figure><br />
<br />
<br />
<xr id="3c279_BG2"/> and <xr id="J1310_BG2"/> show the XX and YY data for the bandpass and phase calibrators after the parallel-hand calibration. <br />
The effect of source polarization is clearly evident.<br />
<br />
===Polarization Calibration===<br />
<br />
A list of useful references about mathematical and theoretical details of polarization calibration is given in the [[3C286_Band6Pol_Calibration_for_CASA_4.3#References | last section of this guide]]. Here we introduce some basic concepts needed to guide you through the calibration steps.<br />
<br />
Correlations between circularly polarized feeds are sensitive to total intensity and the source circular polarization, while <br />
correlations between linearly polarized feeds are sensitive predominantly to total intensity plus a contribution from the linear polarization. Since the large majority of extragalactic radio sources are quite weakly circularly polarized, the separation of the calibration of the two parallel hand gains from each other and from the instrumental polarization is much easier in interferometers using circularly polarized feeds. For interferometers with linearly polarized feeds the situation is more complex: a point source at the phase center contributes a function of Stokes ''Q'', ''U'' and the parallactic angle ''ψ'' to the real part of all correlations '''(this should be made more clear)'''. <br />
<br />
The polarization response can be described assuming that each feed is perfectly coupled to the polarization state to which it is sensitive, with the addition of a complex factor times the orthogonal polarization; this is called the "leakage" or "D-term" model.<br />
The instrumental contribution to the cross-polarized interferometer response (i.e., the effect due to leakage) is unaffected by parallactic angle, whereas the contribution from the source does depend on the parallactic angle for alt-az mount antennas.<br />
<br />
In the limit of nearly perfect feeds (any higher order terms involving instrumental polarization can be ignored) and zero circular polarization, the linearized approximation for crossed linearly polarized feeds on one baseline is: <br />
<br />
<center><br />
<equation id="Visibilities"> <br />
<br />
<math>\ V_{XX} = (I + Q_{\psi}) + U_{\psi}(d_{Xj}^{*} + d_{Xi})</math><br />
<br />
<math>\ V_{XY} = U_{\psi} + I(d_{Yj}^{*} + d_{Xi}) + Q_{\psi}</math><br />
<math>\ (d_{Yj}^{*} - d_{Xi})</math><br />
<br />
<math>\ V_{YX} = U_{\psi} + I(d_{Yi} + d_{Xj}^{*}) + Q_{\psi}</math><br />
<math>\ (d_{Yi} - d_{Xj}^{*}) </math><br />
<br />
<math>\ V_{YY} = (I - Q_{\psi}) + U_{\psi}(d_{Yi} + d_{Yj}^{*})</math><br />
<br />
<br />
</equation><br />
<xr id="Visibilities" nolink/>. Visibilities for one baseline. Linearized approximation for linear feed.<br />
</center><br />
<br />
<br />
where the functions: <br />
<math> <br />
Q_{\psi}= Q cos2\psi + U sin2\psi <br />
</math> <br />
and <br />
<math> <br />
U_{\psi} = -Q sin2\psi + U cos2\psi <br />
</math> <br />
show the dependence of the source polarization on the parallactic angle.<br />
<br />
In <xr id="Visibilities" /> we can recognize a constant complex offset proportional to I in cross-hands visibilities, and a time-dependent contribution of linear polarization from the source, scaled by the D-terms, in all correlations.<br />
In order to separate the source and instrumental contributions to the correlations, observations with an array using linear feeds need to include frequent measurements of an unresolved calibrator over a wide range of parallactic angle.<br />
<br />
The following steps will allow us to determine of all these factors to properly correct the data. <br />
<br />
<br />
====Gains for the polarization calibrator====<br />
<br />
We start examining the polarization calibrator. Since we are concerned only about its fractional polarization, we do not worry about its absolute total flux density, and just use I=1.0.<br />
The first gains we determine will absorb all these contributions, and we will revise them once the source polarization is correctly estimated.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G1')<br />
gaincal(vis = '3c286_SV.ms',<br />
caltable = '3c286_SV.ms.G1',<br />
field = '0',<br />
solint = 'int',<br />
refant = refant,<br />
smodel=[1,0,0,0],<br />
gaintable = '3c286_SV.ms.Bscan',<br />
interp='nearest')<br />
<br />
</source><br />
<br />
We explicitly show some of the default parameters, but they could also be left out -- when a parameter is not specified, its default value is used.<br />
<br />
<figure id="J1337_BG1"><br />
[[Image:J1337_afterBandG1_parang_casa4.3.png|200px|thumb|right|<xr id="J1337_BG1" nolink/>. J1337-1257 amp vs parang after the application of the bandpass and G1 tables.]]<br />
</figure> <br />
<br />
* caltable = '*.G1': the output table. This table will be revised later on, when the source polarization will be estimated.<br />
* calmode = 'ap': this is the default value. We are solving for both amplitude and phase.<br />
* gaintype='G': this is the default value. We are determining gains for each polarization.<br />
* solint = 'int': one solution per integration.<br />
* smodel=[1,0,0,0]: we are using an unpolarized model with a Stokes I flux equal to 1. <br />
<br />
To inspect the results we generate a partially calibrated dataset, applying this gain table, as well as the bandpass, to the polarization calibrator:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1'],<br />
interp=['nearest','linear'], parang=F)<br />
<br />
<br />
</source><br />
<br />
<br />
<br />
<xr id="J1337_BG1"/> shows the polarization calibrator's amplitude versus time, after the application of the bandpass and the gain table G1, we just computed.<br />
<br />
The source's linear polarization, which rotates with parallactic angle as a function of time, has been absorbed by the gains, since we assumed an unpolarized model for the source.<br />
<br />
The presence of source polarization in the gains can be seen by plotting the amp vs time for this table using poln='/', which forms the complex polarization ratio.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.G1','scan','amp',field='',poln='/',subplot=111, figfile='G1_polnratio.png')<br />
<br />
</source><br />
<br />
<figure id="G1_polnratio"><br />
[[Image:G1_polnratio_scan_casa4.3.png|thumb|<xr id="G1_polnratio" nolink/>. Polarization ratio from the table 3c286_SV.ms.G1 versus scan number]]<br />
</figure><br />
<br />
The antenna-based complex polarization ratio reveals the sinusoidal (in parallactic angle) variation, which clearly shows the presence of polarization in the source.<br />
<br />
In order to extract the source polarization information hidden in the gains, we use one of the ad hoc scripts included in the almapolhelpers.py: qufromgain().<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
qu=qufromgain('3c286_SV.ms.G1')<br />
<br />
</source><br />
<br />
This script estimates the Q and U amplitudes from the gains, for each spectral window. The results are stored in the python dictionary qu, which will be used later on to remove the ambiguity in the XY-phase.<br />
The source polarization reported for all spws should be reasonably consistent.<br />
This estimate is not as good as can be obtained from the cross-hands, since it relies on the gain amplitude polarization ratio being stable which may not be precisely true. However, it will be useful later on in removing an ambiguity that occurs in the cross-hand estimates.<br />
<br />
The output will be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Latitude = -23.0294371117<br />
Found as many as 5 fields.<br />
Found as many as 4 spws.<br />
Fld= 0 Spw= 0 (B=06, PA offset=-135.0deg) Gx/Gy= 0.992405159941 Q= 0.0120289156117 U= 0.0357752509932 P= 0.0377433887511 X= 35.7077595289<br />
Fld= 0 Spw= 1 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00460116288 Q= 0.0121161080168 U= 0.0342483052217 P= 0.0363283151829 X= 35.2588108949<br />
Fld= 0 Spw= 2 (B=06, PA offset=-135.0deg) Gx/Gy= 1.00477773393 Q= 0.0132551079897 U= 0.036581802383 P= 0.0389092039678 X= 35.0412212234<br />
Fld= 0 Spw= 3 (B=06, PA offset=-135.0deg) Gx/Gy= 0.997298258786 Q= 0.0135497332503 U= 0.0372695146153 P= 0.0396561721654 X= 35.0103595898<br />
For field id = 0 there are 4 good spws.<br />
Spw mean: Fld= 0 Q= 0.0127374662171 U= 0.0359687183033 (rms= 0.000673769380338 0.00112529928303 ) P= 0.0381574598475 X= 35.2498053524<br />
</pre><br />
<br />
From this output we see that the Q and U values reported for all spws are consistent at ~0.1% level.<br />
<br />
====Cross-hand delay==== <br />
<br />
When the data have more than one channel per spectral window, it is important to be sure there is no large cross-hand (XY, YX) delay still present in the data. <br />
The gain and bandpass calibration will only correct for parallel-hand (XX, YY) delay residuals, since the two polarizations are referenced independently. <br />
Plots of cross-hand phases as a function of frequency for a strongly polarized source (i.e., a source whose polarization dominates the instrumental polarization) will show the cross-hand delay as a phase slope with frequency (see <xr id="kcross_1bl" />). This slope will be the same magnitude on all baselines, but with different sign in the two cross-hand correlations (XY, YX). <br />
<br />
Note that in this dataset you can produce even higher-SNR plots of the cross-hand delay by using 3C279. However, in this guide we proceed by using the polarization calibrator for all of the polarization calibration steps (cross-hand delay, XY-phase, and leakages).<br />
<br />
<figure id="kcross_1bl"><br />
[[Image:bG2_ph_freq_DA48DV23.png|200px|thumb|right|<xr id="kcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq before the cross-hand delay calibration.]]<br />
</figure><br />
<br />
<br />
We can plot the corrected column of the dataset (we applied so far the bandpass and the G1 tables) to show this effect on one baseline:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms',<br />
ydatacolumn='corrected',<br />
xaxis='freq', yaxis='phase',<br />
field='0', <br />
avgtime='1e9',<br />
correlation='XY,YX',<br />
spw='', antenna='DA48',<br />
iteraxis='baseline',coloraxis='corr',<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
This cross-hand delay can be estimated using the gaintype=’KCROSS’ mode of {{gaincal}}. <br />
<br />
'''CHECK!!! For the cross-hand delay calculation we need to choose a scan where the source's cross-hand contribution is maximum (in absolute value), since this will minimize the mean effect of instrumental polarization. This scan would be the one where the gain ratio is near the mean value in <xr id="G1_polnratio"/>: scan 48.'''<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf 3c286_SV.ms.Kcrs')<br />
# In CASA<br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.Kcrs',<br />
selectdata=T,<br />
scan='48',<br />
gaintype='KCROSS',<br />
solint='inf',refant=refant, <br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1'],<br />
interp=['nearest','linear'])<br />
<br />
<br />
</source><br />
<br />
<figure id="afterkcross_1bl"><br />
[[Image:afterKcr_DA48DV23.png|200px|thumb|right|<xr id="afterkcross_1bl" nolink/>. Baseline DA48&DV23: XY and YX amp vs freq after the cross-hand delay calibration.]]<br />
</figure><br />
<br />
*caltable='*.Kcrs': the output table.<br />
*selectdata=T: this parameter allows further selection data parameters. Selection based on antennas, timerange, uvrange, scan, etc.<br />
*scan='48': we select the scan with strong polarization, and we calculate the gain solution using only this scan.<br />
*gaintype='KCROSS': solves for a global cross-hand delay.<br />
*smodel=[1,0,1,0]: here we are using a polarized model (a non-zero value for U is assumed). '''FIX: This is just to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio between data and model.''' It is not important to specify this polarization Stokes parameters correctly, since here we are only solving for the delay. <br />
*gaintable=['*.Bscan','*.G1']: we apply on-the-fly the bandpass and the first gains tables<br />
<br />
We apply this new cross-hand delay calibration to the dataset, along with the bandpass and gain tables:<br />
<br />
<source lang="python"><br />
applycal(vis='3c286_SV.ms', <br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1', '3c286_SV.ms.Kcrs'],<br />
interp=['nearest','linear', 'nearest'])<br />
<br />
</source><br />
<br />
Running plotms again we can verify the effect of this calibration (<xr id="afterkcross_1bl" />). These plots are a nice example of the effect of Kcrs correction on the cross-hand phases:<br />
by applying the Kcrs table to the data, the phase slopes vs frequency are corrected. The remaining frequency structure in the cross-hand phase is due to the remaining cross-hand bandpass phase, as well as the instrumental polarization.<br />
<br />
====XY-phase and QU====<br />
<br />
We have so far computed the bandpass and gain tables adequate for the parallel hands, and the Kcross table which corrects the cross-hands for a systematic linear slope across each spw. <br />
In computing bandpass and gains we don't measure absolute phase values; instead, we set the phase of the reference antenna to zero in both polarizations, yielding relative phases for all other antennas. <br />
This has no effect on parallel-hand calibration, since the two polarizations are referenced independently, while the cross-hand bandpass phase <br />
of the reference antenna remains undetected. We need to solve for this residual XY-phase offset so that both cross- and parallel-hands can be combined to extract correct Stokes parameters.<br />
<br />
''' NEW: To visualize the effect of this XY-phase offset on the data, we can plot the real and imaginary part of the data corrected for bandpass, gains, and cross-hands delay. <xr id="imagreal_bg1kcr"/> shows the cross-hands visibilities of the polarization calibrator, averaged over all baselines, in one spw. The XY-phase is clearly visible as the slope of cross-hand visibilities in the complex plane.''' <br />
<br />
<figure id="imagreal_bg1kcr"><br />
[[File:imaginary_plane.png|200px|thumb|right|<xr id="imagreal_bg1kcr" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr. '''TBD: ROSITA: redo plotms for this fig due to calwt=T in applycal''']]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms',<br />
ydatacolumn='corrected',<br />
xdatacolumn='corrected',<br />
xaxis='real', yaxis='imag',<br />
field='0',<br />
avgtime='1e9',<br />
avgchannel='128',<br />
avgbaseline=T,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06])<br />
</source><br />
<br />
By using the XYf+QU solve in gaincal, we can estimate both the XY-phase offset and the source polarization from the cross-hands.<br />
The XYf+QU solve averages all baselines together and first solves for a the XY-phase as a function of channel. <br />
It then corrects that slope, and solves for a channel-averaged source polarization. <br />
The application of the cross-hand delay (above) ensures that the frequency average is coherent for the QU part of the XYf+QU solve. The XYf part of that solution will correct for the non-linear parts of the cross-hand phase spectrum, removing any small residual delays that were not corrected by the KCROSS solution.<br />
<br />
Note that we can solve for the XY-phase without an absolute position angle (PA) calibrator like a polarized noise source. '''This is possible because...(needs work!)'''<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.XY0amb') <br />
gaincal(vis='3c286_SV.ms',caltable='3c286_SV.ms.XY0amb', <br />
field='0',<br />
gaintype='XYf+QU',<br />
solint='inf',<br />
combine='scan,obs',<br />
preavg=300, <br />
refant=refant,<br />
smodel=[1,0,1,0],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1','3c286_SV.ms.Kcrs'],<br />
interp=['nearest','linear','nearest'])<br />
</source><br />
<br />
*caltable='*.XY0amb': the output table. In the name we just want to remember that there could still be a 180 deg ambiguity in the solutions obtained in this table.<br />
*gaintype='XYf+QU': estimate both the XY-phase offset and source polarization from the cross-hands<br />
*solint='inf'; combine='scan,obs': we get one solution for the all dataset. The option "obs" takes into account the different Obs ID which are usually present in different scheduling blocks.<br />
*preavg=300: pre-averaging interval (sec). This limits averaging within the solution interval to within scan boundaries, since the parallactic angle changes from scan to scan are important for the solution.<br />
*smodel=[1,0,1,0]: we again use a polarized model '''FIX, AS ABOVE: to enforce the assumption of non-zero source polarization signature in the cross-hands in the ratio of data and model.'''<br />
*gaintable=['*.Bscan','*.G1','*.Kcrs']: we apply on-the-fly the bandpass, the gain and the cross-hand delay tables.<br />
<br />
<figure id="XYcomparison"><br />
[[File:XY0_comparison_casa4.3.png|200px|thumb|right| <xr id="XYcomparison" nolink/>. Comparison between the XY-phase tables before and after resolving the ambiguity]]<br />
</figure><br />
<br />
The output table contains the values of Q, U and the XY-phase. A <br />
degeneracy may still be present<br />
(XY-phase, Q, U) ---> (XY-phase + π, -Q, -U). <br />
This ambiguity can be resolved by using the Q and U values derived from the <br />
gains in G1 table (qufromgain() results obtained above). We use the <br />
script xyamb() utility contained in the almapolhelpers.py.<br />
<br />
<source lang="python"><br />
# In CASA<br />
S=xyamb(xytab='3c286_SV.ms.XY0amb',qu=qu[0],xyout='3c286_SV.ms.XY0')<br />
</source><br />
<br />
This is an extract of the output of the xyamb() utility:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Expected QU = (0.012737479249452035, 0.035968714662568159)<br />
Spw = 0: Found QU = [ 0.01259385 0.04101928]<br />
...KEEPING X-Y phase 84.4169495884 deg<br />
Spw = 1: Found QU = [-0.01261223 -0.04112571]<br />
...CONVERTING X-Y phase from -73.064852046 to 106.935147954 deg<br />
Spw = 2: Found QU = [ 0.01355364 0.0418143 ]<br />
...KEEPING X-Y phase 8.60411636622 deg<br />
Spw = 3: Found QU = [ 0.01344682 0.04199271]<br />
...KEEPING X-Y phase -21.7400889849 deg<br />
Ambiguity resolved (spw mean): Q= 0.0130516346544 U= 0.0414879983291 (rms= 0.000450227601812 0.000421946318322 ) P= 0.0434925185809 X= 36.2685199328<br />
Returning the following Stokes vector: [1.0, 0.013051634654402733, 0.041487998329102993, 0.0]<br />
</pre><br />
<br />
<figure id="afterXY0"><br />
[[File:afterXY0_DA48DV23.png|200px|thumb|right|<xr id="afterXY0" nolink/>. Baseline DA48&DV23: XY and YX phase vs channels after the XY0 calibration.]]<br />
</figure><br />
<br />
<figure id="afterXY0_imagreal"><br />
[[File:afterXY0_imagreal.png|200px|thumb|right|<xr id="afterXY0_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G1, Kcr, XY0. '''TBD: ROSITA: redo plotms for this fig due to calwt=T in applycal''']]<br />
</figure><br />
<br />
The utility produces a new table with the unambiguous values of the XY-phases as well as a python variable S, reported in the last line,<br />
containing the mean source model (Stokes I=1; Q/I; U/I; V=0). This <br />
can be used in a revision of the gain calibration and instrumental <br />
polarization calibration. <br />
<br />
The XY-phase value in spw 1 has been converted from -73 to 107 degrees, as reported in the output. This can be seen when we compare the phases from both tables (see <xr id="XYcomparison" />). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.XY0amb','freq','phase',antenna='0',poln='X',subplot=121)<br />
plotcal('3c286_SV.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122)<br />
</source><br />
<br />
To clarify the effect produced by this calibration on the cross-hand phases, we can apply it to the data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c286_SV.ms',<br />
field='0',<br />
calwt=T,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G1','3c286_SV.ms.Kcrs','3c286_SV.ms.XY0'],<br />
interp=['nearest','linear','nearest','nearest'])<br />
</source><br />
<br />
Plotting the corrected phase versus frequency (<xr id="afterXY0" />) and comparing the result with <xr id="afterkcross_1bl" />, we see that <br />
the application of this table does indeed remove residual delays from the data. <br />
<br />
'''NEW: In terms of the real and imaginary parts, the application of this table removes the slope seen in <xr id="imagreal_bg1kcr" />. What we can see now in the complex plane (<xr id="afterXY0_imagreal" />) is the effect of parallactic angle variation of the source polarization (which makes the real parts of XY and YX range between -0.06 and 0.06) and of the instrumental polarization (producing a non-zero imaginary offset).'''<br />
<br />
====Revise gain with good source pol estimate====<br />
<br />
Now we revise the gain calibration using the full polarization source model we derived above.<br />
In this way we will remove from the gains any signature of the source polarization, which is now correctly accounted for in the model "S".<br />
Cross-hands are not used here, so cross-hand calibration tables are not needed.<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.G2.polcal') <br />
gaincal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.G2.polcal', <br />
field='0',<br />
solint='int',<br />
refant=refant,<br />
smodel=S,<br />
gaintable=['3c286_SV.ms.Bscan'],interp=['nearest'],<br />
parang=T)<br />
<br />
<br />
</source><br />
<br />
<figure id="G1_G2_ratio"><br />
[[Image:gainsG1_G2polcal_casa4.3.png|200px|thumb|right|<xr id="G1_G2_ratio" nolink/>. Complex polarization ratio comparison between table G1 and the revised G2.polcal]]<br />
</figure><br />
<br />
*caltable='*.G2.polcal': the output table. The name reminds us that these are gains for the polarization calibrator.<br />
*smodel=S: here we use as source model the full Stokes model we obtained above.<br />
*parang=T: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=T the supplied source linear polarization is properly rotated in the parallel-hand visibility model. This new gain solution can be plotted with poln=’/’ as above to show that the source polarization is no longer distorting it. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal('3c286_SV.ms.G1','time','amp',field='J1337-1257',poln='/',subplot=121)<br />
plotcal('3c286_SV.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122)<br />
</source><br />
<br />
''' CHECK: In <xr id="G1_G2_ratio" /> a small distortion can be noticed, in the central scans of table G2.polcal. It is due to antenna DV02 in spw 1, which shows a variation in the ratio slightly different than the average. '''<br />
<br />
Just to check: if qufromgain() is run on this new gain table, the reported source polarization should be statistically indistinguishable from zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
qufromgain('3c286_SV.ms.G2.polcal')<br />
</source><br />
<br />
We show here just the average values obtained, which can be compared with the last line of qufromgain() results, reported above.<br />
We can see that now the Q and U values are comparable to the rms.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spw mean: Fld= 0 Q= 0.000838681858308 U= -0.000234770753915 (rms= 0.000600891446491 0.000705059408831 ) <br />
P= 0.000870921676357 X= -7.81921742693<br />
</pre><br />
<br />
<br />
====Solving for the Leakage Terms====<br />
<br />
Finally, we can now solve for the instrumental polarization. <br />
this solve will produce an absolute instrumental polarization solution that is registered to the assumed source polarization and prior calibrations.<br />
To do that we apply all the previous calibrations in order to extract the D-terms from the corrected I, Q and U.<br />
<br />
The task used to estimate the D-terms is {{polcal}}:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
os.system('rm -rf 3c286_SV.ms.Df0*') <br />
polcal(vis='3c286_SV.ms',<br />
caltable='3c286_SV.ms.Df0', <br />
field='0', #J1337-1257<br />
solint='inf',combine='obs,scan',<br />
preavg=300,<br />
poltype='Dflls',<br />
refant='', #solve absolute D-term<br />
smodel=S,<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs', '3c286_SV.ms.XY0'],<br />
gainfield=['', '', '', ''],<br />
interp=['nearest','linear','nearest','nearest'])<br />
<br />
</source><br />
<br />
*caltable='*.Df0': the output table.<br />
*poltype='Dflls': frequency-dependent LLS solver '''ADD MORE'''<br />
*refant='': no reference antenna is needed here<br />
*smodel=S[0]: we use as model the "S" we calculated above<br />
*gaintable=['*.Bscan','*.G2.polcal','*.Kcrs', '*.XY0']: we apply the bandpass, gain, and cross-hand calibration tables (Kcrs, and XY0) <br />
<br />
Using a reference antenna would bias the net instrument polarization according to the actual (imperfect) instrumental polarization of the reference antenna's X feed. Since our calibrator is polarized, it provides constraints enabling us to avoid this bias, allowing us to solve for instrumental polarization calibration that is unbiased relative to the presumed calibrator polarization '''(I tried to reword this, but it still needs to be tweaked.)'''.<br />
<br />
Here we plot the amplitude, the real part, and the imaginary part of leakage (D-term) solutions, computed in frame of the telescope.<br />
<br />
<source lang="python"><br />
<br />
plotcal('3c286_SV.ms.Df0','freq','amp', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,0,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06])<br />
<br />
plotcal('3c286_SV.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
plotcal('3c286_SV.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06])<br />
plotcal('3c286_SV.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06])<br />
<br />
</source><br />
{|<br />
| <figure id="D_amp"> [[Image:Df0_amp_casa4.3.png|200px|thumb|left|<xr id="D_amp" nolink/>. Df0 amp vs freq]]</figure><br />
| <figure id="D_real"> [[Image:Df0_real_casa4.3.png|200px|thumb|left|<xr id="D_real" nolink/>. Df0 real vs freq]]</figure><br />
| <figure id="D_imag"> [[Image:Df0_imag_casa4.3.png|200px|thumb|center|<xr id="D_imag" nolink/>. Df0 imag vs freq]]</figure> <br />
|}<br />
<br />
The values obtained--a few percent for most of the antennas--are reasonable, and we will apply them to the data.<br />
<br />
Before applying them we need to modify the D-term table in order for it to be applied to the parallel-hands as<br />
well as the cross-hands.<br />
We do that using the module Dgen() of casapolhelpers.py:<br />
<br />
<source lang="python"><br />
<br />
# In CASA<br />
Dgen(dtab='3c286_SV.ms.Df0',dout='3c286_SV.ms.Df0gen')<br />
<br />
</source><br />
<br />
Before applying all the calibration tables, it is worth verifying the images resulting from a calibration not including the D-terms correction. <br />
This will be done in section 2 of the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3]]'''<br />
<br />
==Imaging of the polarization calibrator with and without applying D-terms corrections==<br />
<br />
Before proceeding with the application of all the calibration tables to the data, it makes sense to verify the actual effect of D-terms correction on the images. <br />
For verification purposes only we now apply to the polarization calibrator all calibration tables computed in the calibration guide ''except'' the D-terms corrections.<br />
In the dir 3C286_Band6_pol_UnCalibrated you should now have all the calibration tables, and you can proceed as follows:<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs', '3c286_SV.ms.XY0'],<br />
interp=['nearest','linear', 'nearest','nearest'], <br />
gainfield=['', '', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
Now we make a full-polarization image of the polarization calibrator, just for inspection purposes. <br />
We use the task {{clean}} interactively, adding a mask around the central source. <br />
In the following section you will find a more clear explanation of how to define the cell and imsize parameters.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.noDterm.Stokes.clean*')<br />
clean(vis='3c286_SV.ms',<br />
field='0',<br />
imagename='Field0.noDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T, niter=10000)<br />
<br />
</source><br />
<br />
After the first 500 iterations the residual image is noise-like and we stop the cleaning. The clean flux is of 1.06 Jy.<br />
<br />
Now we apply all the calibration tables, including Df0gen:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal','3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
<br />
</source><br />
<br />
And we clean again:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
os.system('rm -rf Field0.withDterm.Stokes.clean*')<br />
clean(vis='3c286_SV.ms',<br />
field='0',<br />
imagename='Field0.withDterm.Stokes.clean',<br />
cell=['0.1arcsec'],<br />
imsize=[250,250],<br />
stokes='IQUV',<br />
psfmode='clarkstokes',<br />
interactive=T,niter=10000)<br />
<br />
</source><br />
<br />
To reach the same clean flux (~ 1.06 Jy) more iterations are needed and the residuals level decreases.<br />
<br />
As you can see in <xr id="comparison" />, the application of D-term calibration clearly improves the images of Stokes Q, U, and V.<br />
<br />
<figure id="comparison"><br />
<gallery widths=220px heights=150px perrow=2 mode="nolines" ><br />
File:comparisonI.png | Stokes I.<br />
File:comparisonQ.png | Stokes Q.<br />
File:comparisonU.png | Stokes U.<br />
File:comparisonV.png | Stokes V.<br />
</gallery><br />
<xr id="comparison" nolink/>. Comparison between images of the polarization calibrator without (left panels) and with (right panels) the D-term corrections applied.<br />
</figure><br />
<br />
==Applying the calibrations and splitting of the corrected data==<br />
<br />
<figure id="afterall_imagreal"><br />
[[File:afterall_imagreal.png|200px|thumb|right|<xr id="afterall_imagreal" nolink/>. Imag vs real. Calibration tables applied to the data are B, G2polcal, Kcr, XY0, and D.]]<br />
</figure><br />
<br />
Now we will use {{applycal}} to apply the calibration tables that we generated in the previous sections. <br />
First, we apply the calibration tables to the polarization calibrator. <br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 0<br />
applycal(vis='3c286_SV.ms', <br />
field='0', <br />
calwt=[T,T,F,F,F],<br />
gaintable=['3c286_SV.ms.Bscan','3c286_SV.ms.G2.polcal',<br />
'3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear', 'linear','nearest', 'nearest'], <br />
gainfield=['', '','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
'''NEW: We first plot the complex plane again, and compare the results with <xr id="afterXY0_imagreal" />. <xr id="afterall_imagreal" /> shows clearly that the imaginary part is now zero, while the real part is corrected for the variation shown before; its corrected value is ~0.04.''' <br />
<br />
Let's now examine the corrected amplitude and phase of the polarization calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', xaxis='chan', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='0',<br />
averagedata=True, avgchannel='', <br />
avgtime='1e9', avgscan=T, <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
| <figure id="afterall_amp">[[Image:afterAll_allantennas_amp_casa4.3.png|200px|thumb|left|<xr id="afterall_amp" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration.]]</figure><br />
| <figure id="afterall_phase">[[Image:afterAll_allantennas_phase_casas4.3.png|200px|thumb|center|<xr id="afterall_phase" nolink/>. XX,YY, XY and YX amp vs channels for all antennas after the whole calibration]]</figure><br />
| <figure id="afterall_phase_1bl">[[File:afterAll_1baseline_phase.png|200px|thumb|right|<xr id="afterall_phase_1bl" nolink/>. Baseline DA48&DV23: XY and YX phase vs frequency after the whole calibration]]</figure><br />
|}<br />
<br />
In <xr id="afterall_amp" /> we see that the XX,YY correlations have unitary amplitude, since we didn't scaled the flux. <br />
The XY,YX amplitude value is of the order of 0.04, which means the polarization ratio of this source is ~4%. This value is consistent with what the previous steps revealed.<br />
After the calibration all the phases are zero (<xr id="afterall_phase" />). <br />
To more clearly show the effect of the D-terms application on the polarization calibrator we also plot the corrected phases of the baseline DA48&DV23 (<xr id="afterall_phase_1bl" />). Comparing this result with <xr id="afterXY0" /> we see that the XY and YX phases are now corrected and around zero.<br />
<br />
We now apply the solutions from the phase calibrator (field='3') to the science target (field='4'). <br />
Its flux scale has also been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator.<br />
We apply to these sources the polarization calibrations (Kcrs, XY0, and Df0gen) that we obtained for the polarization calibrator (field='0'). <br />
<br />
<source lang="python"><br />
# In CASA<br />
# Apply caltables to fields = 3 & 4<br />
applycal(vis='3c286_SV.ms', <br />
field='3,4', <br />
calwt=[T,T,F,F,F],<br />
gaintable = ['3c286_SV.ms.Bscan','3c286_SV.ms.G2ph','3c286_SV.ms.flux',<br />
'3c286_SV.ms.Kcrs','3c286_SV.ms.XY0','3c286_SV.ms.Df0gen'],<br />
interp=['nearest','linear','linear','nearest','nearest','nearest'], <br />
gainfield=['', '3', '3','', '', ''],<br />
parang=T)<br />
</source><br />
<br />
* gaintable=['*.Bscan', '*.G2ph', '*.flux', '*.Kcrs', '*.XY0', '*.Df0gen']: these are all the tables to be applied to the data.<br />
* interp=['nearest', 'linear', 'linear', 'nearest', 'nearest', 'nearest']: the corresponding interpolation method <br />
* gainfield=['', '3', '3','', '', '']: select the field from the corresponding gaintable. Here the phase calibrator gains are applied to both the calibrator itself and the target.<br />
* parang=T: apply the parallactic angle correction<br />
<br />
To check the effects of calibration on the scientific target we can compare the plot of imaginary vs real part before the calibration (xdatacolumn & ydatacolumn='data') and after (xdatacolumn & ydatacolumn='corrected'):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c286_SV.ms', field='4', <br />
xaxis='real', yaxis='imag', spw='0', <br />
ydatacolumn='data', xdatacolumn='data', selectdata=True, <br />
averagedata=True, avgchannel='1000', <br />
avgtime='1e9', avgscan=T, plotrange=[-1,1,-1,1], <br />
coloraxis='corr')<br />
</source><br />
<br />
{|<br />
|<figure id="field4_before"> [[Image:field4_beforeaal_casa4.3.png|200px|thumb|center|<xr id="field4_before" nolink/>. 3C286: zoom in of the plot of data columns. Imag vs real of parallel- and cross-hand correlations before the calibration. All scans have been averaged.]]</figure><br />
|<figure id="field4_aftall"> [[Image:field4_afterall_casa43..png|200px|thumb|right|<xr id="field4_aftall" nolink/>. 3C286: Imag vs real of parallel- and cross-hand correlations after the whole calibration. The corrected amplitude has been flux scaled, so it is in units of Jy.]]</figure><br />
|}<br />
<br />
You can see in these plots how the calibration has corrected the real and imaginary parts of the target visibilities. The imaginary parts of both the parallel and the cross-hands are close to zero, while the real parts are ~340 mJy and ~60 mJy, respectively.<br />
<br />
We now split the scientific target (field 4) corrected data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 3c286_SVpol.cal.ms') <br />
split(vis='3c286_SV.ms',<br />
outputvis='3c286_SVpol.cal.ms',<br />
field='4',<br />
datacolumn='corrected',<br />
width='8')<br />
</source><br />
<br />
Using the parameter '''width''' we average the channels, in order to reduce the size of the output file (3c286_SVpol.cal.ms will have 16 channels).<br />
In Band 3 TDM observations, averaging more than <br />
about 8 channels in full Stokes would produce significant bandwidth smearing.<br />
<br />
Now you can continue on to the '''[[3C286_Band6Pol_Imaging_for_CASA_4.3 |imaging guide]]'''.<br />
<br />
==References==<br />
<br />
* Synthesis Imaging in Radio Astronomy II, 1999, ASP Conference Series, Vol. 180, Editors: Taylor, G. B.; Carilli, C. L.; Perley, R. A. <br />
* Interferometry and Synthesis in Radio Astronomy, 2nd Edition, 2001, Thompson, A.R., Moran, J.M., Swenson, G. W., Ed. Wiley<br />
* AT polarization calibration, 1991, Sault, R. J., Killeen,N.E.B., & Kesteven, M.J., ATNF memo <br />
* Understanding radio polarimetry. I. Mathematical foundations., 1996, Hamaker, J. P.; Bregman, J. D.; Sault, R. J., Astronomy and Astrophysics Supplement, v.117<br />
<br />
<br />
{{Checked 3.0.0}}</div>Paladino