https://casaguides.nrao.edu/api.php?action=feedcontributions&user=Jthorley&feedformat=atomCASA Guides - User contributions [en]2024-03-29T07:44:13ZUser contributionsMediaWiki 1.38.6https://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=26740Self-Calibration Template CASA 6.1.12019-03-05T13:02:31Z<p>Jthorley: </p>
<hr />
<div>This guide continues with products created in '''[[Image_Continuum | Image the Continuum Template]]'''. All imaging parameters are set in the previous guide. You will need '''calibrated_final_cont.ms''' to proceed.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Self-Calibration on the Continuum (optional) ==<br />
<br />
If you have a high signal-to-noise detection of your source, you can use the source itself to calibrate the phases and potentially the amplitudes of the visibilities as a function of time. This technique is called self-calibration and takes advantage of the fact that interferometer data is over-constrained (we have more equations than we have solutions). The recommended signal to noise depends on the number of antennas. For an array of 40 antennas, you should have a Peak/RMS of at least 45 in your continuum image to attempt self-calibration. You can use the following relationship to find the minimum Peak/RMS for your dataset.<br />
<br />
<math><br />
\frac{Peak}{RMS} > 3 \sqrt{N-3} \sqrt{\frac{t_{int}}{t_{solint}}}<br />
</math><br />
<br />
<br />
where:<br />
<br />
''Peak'' is the maximum value in the continuum image.<br />
<br />
''RMS'' is the RMS of the non-self-calibrated continuum image.<br />
<br />
''N'' is the number of antennas.<br />
<br />
''t<sub>int</sub>'' is the total on source integration time.<br />
<br />
''t<sub>solint</sub>'' is the solution interval used to calculate the corrections. In this case, use the scan length.<br />
<br />
See the NRAO Live! presentation [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-wm16/Selfcal_Madison.pdf When, why, and how to do self-calibration] for more information on this relationship.<br />
<br />
Self-calibration is an iterative process. You start by generating a model of your source using {{tclean}}. Then you use this model to determine the gains as a function of time using the {{gaincal}} task. Finally you apply these solutions to the data and re-image. These steps are repeated until you are happy with your model or the solution interval is too short to reach the necessary signal-to-noise. In general, you start with phase-only self-calibration and only do amplitude calibration at the end of the self-calibration process if there are amplitude-based gain artifacts in the data (see the [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf Imaging and Deconvolution talk] from the Synthesis Imaging Summer School for more detail. Amplitude calibration should be used with caution because it has the potential to change the fluxes of sources in your data.<br />
<br />
Self-calibration can either be performed with line or continuum data. Here we demonstrate how to do it with continuum data. The principle is the same for line data, except you form your image using the brightest line emission. For an example of self-calibration with line data, see the [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216#UV_Continuum_Subtraction_and_Setting_Up_for_Self-Calibration VLA high frequency spectral line tutorial for IRC+10216].<br />
<br />
----<br />
<br />
The first thing you should do when beginning self-calibration is to save the original flags in your data set. This step is necessary because when you apply the calibration to a data set it flags data that is not associated with a solution. Applying a bad calibration table to your data can result in the excessive flagging of your data. Saving your original flags allows you to restore the original state of your data easily.<br />
We also recommend you save your flags after each {{applycal}} command. This will allow you to go back to a given point in the self-cal process without starting from the beginning. See [[Self_Calibration_Template#Restart_Self-Calibration]] if you need to start over or go back a step in self-cal.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='before_selfcal',merge='replace')<br />
</source><br />
<br />
Now we can set up the parameters for the self calibration. Begin by setting the parameters for your ms and continuum image name. The ms '''calibrated_final_cont.ms''' was created in the previous part of this guide: '''[[Image_Continuum | Image the Continuum Template]]'''.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
If you run the self-calibration process more than once, you will need to remove any models that could be left in the measurement set. This can can be accomplished by using the {{delmod}} task as well as the {{clearcal}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,field=field,otf=True)<br />
# clearcal(vis=contvis)<br />
</source><br />
<br />
You should use the same reference antenna that was used during calibration. For pipeline reductions, this can be found in the stage '''hif_refant''' as the first antenna in the list for each execution. For manual reductions, the reference antenna will be stated near the top of *.ms.scriptForCalibration.py. If there are multiple executions, make sure to use an antenna that has good solutions and is present in all executions. The Analysis Utilities task [https://safe.nrao.edu/wiki/bin/view/ALMA/CommonAntennas au.commonAntennas] can help you find antennas that meet this criteria. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. Tasks such as {{plotants}} or {{listobs}}/{{vishead}} can also be used to find antennas in all executions. <br />
<br />
<source lang="python"><br />
# in CASA<br />
refant = 'DV09' # pick a reference antenna.<br />
</source><br />
<br />
In the example below, we combine the signal from all spectral windows to improve the signal-to-noise for our gain solution. When combining the spectral windows, you need to map the solution from the combined spectral window (0) to the individual spectral windows using the spwmap parameter. This parameter is a list where the index of the element in the list indicates the spectral window and the value for that index the window that it is mapped to. For example, if we have three spectral windows in the original data set and use combine='spw' for our gain solution, we set spwmap=[0,0,0] to map spw=0 to spw=0, spw=1 to spw=0, and spw=2 to spw=0.<br />
<br />
<source lang="python"><br />
# in CASA<br />
spwmap = [0,0,0] # mapping self-calibration solutions to individual spectral windows. Generally an array of n zeroes, where n is the number of spectral windows in the data sets.<br />
</source><br />
<br />
You then begin the process of shallowly cleaning your continuum data to create an initial model for your data in the model column of your data set. Usually you only should do at most a few hundred iterations on the brightest source(s) in the field.<br />
<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shallow clean on the continuum<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p0'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p0',<br />
field=field,<br />
#phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
<br />
Next you take that model and use it to determine the per-antenna phase solutions as a function of time using {{gaincal}}. We use the {{rmtables}} command here to completely eradicate any previous solution table from CASA's memory. Note that we start here with a fairly long solution interval that is the length of a scan (solint='inf').<br />
<br />
<source lang="python"><br />
# in CASA<br />
# per scan solution<br />
rmtables('pcal1')<br />
gaincal(vis=contvis,<br />
caltable='pcal1',<br />
field=field,<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6)<br />
</source><br />
<br />
Inspect the logging messages output by {{gaincal}} to see how many solutions were expected/attempted/succeeded. If you have a large number of failed solutions, do not proceed further! This usually means that you do not have enough signal-to-noise on your source to proceed with self-calibration. Note that if you apply a calibration table with many failed solutions to the data, it will flag the data associated with these solutions. You may try changing the minsnr and minblperant parameters in the {{gaincal}} call above to find more solutions, but this option should be used with caution because these parameters are already low. This is especially relevant for 7-meter datasets, where achieving 6 baselines per antenna may be difficult. If you choose to modify these parameters, make sure to examine the results in detail.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Calibration solve statistics per spw: (expected/attempted/succeeded):<br />
Spw 0: 235/235/235<br />
Spw 1: 235/235/235<br />
Spw 2: 235/235/235<br />
</pre><br />
<figure id="Plotcal_image.png"><br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
</figure><br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal}}. The solutions should vary smoothly with time and there should not be any large outliers. The<br />
reference antenna’s phases should be flat in time. <br />
<br />
<source lang="python"><br />
# in CASA<br />
# Check the solution<br />
plotcal(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
If you are satisfied with the solutions, apply them to the ms. Note: this step usually takes a while, so go ahead and get a cup of coffee.<br />
<figure id="Pcal1.png"><br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# in CASA<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
field=field,<br />
spwmap=spwmap,<br />
gaintable=['pcal1'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
</source><br />
<br />
Save the flags in case you need to go back to this step.<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal1')<br />
</source><br />
<br />
Using our new gain solutions, we can generate an improved model for our source using {{tclean}}. During this second tclean iteration, you should clean a bit deeper than previously, but not all the way down to the noise. Remember the goal here is to build up a good model for your source, so you don't want to include things that are not real emission.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p1'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p1',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in the viewer to assess how well self-calibration worked. In general, the noise should be lower and the signal-to-noise ratio higher than in the original image and there should be no major new artifacts in the image. If the signal-to-noise ratio does not increase, you may not have enough signal-to-noise on your target to run self-calibration. If you don't see an improvement in the image, you may wish to try a new reference antenna by first clearing the calibration with clearcal (see commands above). If this still does not help improve the selfcal images you may proceed to [[Image_Line#Continuum_Subtraction_for_Line_Emission | continuum subtraction]] (if you are working on a line project).<br />
<br />
If the image has improved you can proceed with the self-cal and generate a new gain solution table. The next {{gaincal}} call uses a shorter solution interval (solint) to generate solutions on a shorter time interval. Note that we always want to generate our model based on the latest gaincal solutions. The calibration tables, however, should be generated by comparing the original visibilities to the model. This prevents bad solutions from propagating through different iterations of self-calibration.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shorter solution<br />
rmtables('pcal2')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal2',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='30.25s', # solint=30.25s gets you five 12m integrations, while solint=50.5s gets you five 7m integration<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal2'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal2')<br />
</source><br />
<br />
<br />
Now we can repeat the {{tclean}}/{{gaincal}}/{{applycal}} process until we start seeing many failed solutions and only small improvements to the data. Remember to clean a bit deeper each time to improve your model and be cautious about what emission you are including in your tclean mask. You should also decrease the solution interval each time to better model the gain variations with time. Note that it generally only take 3-4 rounds of phase self-calibration to produce a good solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p2'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p2',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
<br />
# shorter solution<br />
rmtables('pcal3')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal3',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='int',<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal3'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal3')<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p3'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p3',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
</source><br />
<figure id="Imaging-tutorial-selfcal-3.png"><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
</figure><br />
<figure id="Apcal.png"><br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<br />
</figure><br />
<br />
The next section performs an amplitude calibration. This is an optional part of self-calibration. If you are happy with the results of your phase calibration, you can stop here. However, if you see amplitude-based artifacts, you can attempt to improve the situation using amplitude self-calibration. Since amplitude solutions are inherently less constrained than phase solutions, we use a longer solution interval only here. If you have a complex source with lots of extended emission, you may set a uvrange limit on the data to avoid downweighting the large scale emission <br />
<br />
While the phase calibration involved iterating with different solution intervals, the amplitude self-calibration will only use an infinite solution interval.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables('apcal')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='apcal',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='ap',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6,<br />
# uvrange='>50m', # may need to use to exclude extended emission<br />
gaintable='pcal3',<br />
spwmap=spwmap,<br />
solnorm=True)<br />
<br />
plotcal(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,0.2,1.8])<br />
<br />
applycal(vis=contvis,<br />
spwmap=[spwmap,spwmap], # select which spws to apply the solutions for each table<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_apcal')<br />
<br />
# Make amplitude and phase self-calibrated image.<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_ap'+ ext)<br />
<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_ap',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn',<br />
pbcor=True) # apply the primary beam correction since this is the last image.<br />
</source><br />
<br />
Compare the final image to the initial image and see if the image dynamic range (ratio betwen peak flux and rms noise) has improved and phase- and amplitude-based errors have improved.<br />
<br />
Finally, you should split out the results of your self-calibration for safe-keeping. <br />
<br />
<source lang="python"><br />
# in CASA<br />
split(vis=contvis,<br />
outputvis=contvis+'.selfcal', datacolumn='corrected')<br />
</source><br />
<br />
== Restart Self-Calibration ==<br />
<br />
If you would like to revert to a certain point in the self-cal process, use the following commands to do so.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to a given point in the iterative process (here after pcal2 has been applied)<br />
# flagmanager(vis=contvis, mode='restore',versionname='after_pcal2')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
Then return to the {{applycal}} step that applied the desired calibration table. In the example code above, you would return to where the table pcal2 was applied. <br />
<br />
If you are unhappy with the self-calibration, use the {{clearcal}} and {{delmod}} tasks and restore the original flags to return your ms to it’s original pre-self-cal state.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to pre self-cal ms<br />
# flagmanager(vis=contvis, mode='restore',versionname='before_selfcal')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
<br />
If you have line data, you will subtract the continuum and apply the self-calibration results to the line data on the next page, '''[[Image_Line | Spectral Line Imaging Template]]'''.<br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25794Image Continuum CASA 6.1.12018-11-27T14:51:00Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure 1 shows a clear line at channel 1700 whereas Figure 2 shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic and set to appropriate field number<br />
# phasecenter='TRACKFIELD' # uncomment if imaging an ephemeris object, the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
For ephemeris objects such as planets, the outframe should be set to phasecenter = 'TRACKFIELD', not a field number as above.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'.<br />
# phasecenter = 'TRACKFIELD' # If imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image. If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25793Image Continuum CASA 6.1.12018-11-27T14:49:49Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure 1 shows a clear line at channel 1700 whereas Figure 2 shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic and set to appropriate field number<br />
# phasecenter='TRACKFIELD' # uncomment if imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
For ephemeris objects such as planets, the outframe should be set to phasecenter = 'TRACKFIELD', not a field number as above.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'.<br />
# phasecenter = 'TRACKFIELD' # If imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image. If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25792Image Continuum CASA 6.1.12018-11-27T14:49:24Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure 1 shows a clear line at channel 1700 whereas Figure 2 shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic and set to appropriate field number<br />
# phasecenter = 'TRACKFIELD' # uncomment if imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
For ephemeris objects such as planets, the outframe should be set to phasecenter = 'TRACKFIELD', not a field number as above.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'.<br />
# phasecenter = 'TRACKFIELD' # If imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image. If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25791Image Continuum CASA 6.1.12018-11-27T14:46:52Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure 1 shows a clear line at channel 1700 whereas Figure 2 shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
For ephemeris objects such as planets, the outframe should be set to phasecenter = 'TRACKFIELD', not a field number as above.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'.<br />
# phasecenter = 'TRACKFIELD' # If imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image. If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25790Image Continuum CASA 6.1.12018-11-27T14:34:27Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
For ephemeris objects such as planets, the outframe should be set to phasecenter = 'TRACKFIELD', not a field number as above.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'.<br />
# phasecenter = 'TRACKFIELD' # If imaging an ephemeris object (planet, etc), the phasecenter needs to be TRACKFIELD, not a field number as above.<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image. If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25789Image Continuum CASA 6.1.12018-11-27T14:26:15Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image. If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25788Image Continuum CASA 6.1.12018-11-27T14:25:29Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
If you are making a mosaic image do not use a robust value smaller than 0 as this may introduce major artifacts in the images including uneven noise across the image.<br />
If you choose to do any form of uvtapering to the data in tclean(), set robust to 2 (Natural weighting) to avoid upweighting points that are going to be downweighted by uv-taper.<br />
<br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25787Image Line CASA 6.1.12018-11-27T14:14:57Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful if you would like {{tclean}} to produce the mask for you.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. By only imaging a subsection of the spectral window you can speed up the time it takes {tclean} to produce a cube and reduces the final size of the cube.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object <br />
# mosweight = True, # uncomment if mosaic <br />
specmode='cube', # comment this if observing an ephemeris source<br />
#specmode='cubesource', #uncomment this line if observing an ephemeris source<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common',<br />
chanchunks=-1) # break up large cubes automatically so that you don't run out of memory.<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25786Image Continuum CASA 6.1.12018-11-27T14:13:35Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
In CASA 5.4 and later, {{tclean}} calls with gridder = 'mosaic' have an additional parameter mosweight with a default of True. When mosweight = True, the gridder weights each field in the mosaic independently. The mosweight parameter is particularly important for mosaics with non-uniform sensitivity, with rectangular shapes, or when using more uniform values of robust Briggs weighting. For more information on mosweight, please see the {{tclean}} documentation.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25763Image Line CASA 6.1.12018-11-26T18:09:17Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful if you would like {{tclean}} to produce the mask for you.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. By only imaging a subsection of the spectral window you can speed up the time it takes {tclean} to produce a cube and reduces the final size of the cube.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object <br />
# mosweight = True, # uncomment if mosaic <br />
specmode='cube', # comment this if observing an ephemeris source<br />
#specmode='cubesource', #uncomment this line if observing an ephemeris source<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common',<br />
chanchunks=-1) # break up large cubes automatically so that you don't run out of memory.<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25762Image Line CASA 6.1.12018-11-26T18:02:05Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful if you would like {{tclean}} to produce the mask for you.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. By only imaging a subsection of the spectral window you can speed up the time it takes {tclean} to produce a cube and reduces the final size of the cube.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object <br />
# mosweight = True, # uncomment if mosaic <br />
specmode='cube', # comment this if observing an ephemeris source<br />
#specmode='cubesource', #uncomment this line if observing an ephemeris source<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common',<br />
chanchunks=-1) # break up large cubes automatically so that you don't run out of memory.<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25761Image Line CASA 6.1.12018-11-26T18:00:01Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful if you would like {{tclean}} to produce the mask for you.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. By only imaging a subsection of the spectral window you can speed up the time it takes {tclean} to produce a cube and reduces the final size of the cube.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object <br />
# mosweight = True, # uncomment if mosaic <br />
specmode='cube', # comment this if observing an ephemeris source<br />
#specmode='cubesource', #uncomment this line if observing an ephemeris source<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common',<br />
chanchunks=-1) # break up large cubes automatically so that you don't run out of memory.<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25760Image Line CASA 6.1.12018-11-26T17:58:30Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful if you would like {tclean} to produce the mask for you.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. By only imaging a subsection of the spectral window you can speed up the time it takes {tclean} to produce a cube and reduces the final size of the cube.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object <br />
# mosweight = True, # uncomment if mosaic <br />
specmode='cube', # comment this if observing an ephemeris source<br />
#specmode='cubesource', #uncomment this line if observing an ephemeris source<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common',<br />
chanchunks=-1) # break up large cubes automatically so that you don't run out of memory.<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25755Image Line CASA 6.1.12018-11-26T16:34:02Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful if you would like {tclean} to produce the mask for you.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. For example, by looking at Figure 1, you can determine that it would be appropriate to image the inner 100 channels at a spectral resolution of 2 km/s.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object <br />
# mosweight = True, # uncomment if mosaic <br />
specmode='cube', # comment this if observing an ephemeris source<br />
#specmode='cubesource', #uncomment this line if observing an ephemeris source<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common',<br />
chanchunks=-1) # break up large cubes automatically so that you don't run out of memory.<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Line_CASA_6.1.1&diff=25754Image Line CASA 6.1.12018-11-26T16:31:37Z<p>Jthorley: </p>
<hr />
<div>This guide continues from '''[[Image_Continuum | Image the Continuum Template]]''' and '''[[Self_Calibration_Template | Self-Calibration Template]]''' (optional). Imaging parameters and calibration tables (if applicable) should already be set prior to continuing. <br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Continuum Subtraction for Line Emission ==<br />
<br />
If you have observations that include both line and strong continuum emission (>3 sigma per channel), you should subtract the continuum from the spectral windows before imaging the line. You do not need to continuum subtract if the line of interest is an absorption line. <br />
<br />
To subtract the continuum, you need to select channel ranges which only contain continuum. The continuum subtraction routine will then do a linear fit to each integration to determine the continuum and then subtract that linear fit from the data. The range used to fit the continuum is just the opposite of the channels you flagged when creating the continuum (see [[Image Continuum#Create an Averaged Continuum MS | Create an Averaged Continuum MS]] section of the [[Image Continuum]] guide. You can either manually invert the channels or use the Analysis Utilities routine [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] to determine the channel ranges. Note that if you use [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges], you will need to include any continuum spws that weren't in flagchannels. For example, if your continuum spws are '0,1,2' and flagchannels='1:260~500', [https://safe.nrao.edu/wiki/bin/view/ALMA/InvertChannelRanges au.invertChannelRanges] will return '1:0~259,1:501~3839'. The fitspw parameter should be '0,1:0~259,1:501~3839,2'. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Continuum subtraction is done per field. If all your fields have the same line-free channels, you only have to run {{uvcontsub}} once. However, if different fields have different line-free channels, then you will need to run {{uvcontsub}} multiple times. (And probably get a cup of coffee or two.)<br />
<br />
The output file for {{uvcontsub}} will be vis + ".contsub". It will read from the corrected data column if it is present and the data column if the corrected data column is not present. You can use {{plotms}} to make sure that the appropriate data is in the appropriate column of your ms. Note that this behavior is different in the pipeline implementation of continuum subtraction '''hif_uvcontsub'''. <br />
<br />
Note that want_cont=True produces a model of the emission and not the actual continuum subtracted ms. The results of want_cont=True should not be used to produce an image of the continuum for a source.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fitspw = '2:1201~2199,3:1201~2199' # line free channels. Use au.invertChannelRanges<br />
linespw = '2,3' # line spectral windows. You can subtract the continuum from multiple spectral line windows at once.<br />
<br />
finalvis='calibrated_final.ms'<br />
<br />
uvcontsub(vis=finalvis,<br />
spw=linespw, # spw to do continuum subtraction on<br />
fitspw=fitspw, # regions without lines.<br />
excludechans=False, # fit the regions in fitspw<br />
#combine='spw', uncomment if there are no line-free channels in the line spectral window. <br />
solint='int',<br />
fitorder=1,<br />
want_cont=False) # This value should not be changed.<br />
</source><br />
<br />
== Apply continuum self-calibration to line data (optional) ==<br />
<br />
This section depends on solutions derived with '''[[Self_Calibration_Template | Self-Calibration Template]]'''. Skip to [[Image_Line#Image_line_emission_.28repeat_as_necessary.29 | Image Line Emission]] if you do not wish to apply self-calibration solutions to the line data.<br />
<br />
If you find self-calibration does help with lowering the rms in your continuum images, it is a good idea to apply the continuum self-calibration to the line data. Depending on if you performed continuum subtraction, select the definition of linevis accordingly. Once this has been done, it is recommended that you save the flags before you apply the self-calibration solution to the individual line spectral windows, in case you do not like the results or they do not improve the image. If self-calibration of the continuum does improve the quality of the data, apply the derived gaintable to the spectral line channels using the {{applycal}} task. This will improve the image quality of the stronger spectral line channels, but will not help (or harm) the weaker line channels. Then save the results of self-cal in a new ms and reset the image name. You also need to reset the corrected data column in the ms to the original calibration. The clearcal(linevis) task can also be used to return your ms to its original pre-self-cal state, if you are dissatisfied with the self-calibration results. <br />
<source lang="python"><br />
# in CASA<br />
# Uncomment one of the following: <br />
# linevis = finalvis+'.contsub' # if continuum subtracted<br />
# linevis = finalvis # if not continuum subtracted<br />
# save original flags in case you don't like the self-cal<br />
flagmanager(vis=linevis,mode='save',versionname='before_selfcal',merge='replace')<br />
<br />
spwmap_line = [0] # Mapping self-calibration solution to the individual line spectral windows.<br />
applycal(vis=linevis,<br />
spwmap=[spwmap_line, spwmap_line], # entering the appropriate spwmap_line value for each spw in the input dataset<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp=['linearperobs','linearperobs'])<br />
<br />
# Save results of self-cal in a new ms and reset the image name.<br />
split(vis=linevis,<br />
outputvis=linevis+'.selfcal',<br />
datacolumn='corrected')<br />
</source><br />
<br />
== Image line emission (repeat as necessary) ==<br />
<br />
You should now have a measurement set that is ready to create cubes of the line emission. <br />
<br />
If you are new to line imaging, look at [[First Look at Line Imaging]] for an introduction to creating line cubes.<br />
<br />
If you expect more complex emission and do not want to create the mask by hand, you can use the directions at [[Create a Clean Mask from Continuum Image or Moment Cube]] to create a mask from the dirty cube.<br />
<br />
Depending on the observation and the steps you have applied previously, the measurement set may have a variety of names. Make sure to select the correct option below.<br />
<br />
<source lang="python"><br />
# in CASA<br />
finalvis = 'calibrated_final.ms'<br />
<br />
# uncomment if you have neither continuum subtracted nor self-calibrated your data<br />
# linevis = finalvis<br />
# uncomment if you have continuum subtracted your data<br />
# linevis = finalvis + ‘.contsub’<br />
# uncomment if you have both continuum subtracted and self-calibrated your data<br />
# linevis = finalvis + '.contsub.selfcal'<br />
# uncomment if you have only self-calibrated your data<br />
# linevis = finalvis + '.selfcal'<br />
</source><br />
<br />
The measurement set indicated in the linevis variable will be used for the rest of the cleaning. Before starting to clean your line cube, run a {{vishead}} or {{listobs}} to check on the spectral window and field numbers, which may have been re-numbered during the previous steps in the imaging process.<br />
<br />
<source lang="python"><br />
# in CASA<br />
vishead(linevis)<br />
</source><br />
<br />
Now you need to set the necessary parameters for {{tclean}}. If you haven't already, follow the procedure in the [[Image Continuum#Imaging Parameters | Image Continuum]] section to set the imsize, cellsize, field, phasecenter,etc. Here we focus on the additional parameters needed to image line data.<br />
<br />
First, we set the imagename. Here we name the image for the source and line observed, but you could give it any name you'd like.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcename ='n253' # name of source<br />
linename = 'CO10' # name of transition <br />
lineimagename = sourcename+'_'+linename # name of line image<br />
</source><br />
<br />
Next select the spws you would like to image. You should only image spws associated with a single rest frequency in the same image. If you have multiple executions and did not regrid the frequency axis using cvel, you will have to select multiple spws (one for each execution). The restfreq is typically set at the rest frequency of the line of interest. If the source is significantly redshifted (z>0.2), common practice is to set the rest frequency to the observed sky frequency (nu_rest/1+z) instead. Then the velocity axis shows offsets from the expected sky frequency.<br />
<br />
Finally, if {{cvel}} or {{mstransform}} was used to regrid spectral windows, make sure to use the same values below as you used with those tasks. In other words, avoid regridding your frequency axis twice: once in {{cvel}} and once in {{tclean}}.<br />
<figure id="TWHydra_CO3_2_plotms.png"><br />
[[File:TWHydra_CO3_2_plotms.png|thumb|<caption>The CO window is plotted in plotms. Use this to determine the start and nchan parameters.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
spw = ‘0’ # update to the spw you would like to image<br />
restfreq='115.27120GHz’<br />
</source><br />
<br />
<br />
The start, width, and nchan parameters will determine the size of the cube you create. Setting the values at their defaults will image the entire spectral window at the native resolution. <br />
<br />
<source lang="python"><br />
# in CASA<br />
start = ‘’<br />
width = ‘’<br />
nchan = -1<br />
</source><br />
<br />
You can also image a subset of the cube. For example, by looking at Figure 1, you can determine that it would be appropriate to image the inner 100 channels at a spectral resolution of 2 km/s.<br />
<br />
<source lang="python"><br />
# in CASA<br />
start='-100km/s' <br />
width='2km/s'<br />
nchan = 100<br />
</source><br />
<br />
Remember that you have already set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for 'extragalactic' sources and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
Generally, if you set outframe = 'bary' and restfreq = observed frequency, the line center should be at around 0 km/s. If you set outframe = 'lsrk' and restfreq = lab frequency, you will need to know the source radial velocity in order to predict the line position. If you are unsure, you can use the {{plotms}} command below to plot the visibilities to explore the effects of outframe and restfreq.<br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. It is standard to leave this set to ‘radio’ in all projects regardless of the velocity frame used in the project.<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
You can use {{plotms}} to find the line if it is bright enough to show up in the averaged visibilities. This is similar to the procedure you used to identify the line when creating the averaged continuum ms in [[Image Continuum#Create an Averaged | Continuum MS]]. <br />
<br />
<figure id="CO_initial_image.png"><br />
[[File:CO_initial_image.png|thumb|<caption>Channel 54 of the CO line cube is shown. Create a mask for each channel or all channels and proceed with cleaning.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=linevis,xaxis=’velocity’,yaxis=’amp’,avgtime=’1e8’,avgscan=True,avgantenna=True,spw=spw,coloraxis=’spw’,transform=True,freqframe=outframe.upper(),restfreq=restfreq)<br />
</source><br />
<br />
The {{tclean}} command for generating your line cube is shown below. You can use this template to image all targeted lines in your observation. For more information about the tclean GUI, see [[Image_Continuum#Imaging_the_Continuum | Imaging the Continuum]] section of the guide.<br />
<br />
If you are creating your mask manually, notice that the default is to apply the mask to the current channel you are viewing. The mask can also be applied to all channels. This is indicated with the "This Channel" or "All Channels" toggle.<br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=linevis,<br />
imagename=lineimagename, <br />
field=field,<br />
spw=spw,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
start=start,<br />
width=width,<br />
nchan=nchan, <br />
outframe=outframe,<br />
veltype=veltype, <br />
restfreq=restfreq, <br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting,<br />
robust=robust,<br />
gridder=gridder,<br />
pbcor=True,<br />
restoringbeam='common')<br />
</source><br />
<br />
As you may recall from the continuum imaging section, {{tclean}} generates several images with the name imagename+extension every time it cleans an image. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images from open version of CASA, you need to run the {{rmtables}} command. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(vis=linevis)<br />
delmod(vis=linevis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(lineimagename + ext)<br />
</source><br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<figure id="TWHydra_CO_3_2.image.mom8.png"><br />
[[File:TWHydra_CO_3_2.image.mom8.png|thumb|<caption>The moment 8 map is shown for the CO (3-2) line cube created above.</caption>]]<br />
</figure><br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The commands create png files of the continuum image and moment 8 maps. <br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
<br />
mylineimages = glob.glob("*cube*manual.image")<br />
for limage in mylineimages:<br />
mom8=limage+'.mom8'<br />
os.system("rm -rf "+mom8)<br />
immoments(limage,moments=[8],outfile=mom8)<br />
mymax=imstat(mom8)['max'][0]<br />
mymin=-0.1*mymax<br />
os.system("rm -rf "+mom8+".png")<br />
imview(raster={'file':mom8,'range':[mymin,mymax]},out=mom8+'.png')<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=25753Self-Calibration Template CASA 6.1.12018-11-26T16:26:56Z<p>Jthorley: </p>
<hr />
<div>This guide continues with products created in '''[[Image_Continuum | Image the Continuum Template]]'''. All imaging parameters are set in the previous guide. You will need '''calibrated_final_cont.ms''' to proceed.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Self-Calibration on the Continuum (optional) ==<br />
<br />
If you have a high signal-to-noise detection of your source, you can use the source itself to calibrate the phases and potentially the amplitudes of the visibilities as a function of time. This technique is called self-calibration and takes advantage of the fact that interferometer data is over-constrained (we have more equations than we have solutions). The recommended signal to noise depends on the number of antennas. For an array of 40 antennas, you should have a Peak/RMS of at least 45 in your continuum image to attempt self-calibration. You can use the following relationship to find the minimum Peak/RMS for your dataset.<br />
<br />
<math><br />
\frac{Peak}{RMS} > 3 \sqrt{N-3} \sqrt{\frac{t_{int}}{t_{solint}}}<br />
</math><br />
<br />
<br />
where:<br />
<br />
''Peak'' is the maximum value in the continuum image.<br />
<br />
''RMS'' is the RMS of the non-self-calibrated continuum image.<br />
<br />
''N'' is the number of antennas.<br />
<br />
''t<sub>int</sub>'' is the total on source integration time.<br />
<br />
''t<sub>solint</sub>'' is the solution interval used to calculate the corrections. In this case, use the scan length.<br />
<br />
See the NRAO Live! presentation [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-wm16/Selfcal_Madison.pdf When, why, and how to do self-calibration] for more information on this relationship.<br />
<br />
Self-calibration is an iterative process. You start by generating a model of your source using {{tclean}}. Then you use this model to determine the gains as a function of time using the {{gaincal}} task. Finally you apply these solutions to the data and re-image. These steps are repeated until you are happy with your model or the solution interval is too short to reach the necessary signal-to-noise. In general, you start with phase-only self-calibration and only do amplitude calibration at the end of the self-calibration process if there are amplitude-based gain artifacts in the data (see the [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf Imaging and Deconvolution talk] from the Synthesis Imaging Summer School for more detail. Amplitude calibration should be used with caution because it has the potential to change the fluxes of sources in your data.<br />
<br />
Self-calibration can either be performed with line or continuum data. Here we demonstrate how to do it with continuum data. The principle is the same for line data, except you form your image using the brightest line emission. For an example of self-calibration with line data, see the [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216#UV_Continuum_Subtraction_and_Setting_Up_for_Self-Calibration VLA high frequency spectral line tutorial for IRC+10216].<br />
<br />
----<br />
<br />
The first thing you should do when beginning self-calibration is to save the original flags in your data set. This step is necessary because when you apply the calibration to a data set it flags data that is not associated with a solution. Applying a bad calibration table to your data can result in the excessive flagging of your data. Saving your original flags allows you to restore the original state of your data easily.<br />
We also recommend you save your flags after each {{applycal}} command. This will allow you to go back to a given point in the self-cal process without starting from the beginning. See [[Self_Calibration_Template#Restart_Self-Calibration]] if you need to start over or go back a step in self-cal.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='before_selfcal',merge='replace')<br />
</source><br />
<br />
Now we can set up the parameters for the self calibration. Begin by setting the parameters for your ms and continuum image name. The ms '''calibrated_final_cont.ms''' was created in the previous part of this guide: '''[[Image_Continuum | Image the Continuum Template]]'''.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
If you run the self-calibration process more than once, you will need to remove any models that could be left in the measurement set. This can can be accomplished by using the {{delmod}} task as well as the {{clearcal}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,field=field,otf=True)<br />
# clearcal(vis=contvis)<br />
</source><br />
<br />
You should use the same reference antenna that was used during calibration. For pipeline reductions, this can be found in the stage '''hif_refant''' as the first antenna in the list for each execution. For manual reductions, the reference antenna will be stated near the top of *.ms.scriptForCalibration.py. If there are multiple executions, make sure to use an antenna that has good solutions and is present in all executions. The Analysis Utilities task [https://safe.nrao.edu/wiki/bin/view/ALMA/CommonAntennas au.commonAntennas] can help you find antennas that meet this criteria. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. Tasks such as {{plotants}} or {{listobs}}/{{vishead}} can also be used to find antennas in all executions. <br />
<br />
<source lang="python"><br />
# in CASA<br />
refant = 'DV09' # pick a reference antenna.<br />
</source><br />
<br />
In the example below, we combine the signal from all spectral windows to improve the signal-to-noise for our gain solution. When combining the spectral windows, you need to map the solution from the combined spectral window (0) to the individual spectral windows using the spwmap parameter. This parameter is a list where the index of the element in the list indicates the spectral window and the value for that index the window that it is mapped to. For example, if we have three spectral windows in the original data set and use combine='spw' for our gain solution, we set spwmap=[0,0,0] to map spw=0 to spw=0, spw=1 to spw=0, and spw=2 to spw=0.<br />
<br />
<source lang="python"><br />
# in CASA<br />
spwmap = [0,0,0] # mapping self-calibration solutions to individual spectral windows. Generally an array of n zeroes, where n is the number of spectral windows in the data sets.<br />
</source><br />
<br />
You then begin the process of shallowly cleaning your continuum data to create an initial model for your data in the model column of your data set. Usually you only should do at most a few hundred iterations on the brightest source(s) in the field.<br />
<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shallow clean on the continuum<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p0'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p0',<br />
field=field,<br />
#phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
<br />
Next you take that model and use it to determine the per-antenna phase solutions as a function of time using {{gaincal}}. We use the {{rmtables}} command here to completely eradicate any previous solution table from CASA's memory. Note that we start here with a fairly long solution interval that is the length of a scan (solint='inf').<br />
<br />
<source lang="python"><br />
# in CASA<br />
# per scan solution<br />
rmtables('pcal1')<br />
gaincal(vis=contvis,<br />
caltable='pcal1',<br />
field=field,<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6)<br />
</source><br />
<br />
Inspect the logging messages output by {{gaincal}} to see how many solutions were expected/attempted/succeeded. If you have a large number of failed solutions, do not proceed further! This usually means that you do not have enough signal-to-noise on your source to proceed with self-calibration. Note that if you apply a calibration table with many failed solutions to the data, it will flag the data associated with these solutions. You may try changing the minsnr and minblperant parameters in the {{gaincal}} call above to find more solutions, but this option should be used with caution because these parameters are already low. This is especially relevant for 7-meter datasets, where achieving 6 baselines per antenna may be difficult. If you choose to modify these parameters, make sure to examine the results in detail.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Calibration solve statistics per spw: (expected/attempted/succeeded):<br />
Spw 0: 235/235/235<br />
Spw 1: 235/235/235<br />
Spw 2: 235/235/235<br />
</pre><br />
<figure id="Plotcal_image.png"><br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
</figure><br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal}}. The solutions should vary smoothly with time and there should not be any large outliers. The<br />
reference antenna’s phases should be flat in time. The reference antenna’s phases should be flat in time. <br />
<br />
<source lang="python"><br />
# in CASA<br />
# Check the solution<br />
plotcal(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
If you are satisfied with the solutions, apply them to the ms. Note: this step usually takes a while, so go ahead and get a cup of coffee.<br />
<figure id="Pcal1.png"><br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# in CASA<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
field=field,<br />
spwmap=spwmap,<br />
gaintable=['pcal1'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
</source><br />
<br />
Save the flags in case you need to go back to this step.<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal1')<br />
</source><br />
<br />
Using our new gain solutions, we can generate an improved model for our source using {{tclean}}. During this second tclean iteration, you should clean a bit deeper than previously, but not all the way down to the noise. Remember the goal here is to build up a good model for your source, so you don't want to include things that are not real emission.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p1'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p1',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in the viewer to assess how well self-calibration worked. In general, the noise should be lower and the signal-to-noise ratio higher than in the original image and there should be no major new artifacts in the image. If the signal-to-noise ratio does not increase, you may not have enough signal-to-noise on your target to run self-calibration. If you don't see an improvement in the image, you may wish to try a new reference antenna by first clearing the calibration with clearcal (see commands above). If this still does not help improve the selfcal images you may proceed to [[Image_Line#Continuum_Subtraction_for_Line_Emission | continuum subtraction]] (if you are working on a line project).<br />
<br />
If the image has improved you can proceed with the self-cal and generate a new gain solution table. The next {{gaincal}} call uses a shorter solution interval (solint) to generate solutions on a shorter time interval. Note that we always want to generate our model based on the latest gaincal solutions. The calibration tables, however, should be generated by comparing the original visibilities to the model. This prevents bad solutions from propagating through different iterations of self-calibration.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shorter solution<br />
rmtables('pcal2')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal2',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='30.25s', # solint=30.25s gets you five 12m integrations, while solint=50.5s gets you five 7m integration<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal2'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal2')<br />
</source><br />
<br />
<br />
Now we can repeat the {{tclean}}/{{gaincal}}/{{applycal}} process until we start seeing many failed solutions and only small improvements to the data. Remember to clean a bit deeper each time to improve your model and be cautious about what emission you are including in your tclean mask. You should also decrease the solution interval each time to better model the gain variations with time. Note that it generally only take 3-4 rounds of phase self-calibration to produce a good solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p2'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p2',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
<br />
# shorter solution<br />
rmtables('pcal3')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal3',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='int',<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal3'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal3')<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p3'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p3',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
</source><br />
<figure id="Imaging-tutorial-selfcal-3.png"><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
</figure><br />
<figure id="Apcal.png"><br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<br />
</figure><br />
<br />
The next section performs an amplitude calibration. This is an optional part of self-calibration. If you are happy with the results of your phase calibration, you can stop here. However, if you see amplitude-based artifacts, you can attempt to improve the situation using amplitude self-calibration. Since amplitude solutions are inherently less constrained than phase solutions, we use a longer solution interval only here. If you have a complex source with lots of extended emission, you may set a uvrange limit on the data to avoid downweighting the large scale emission <br />
<br />
While the phase calibration involved iterating with different solution intervals, the amplitude self-calibration will only use an infinite solution interval.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables('apcal')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='apcal',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='ap',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6,<br />
# uvrange='>50m', # may need to use to exclude extended emission<br />
gaintable='pcal3',<br />
spwmap=spwmap,<br />
solnorm=True)<br />
<br />
plotcal(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,0.2,1.8])<br />
<br />
applycal(vis=contvis,<br />
spwmap=[spwmap,spwmap], # select which spws to apply the solutions for each table<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_apcal')<br />
<br />
# Make amplitude and phase self-calibrated image.<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_ap'+ ext)<br />
<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_ap',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn',<br />
pbcor=True) # apply the primary beam correction since this is the last image.<br />
</source><br />
<br />
Compare the final image to the initial image and see if the image dynamic range (ratio betwen peak flux and rms noise) has improved and phase- and amplitude-based errors have improved.<br />
<br />
Finally, you should split out the results of your self-calibration for safe-keeping. <br />
<br />
<source lang="python"><br />
# in CASA<br />
split(vis=contvis,<br />
outputvis=contvis+'.selfcal', datacolumn='corrected')<br />
</source><br />
<br />
== Restart Self-Calibration ==<br />
<br />
If you would like to revert to a certain point in the self-cal process, use the following commands to do so.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to a given point in the iterative process (here after pcal2 has been applied)<br />
# flagmanager(vis=contvis, mode='restore',versionname='after_pcal2')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
Then return to the {{applycal}} step that applied the desired calibration table. In the example code above, you would return to where the table pcal2 was applied. <br />
<br />
If you are unhappy with the self-calibration, use the {{clearcal}} and {{delmod}} tasks and restore the original flags to return your ms to it’s original pre-self-cal state.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to pre self-cal ms<br />
# flagmanager(vis=contvis, mode='restore',versionname='before_selfcal')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
<br />
If you have line data, you will subtract the continuum and apply the self-calibration results to the line data on the next page, '''[[Image_Line | Spectral Line Imaging Template]]'''.<br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=25752Self-Calibration Template CASA 6.1.12018-11-26T16:25:47Z<p>Jthorley: </p>
<hr />
<div>This guide continues with products created in '''[[Image_Continuum | Image the Continuum Template]]'''. All imaging parameters are set in the previous guide. You will need '''calibrated_final_cont.ms''' to proceed.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Self-Calibration on the Continuum (optional) ==<br />
<br />
If you have a high signal-to-noise detection of your source, you can use the source itself to calibrate the phases and potentially the amplitudes of the visibilities as a function of time. This technique is called self-calibration and takes advantage of the fact that interferometer data is over-constrained (we have more equations than we have solutions). The recommended signal to noise depends on the number of antennas. For an array of 40 antennas, you should have a Peak/RMS of at least 45 in your continuum image to attempt self-calibration. You can use the following relationship to find the minimum Peak/RMS for your dataset.<br />
<br />
<math><br />
\frac{Peak}{RMS} > 3 \sqrt{N-3} \sqrt{\frac{t_{int}}{t_{solint}}}<br />
</math><br />
<br />
<br />
where:<br />
<br />
''Peak'' is the maximum value in the continuum image.<br />
<br />
''RMS'' is the RMS of the non-self-calibrated continuum image.<br />
<br />
''N'' is the number of antennas.<br />
<br />
''t<sub>int</sub>'' is the total on source integration time.<br />
<br />
''t<sub>solint</sub>'' is the solution interval used to calculate the corrections. In this case, use the scan length.<br />
<br />
See the NRAO Live! presentation [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-wm16/Selfcal_Madison.pdf When, why, and how to do self-calibration] for more information on this relationship.<br />
<br />
Self-calibration is an iterative process. You start by generating a model of your source using {{tclean}}. Then you use this model to determine the gains as a function of time using the {{gaincal}} task. Finally you apply these solutions to the data and re-image. These steps are repeated until you are happy with your model or the solution interval is too short to reach the necessary signal-to-noise. In general, you start with phase-only self-calibration and only do amplitude calibration at the end of the self-calibration process if there are amplitude-based gain artifacts in the data (see the [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf Imaging and Deconvolution talk] from the Synthesis Imaging Summer School for more detail. Amplitude calibration should be used with caution because it has the potential to change the fluxes of sources in your data.<br />
<br />
Self-calibration can either be performed with line or continuum data. Here we demonstrate how to do it with continuum data. The principle is the same for line data, except you form your image using the brightest line emission. For an example of self-calibration with line data, see the [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216#UV_Continuum_Subtraction_and_Setting_Up_for_Self-Calibration VLA high frequency spectral line tutorial for IRC+10216].<br />
<br />
----<br />
<br />
The first thing you should do when beginning self-calibration is to save the original flags in your data set. This step is necessary because when you apply the calibration to a data set it flags data that is not associated with a solution. Applying a bad calibration table to your data can result in the excessive flagging of your data. Saving your original flags allows you to restore the original state of your data easily.<br />
We also recommend you save your flags after each {{applycal}} command. This will allow you to go back to a given point in the self-cal process without starting from the beginning. See [[Self_Calibration_Template#Restart_Self-Calibration]] if you need to start over or go back a step in self-cal.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='before_selfcal',merge='replace')<br />
</source><br />
<br />
Now we can set up the parameters for the self calibration. Begin by setting the parameters for your ms and continuum image name. The ms '''calibrated_final_cont.ms''' was created in the previous part of this guide: '''[[Image_Continuum | Image the Continuum Template]]'''.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
If you run the self-calibration process more than once, you will need to remove any models that could be left in the measurement set. This can can be accomplished by using the {{delmod}} task as well as the {{clearcal}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,field=field,otf=True)<br />
# clearcal(vis=contvis)<br />
</source><br />
<br />
You should use the same reference antenna that was used during calibration. For pipeline reductions, this can be found in the stage '''hif_refant''' as the first antenna in the list for each execution. For manual reductions, the reference antenna will be stated near the top of *.ms.scriptForCalibration.py. If there are multiple executions, make sure to use an antenna that has good solutions and is present in all executions. The Analysis Utilities task [https://safe.nrao.edu/wiki/bin/view/ALMA/CommonAntennas au.commonAntennas] can help you find antennas that meet this criteria. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. Tasks such as {{plotants}} or {{listobs}}/{{vishead}} can also be used to find antennas in all executions. <br />
<br />
<source lang="python"><br />
# in CASA<br />
refant = 'DV09' # pick a reference antenna.<br />
</source><br />
<br />
In the example below, we combine the signal from all spectral windows to improve the signal-to-noise for our gain solution. When combining the spectral windows, you need to map the solution from the combined spectral window (0) to the individual spectral windows using the spwmap parameter. This parameter is a list where the index of the element in the list indicates the spectral window and the value for that index the window that it is mapped to. For example, if we have three spectral windows in the original data set and use combine='spw' for our gain solution, we set spwmap=[0,0,0] to map spw=0 to spw=0, spw=1 to spw=0, and spw=2 to spw=0.<br />
<br />
<source lang="python"><br />
# in CASA<br />
spwmap = [0,0,0] # mapping self-calibration solutions to individual spectral windows. Generally an array of n zeroes, where n is the number of spectral windows in the data sets.<br />
</source><br />
<br />
You then begin the process of shallowly cleaning your continuum data to create an initial model for your data in the model column of your data set. Usually you only should do at most a few hundred iterations on the brightest source(s) in the field.<br />
<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shallow clean on the continuum<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p0'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p0',<br />
field=field,<br />
#phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
<br />
Next you take that model and use it to determine the per-antenna phase solutions as a function of time using {{gaincal}}. We use the {{rmtables}} command here to completely eradicate any previous solution table from CASA's memory. Note that we start here with a fairly long solution interval that is the length of a scan (solint='inf').<br />
<br />
<source lang="python"><br />
# in CASA<br />
# per scan solution<br />
rmtables('pcal1')<br />
gaincal(vis=contvis,<br />
caltable='pcal1',<br />
field=field,<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6)<br />
</source><br />
<br />
Inspect the logging messages output by {{gaincal}} to see how many solutions were expected/attempted/succeeded. If you have a large number of failed solutions, do not proceed further! This usually means that you do not have enough signal-to-noise on your source to proceed with self-calibration. Note that if you apply a calibration table with many failed solutions to the data, it will flag the data associated with these solutions. You may try changing the minsnr and minblperant parameters in the {{gaincal}} call above to find more solutions, but this option should be used with caution because these parameters are already low. This is especially relevant for 7-meter datasets, where achieving 6 baselines per antenna may be difficult. If you choose to modify these parameters, make sure to examine the results in detail.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Calibration solve statistics per spw: (expected/attempted/succeeded):<br />
Spw 0: 235/235/235<br />
Spw 1: 235/235/235<br />
Spw 2: 235/235/235<br />
</pre><br />
<figure id="Plotcal_image.png"><br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
</figure><br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal}}. The solutions should vary smoothly with time and there should not be any large outliers. The<br />
reference antenna’s phases should be flat in time. The reference antenna’s phases should be flat in time. <br />
<br />
<source lang="python"><br />
# in CASA<br />
# Check the solution<br />
plotcal(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
If you are satisfied with the solutions, apply them to the ms. Note: this step usually takes a while, so go ahead and get a cup of coffee.<br />
<figure id="Pcal1.png"><br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# in CASA<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
field=field,<br />
spwmap=spwmap,<br />
gaintable=['pcal1'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
</source><br />
<br />
Save the flags in case you need to go back to this step.<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal1')<br />
</source><br />
<br />
Using our new gain solutions, we can generate an improved model for our source using {{tclean}}. During this second tclean iteration, you should clean a bit deeper than previously, but not all the way down to the noise. Remember the goal here is to build up a good model for your source, so you don't want to include things that are not real emission.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p1'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p1',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in the viewer to assess how well self-calibration worked. In general, the noise should be lower and the signal-to-noise ratio higher than in the original image and there should be no major new artifacts in the image. If the signal-to-noise ratio does not increase, you may not have enough signal-to-noise on your target to run self-calibration. If you don't see an improvement in the image, you may wish to try a new reference antenna by first clearing the calibration with clearcal (see commands above). If this still does not help improve the selfcal images you may proceed to [[Image_Line#Continuum_Subtraction_for_Line_Emission | continuum subtraction]] (if you are working on a line project).<br />
<br />
If the image has improved you can proceed with the self-cal and generate a new gain solution table. The next {{gaincal}} call uses a shorter solution interval (solint) to generate solutions on a shorter time interval. Note that we always want to generate our model based on the latest gaincal solutions. The calibration tables, however, should be generated by comparing the original visibilities to the model. This prevents bad solutions from propagating through different iterations of self-calibration.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shorter solution<br />
rmtables('pcal2')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal2',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='30.25s', # solint=30.25s gets you five 12m integrations, while solint=50.5s gets you five 7m integration<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal2'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal2')<br />
</source><br />
<br />
<br />
Now we can repeat the {{tclean}}/{{gaincal}}/{{applycal}} process until we start seeing many failed solutions and only small improvements to the data. Remember to clean a bit deeper each time to improve your model and be cautious about what emission you are including in your tclean mask. You should also decrease the solution interval each time to better model the gain variations with time. Note that it generally only take 3-4 rounds of phase self-calibration to produce a good solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p2'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p2',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
<br />
# shorter solution<br />
rmtables('pcal3')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal3',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='int',<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal3'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal3')<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p3'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p3',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic or imaging an ephemeris object<br />
# mosweight = True, # uncomment if mosaic<br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
#pbcor = True, #if final image<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
</source><br />
<figure id="Imaging-tutorial-selfcal-3.png"><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
</figure><br />
<figure id="Apcal.png"><br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<br />
</figure><br />
<br />
The next section performs an amplitude calibration. This is an optional part of self-calibration. If you are happy with the results of your phase calibration, you can stop here. However, if you see amplitude-based artifacts, you can attempt to improve the situation using amplitude self-calibration. Since amplitude solutions are inherently less constrained than phase solutions, we use a longer solution interval only here. If you have a complex source with lots of extended emission, you may set a uvrange limit on the data to avoid downweighting the large scale emission <br />
<br />
While the phase calibration involved iterating with different solution intervals, the amplitude self-calibration will only use an infinite solution interval.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables('apcal')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='apcal',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='ap',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6,<br />
# uvrange='>50m', # may need to use to exclude extended emission<br />
gaintable='pcal3',<br />
spwmap=spwmap,<br />
solnorm=True)<br />
<br />
plotcal(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,0.2,1.8])<br />
<br />
applycal(vis=contvis,<br />
spwmap=[spwmap,spwmap], # select which spws to apply the solutions for each table<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_apcal')<br />
<br />
# Make amplitude and phase self-calibrated image.<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_ap'+ ext)<br />
<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_ap',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Compare the final image to the initial image and see if the image dynamic range (ratio betwen peak flux and rms noise) has improved and phase- and amplitude-based errors have improved.<br />
<br />
Finally, you should split out the results of your self-calibration for safe-keeping. <br />
<br />
<source lang="python"><br />
# in CASA<br />
split(vis=contvis,<br />
outputvis=contvis+'.selfcal', datacolumn='corrected')<br />
</source><br />
<br />
== Restart Self-Calibration ==<br />
<br />
If you would like to revert to a certain point in the self-cal process, use the following commands to do so.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to a given point in the iterative process (here after pcal2 has been applied)<br />
# flagmanager(vis=contvis, mode='restore',versionname='after_pcal2')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
Then return to the {{applycal}} step that applied the desired calibration table. In the example code above, you would return to where the table pcal2 was applied. <br />
<br />
If you are unhappy with the self-calibration, use the {{clearcal}} and {{delmod}} tasks and restore the original flags to return your ms to it’s original pre-self-cal state.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to pre self-cal ms<br />
# flagmanager(vis=contvis, mode='restore',versionname='before_selfcal')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
<br />
If you have line data, you will subtract the continuum and apply the self-calibration results to the line data on the next page, '''[[Image_Line | Spectral Line Imaging Template]]'''.<br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=25751Self-Calibration Template CASA 6.1.12018-11-26T16:20:07Z<p>Jthorley: </p>
<hr />
<div>This guide continues with products created in '''[[Image_Continuum | Image the Continuum Template]]'''. All imaging parameters are set in the previous guide. You will need '''calibrated_final_cont.ms''' to proceed.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Self-Calibration on the Continuum (optional) ==<br />
<br />
If you have a high signal-to-noise detection of your source, you can use the source itself to calibrate the phases and potentially the amplitudes of the visibilities as a function of time. This technique is called self-calibration and takes advantage of the fact that interferometer data is over-constrained (we have more equations than we have solutions). The recommended signal to noise depends on the number of antennas. For an array of 40 antennas, you should have a Peak/RMS of at least 45 in your continuum image to attempt self-calibration. You can use the following relationship to find the minimum Peak/RMS for your dataset.<br />
<br />
<math><br />
\frac{Peak}{RMS} > 3 \sqrt{N-3} \sqrt{\frac{t_{int}}{t_{solint}}}<br />
</math><br />
<br />
<br />
where:<br />
<br />
''Peak'' is the maximum value in the continuum image.<br />
<br />
''RMS'' is the RMS of the non-self-calibrated continuum image.<br />
<br />
''N'' is the number of antennas.<br />
<br />
''t<sub>int</sub>'' is the total on source integration time.<br />
<br />
''t<sub>solint</sub>'' is the solution interval used to calculate the corrections. In this case, use the scan length.<br />
<br />
See the NRAO Live! presentation [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-wm16/Selfcal_Madison.pdf When, why, and how to do self-calibration] for more information on this relationship.<br />
<br />
Self-calibration is an iterative process. You start by generating a model of your source using {{tclean}}. Then you use this model to determine the gains as a function of time using the {{gaincal}} task. Finally you apply these solutions to the data and re-image. These steps are repeated until you are happy with your model or the solution interval is too short to reach the necessary signal-to-noise. In general, you start with phase-only self-calibration and only do amplitude calibration at the end of the self-calibration process if there are amplitude-based gain artifacts in the data (see the [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf Imaging and Deconvolution talk] from the Synthesis Imaging Summer School for more detail. Amplitude calibration should be used with caution because it has the potential to change the fluxes of sources in your data.<br />
<br />
Self-calibration can either be performed with line or continuum data. Here we demonstrate how to do it with continuum data. The principle is the same for line data, except you form your image using the brightest line emission. For an example of self-calibration with line data, see the [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216#UV_Continuum_Subtraction_and_Setting_Up_for_Self-Calibration VLA high frequency spectral line tutorial for IRC+10216].<br />
<br />
----<br />
<br />
The first thing you should do when beginning self-calibration is to save the original flags in your data set. This step is necessary because when you apply the calibration to a data set it flags data that is not associated with a solution. Applying a bad calibration table to your data can result in the excessive flagging of your data. Saving your original flags allows you to restore the original state of your data easily.<br />
We also recommend you save your flags after each {{applycal}} command. This will allow you to go back to a given point in the self-cal process without starting from the beginning. See [[Self_Calibration_Template#Restart_Self-Calibration]] if you need to start over or go back a step in self-cal.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='before_selfcal',merge='replace')<br />
</source><br />
<br />
Now we can set up the parameters for the self calibration. Begin by setting the parameters for your ms and continuum image name. The ms '''calibrated_final_cont.ms''' was created in the previous part of this guide: '''[[Image_Continuum | Image the Continuum Template]]'''.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
If you run the self-calibration process more than once, you will need to remove any models that could be left in the measurement set. This can can be accomplished by using the {{delmod}} task as well as the {{clearcal}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,field=field,otf=True)<br />
# clearcal(vis=contvis)<br />
</source><br />
<br />
You should use the same reference antenna that was used during calibration. For pipeline reductions, this can be found in the stage '''hif_refant''' as the first antenna in the list for each execution. For manual reductions, the reference antenna will be stated near the top of *.ms.scriptForCalibration.py. If there are multiple executions, make sure to use an antenna that has good solutions and is present in all executions. The Analysis Utilities task [https://safe.nrao.edu/wiki/bin/view/ALMA/CommonAntennas au.commonAntennas] can help you find antennas that meet this criteria. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. Tasks such as {{plotants}} or {{listobs}}/{{vishead}} can also be used to find antennas in all executions. <br />
<br />
<source lang="python"><br />
# in CASA<br />
refant = 'DV09' # pick a reference antenna.<br />
</source><br />
<br />
In the example below, we combine the signal from all spectral windows to improve the signal-to-noise for our gain solution. When combining the spectral windows, you need to map the solution from the combined spectral window (0) to the individual spectral windows using the spwmap parameter. This parameter is a list where the index of the element in the list indicates the spectral window and the value for that index the window that it is mapped to. For example, if we have three spectral windows in the original data set and use combine='spw' for our gain solution, we set spwmap=[0,0,0] to map spw=0 to spw=0, spw=1 to spw=0, and spw=2 to spw=0.<br />
<br />
<source lang="python"><br />
# in CASA<br />
spwmap = [0,0,0] # mapping self-calibration solutions to individual spectral windows. Generally an array of n zeroes, where n is the number of spectral windows in the data sets.<br />
</source><br />
<br />
You then begin the process of shallowly cleaning your continuum data to create an initial model for your data in the model column of your data set. Usually you only should do at most a few hundred iterations on the brightest source(s) in the field.<br />
<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shallow clean on the continuum<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p0'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p0',<br />
field=field,<br />
#phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
<br />
Next you take that model and use it to determine the per-antenna phase solutions as a function of time using {{gaincal}}. We use the {{rmtables}} command here to completely eradicate any previous solution table from CASA's memory. Note that we start here with a fairly long solution interval that is the length of a scan (solint='inf').<br />
<br />
<source lang="python"><br />
# in CASA<br />
# per scan solution<br />
rmtables('pcal1')<br />
gaincal(vis=contvis,<br />
caltable='pcal1',<br />
field=field,<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6)<br />
</source><br />
<br />
Inspect the logging messages output by {{gaincal}} to see how many solutions were expected/attempted/succeeded. If you have a large number of failed solutions, do not proceed further! This usually means that you do not have enough signal-to-noise on your source to proceed with self-calibration. Note that if you apply a calibration table with many failed solutions to the data, it will flag the data associated with these solutions. You may try changing the minsnr and minblperant parameters in the {{gaincal}} call above to find more solutions, but this option should be used with caution because these parameters are already low. This is especially relevant for 7-meter datasets, where achieving 6 baselines per antenna may be difficult. If you choose to modify these parameters, make sure to examine the results in detail.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Calibration solve statistics per spw: (expected/attempted/succeeded):<br />
Spw 0: 235/235/235<br />
Spw 1: 235/235/235<br />
Spw 2: 235/235/235<br />
</pre><br />
<figure id="Plotcal_image.png"><br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
</figure><br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal}}. The solutions should vary smoothly with time and there should not be any large outliers. The<br />
reference antenna’s phases should be flat in time. The reference antenna’s phases should be flat in time. <br />
<br />
<source lang="python"><br />
# in CASA<br />
# Check the solution<br />
plotcal(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
If you are satisfied with the solutions, apply them to the ms. Note: this step usually takes a while, so go ahead and get a cup of coffee.<br />
<figure id="Pcal1.png"><br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# in CASA<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
field=field,<br />
spwmap=spwmap,<br />
gaintable=['pcal1'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
</source><br />
<br />
Save the flags in case you need to go back to this step.<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal1')<br />
</source><br />
<br />
Using our new gain solutions, we can generate an improved model for our source using {{tclean}}. During this second tclean iteration, you should clean a bit deeper than previously, but not all the way down to the noise. Remember the goal here is to build up a good model for your source, so you don't want to include things that are not real emission.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p1'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p1',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in the viewer to assess how well self-calibration worked. In general, the noise should be lower and the signal-to-noise ratio higher than in the original image and there should be no major new artifacts in the image. If the signal-to-noise ratio does not increase, you may not have enough signal-to-noise on your target to run self-calibration. If you don't see an improvement in the image, you may wish to try a new reference antenna by first clearing the calibration with clearcal (see commands above). If this still does not help improve the selfcal images you may proceed to [[Image_Line#Continuum_Subtraction_for_Line_Emission | continuum subtraction]] (if you are working on a line project).<br />
<br />
If the image has improved you can proceed with the self-cal and generate a new gain solution table. The next {{gaincal}} call uses a shorter solution interval (solint) to generate solutions on a shorter time interval. Note that we always want to generate our model based on the latest gaincal solutions. The calibration tables, however, should be generated by comparing the original visibilities to the model. This prevents bad solutions from propagating through different iterations of self-calibration.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shorter solution<br />
rmtables('pcal2')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal2',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='30.25s', # solint=30.25s gets you five 12m integrations, while solint=50.5s gets you five 7m integration<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal2'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal2')<br />
</source><br />
<br />
<br />
Now we can repeat the {{tclean}}/{{gaincal}}/{{applycal}} process until we start seeing many failed solutions and only small improvements to the data. Remember to clean a bit deeper each time to improve your model and be cautious about what emission you are including in your tclean mask. You should also decrease the solution interval each time to better model the gain variations with time. Note that it generally only take 3-4 rounds of phase self-calibration to produce a good solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p2'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p2',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
<br />
# shorter solution<br />
rmtables('pcal3')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal3',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='int',<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal3'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal3')<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p3'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p3',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
</source><br />
<figure id="Imaging-tutorial-selfcal-3.png"><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
</figure><br />
<figure id="Apcal.png"><br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<br />
</figure><br />
<br />
The next section performs an amplitude calibration. This is an optional part of self-calibration. If you are happy with the results of your phase calibration, you can stop here. However, if you see amplitude-based artifacts, you can attempt to improve the situation using amplitude self-calibration. Since amplitude solutions are inherently less constrained than phase solutions, we use a longer solution interval only here. If you have a complex source with lots of extended emission, you may set a uvrange limit on the data to avoid downweighting the large scale emission <br />
<br />
While the phase calibration involved iterating with different solution intervals, the amplitude self-calibration will only use an infinite solution interval.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables('apcal')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='apcal',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='ap',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6,<br />
# uvrange='>50m', # may need to use to exclude extended emission<br />
gaintable='pcal3',<br />
spwmap=spwmap,<br />
solnorm=True)<br />
<br />
plotcal(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,0.2,1.8])<br />
<br />
applycal(vis=contvis,<br />
spwmap=[spwmap,spwmap], # select which spws to apply the solutions for each table<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_apcal')<br />
<br />
# Make amplitude and phase self-calibrated image.<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_ap'+ ext)<br />
<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_ap',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Compare the final image to the initial image and see if the image dynamic range (ratio betwen peak flux and rms noise) has improved and phase- and amplitude-based errors have improved.<br />
<br />
Finally, you should split out the results of your self-calibration for safe-keeping. <br />
<br />
<source lang="python"><br />
# in CASA<br />
split(vis=contvis,<br />
outputvis=contvis+'.selfcal', datacolumn='corrected')<br />
</source><br />
<br />
== Restart Self-Calibration ==<br />
<br />
If you would like to revert to a certain point in the self-cal process, use the following commands to do so.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to a given point in the iterative process (here after pcal2 has been applied)<br />
# flagmanager(vis=contvis, mode='restore',versionname='after_pcal2')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
Then return to the {{applycal}} step that applied the desired calibration table. In the example code above, you would return to where the table pcal2 was applied. <br />
<br />
If you are unhappy with the self-calibration, use the {{clearcal}} and {{delmod}} tasks and restore the original flags to return your ms to it’s original pre-self-cal state.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to pre self-cal ms<br />
# flagmanager(vis=contvis, mode='restore',versionname='before_selfcal')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
<br />
If you have line data, you will subtract the continuum and apply the self-calibration results to the line data on the next page, '''[[Image_Line | Spectral Line Imaging Template]]'''.<br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=25750Self-Calibration Template CASA 6.1.12018-11-26T16:16:21Z<p>Jthorley: </p>
<hr />
<div>This guide continues with products created in '''[[Image_Continuum | Image the Continuum Template]]'''. All imaging parameters are set in the previous guide. You will need '''calibrated_final_cont.ms''' to proceed.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Self-Calibration on the Continuum (optional) ==<br />
<br />
If you have a high signal-to-noise detection of your source, you can use the source itself to calibrate the phases and potentially the amplitudes of the visibilities as a function of time. This technique is called self-calibration and takes advantage of the fact that interferometer data is over-constrained (we have more equations than we have solutions). The recommended signal to noise depends on the number of antennas. For an array of 40 antennas, you should have a Peak/RMS of at least 45 in your continuum image to attempt self-calibration. You can use the following relationship to find the minimum Peak/RMS for your dataset.<br />
<br />
<math><br />
\frac{Peak}{RMS} > 3 \sqrt{N-3} \sqrt{\frac{t_{int}}{t_{solint}}}<br />
</math><br />
<br />
<br />
where:<br />
<br />
''Peak'' is the maximum value in the continuum image.<br />
<br />
''RMS'' is the RMS of the non-self-calibrated continuum image.<br />
<br />
''N'' is the number of antennas.<br />
<br />
''t<sub>int</sub>'' is the total on source integration time.<br />
<br />
''t<sub>solint</sub>'' is the solution interval used to calculate the corrections. In this case, use the scan length.<br />
<br />
See the NRAO Live! presentation [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-wm16/Selfcal_Madison.pdf When, why, and how to do self-calibration] for more information on this relationship.<br />
<br />
Self-calibration is an iterative process. You start by generating a model of your source using {{tclean}}. Then you use this model to determine the gains as a function of time using the {{gaincal}} task. Finally you apply these solutions to the data and re-image. These steps are repeated until you are happy with your model or the solution interval is too short to reach the necessary signal-to-noise. In general, you start with phase-only self-calibration and only do amplitude calibration at the end of the self-calibration process if there are amplitude-based gain artifacts in the data (see the [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf Imaging and Deconvolution talk] from the Synthesis Imaging Summer School for more detail. Amplitude calibration should be used with caution because it has the potential to change the fluxes of sources in your data.<br />
<br />
Self-calibration can either be performed with line or continuum data. Here we demonstrate how to do it with continuum data. The principle is the same for line data, except you form your image using the brightest line emission. For an example of self-calibration with line data, see the [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216#UV_Continuum_Subtraction_and_Setting_Up_for_Self-Calibration VLA high frequency spectral line tutorial for IRC+10216].<br />
<br />
----<br />
<br />
The first thing you should do when beginning self-calibration is to save the original flags in your data set. This step is necessary because when you apply the calibration to a data set it flags data that is not associated with a solution. Applying a bad calibration table to your data can result in the excessive flagging of your data. Saving your original flags allows you to restore the original state of your data easily.<br />
We also recommend you save your flags after each {{applycal}} command. This will allow you to go back to a given point in the self-cal process without starting from the beginning. See [[Self_Calibration_Template#Restart_Self-Calibration]] if you need to start over or go back a step in self-cal.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='before_selfcal',merge='replace')<br />
</source><br />
<br />
Now we can set up the parameters for the self calibration. Begin by setting the parameters for your ms and continuum image name. The ms '''calibrated_final_cont.ms''' was created in the previous part of this guide: '''[[Image_Continuum | Image the Continuum Template]]'''.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
If you run the self-calibration process more than once, you will need to remove any models that could be left in the measurement set. This can can be accomplished by using the {{delmod}} task as well as the {{clearcal}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,field=field,otf=True)<br />
# clearcal(vis=contvis)<br />
</source><br />
<br />
You should use the same reference antenna that was used during calibration. For pipeline reductions, this can be found in the stage '''hif_refant''' as the first antenna in the list for each execution. For manual reductions, the reference antenna will be stated near the top of *.ms.scriptForCalibration.py. If there are multiple executions, make sure to use an antenna that has good solutions and is present in all executions. The Analysis Utilities task [https://safe.nrao.edu/wiki/bin/view/ALMA/CommonAntennas au.commonAntennas] can help you find antennas that meet this criteria. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. Tasks such as {{plotants}} or {{listobs}}/{{vishead}} can also be used to find antennas in all executions. <br />
<br />
<source lang="python"><br />
# in CASA<br />
refant = 'DV09' # pick a reference antenna.<br />
</source><br />
<br />
In the example below, we combine the signal from all spectral windows to improve the signal-to-noise for our gain solution. When combining the spectral windows, you need to map the solution from the combined spectral window (0) to the individual spectral windows using the spwmap parameter. This parameter is a list where the index of the element in the list indicates the spectral window and the value for that index the window that it is mapped to. For example, if we have three spectral windows in the original data set and use combine='spw' for our gain solution, we set spwmap=[0,0,0] to map spw=0 to spw=0, spw=1 to spw=0, and spw=2 to spw=0.<br />
<br />
<source lang="python"><br />
# in CASA<br />
spwmap = [0,0,0] # mapping self-calibration solutions to individual spectral windows. Generally an array of n zeroes, where n is the number of spectral windows in the data sets.<br />
</source><br />
<br />
You then begin the process of shallowly cleaning your continuum data to create an initial model for your data in the model column of your data set. Usually you only should do at most a few hundred iterations on the brightest source(s) in the field.<br />
<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shallow clean on the continuum<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p0'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p0',<br />
field=field,<br />
#phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
<br />
Next you take that model and use it to determine the per-antenna phase solutions as a function of time using {{gaincal}}. We use the {{rmtables}} command here to completely eradicate any previous solution table from CASA's memory. Note that we start here with a fairly long solution interval that is the length of a scan (solint='inf').<br />
<br />
<source lang="python"><br />
# in CASA<br />
# per scan solution<br />
rmtables('pcal1')<br />
gaincal(vis=contvis,<br />
caltable='pcal1',<br />
field=field,<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6)<br />
</source><br />
<br />
Inspect the logging messages output by {{gaincal}} to see how many solutions were expected/attempted/succeeded. If you have a large number of failed solutions, do not proceed further! This usually means that you do not have enough signal-to-noise on your source to proceed with self-calibration. Note that if you apply a calibration table with many failed solutions to the data, it will flag the data associated with these solutions. You may try changing the minsnr and minblperant parameters in the {{gaincal}} call above to find more solutions, but this option should be used with caution because these parameters are already low. This is especially relevant for 7-meter datasets, where achieving 6 baselines per antenna may be difficult. If you choose to modify these parameters, make sure to examine the results in detail.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Calibration solve statistics per spw: (expected/attempted/succeeded):<br />
Spw 0: 235/235/235<br />
Spw 1: 235/235/235<br />
Spw 2: 235/235/235<br />
</pre><br />
<figure id="Plotcal_image.png"><br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
</figure><br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal}}. The solutions should vary smoothly with time and there should not be any large outliers. The reference antenna’s phases should be flat in time. <br />
<br />
<source lang="python"><br />
# in CASA<br />
# Check the solution<br />
plotcal(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
If you are satisfied with the solutions, apply them to the ms. Note: this step usually takes a while, so go ahead and get a cup of coffee.<br />
<figure id="Pcal1.png"><br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# in CASA<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
field=field,<br />
spwmap=spwmap,<br />
gaintable=['pcal1'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
</source><br />
<br />
Save the flags in case you need to go back to this step.<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal1')<br />
</source><br />
<br />
Using our new gain solutions, we can generate an improved model for our source using {{tclean}}. During this second tclean iteration, you should clean a bit deeper than previously, but not all the way down to the noise. Remember the goal here is to build up a good model for your source, so you don't want to include things that are not real emission.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p1'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p1',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in the viewer to assess how well self-calibration worked. In general, the noise should be lower and the signal-to-noise ratio higher than in the original image and there should be no major new artifacts in the image. If the signal-to-noise ratio does not increase, you may not have enough signal-to-noise on your target to run self-calibration. If you don't see an improvement in the image, clear the calibration with clearcal (see commands above) and proceed to [[Image_Line#Continuum_Subtraction_for_Line_Emission | continuum subtraction]] (if you are working on a line project).<br />
<br />
If the image has improved you can proceed with the self-cal and generate a new gain solution table. The next {{gaincal}} call uses a shorter solution interval (solint) to generate solutions on a shorter time interval. Note that we always want to generate our model based on the latest gaincal solutions. The calibration tables, however, should be generated by comparing the original visibilities to the model. This prevents bad solutions from propagating through different iterations of self-calibration.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shorter solution<br />
rmtables('pcal2')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal2',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='30.25s', # solint=30.25s gets you five 12m integrations, while solint=50.5s gets you five 7m integration<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal2'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal2')<br />
</source><br />
<br />
<br />
Now we can repeat the {{tclean}}/{{gaincal}}/{{applycal}} process until we start seeing many failed solutions and only small improvements to the data. Remember to clean a bit deeper each time to improve your model and be cautious about what emission you are including in your tclean mask. You should also decrease the solution interval each time to better model the gain variations with time. Note that it generally only take 3-4 rounds of phase self-calibration to produce a good solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p2'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p2',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
<br />
# shorter solution<br />
rmtables('pcal3')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal3',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='int',<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal3'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal3')<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p3'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p3',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
</source><br />
<figure id="Imaging-tutorial-selfcal-3.png"><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
</figure><br />
<figure id="Apcal.png"><br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<br />
</figure><br />
<br />
The next section performs an amplitude calibration. This is an optional part of self-calibration. If you are happy with the results of your phase calibration, you can stop here. However, if you see amplitude-based artifacts, you can attempt to improve the situation using amplitude self-calibration. Since amplitude solutions are inherently less constrained than phase solutions, we use a longer solution interval only here. If you have a complex source with lots of extended emission, you may set a uvrange limit on the data to avoid downweighting the large scale emission <br />
<br />
While the phase calibration involved iterating with different solution intervals, the amplitude self-calibration will only use an infinite solution interval.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables('apcal')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='apcal',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='ap',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6,<br />
# uvrange='>50m', # may need to use to exclude extended emission<br />
gaintable='pcal3',<br />
spwmap=spwmap,<br />
solnorm=True)<br />
<br />
plotcal(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,0.2,1.8])<br />
<br />
applycal(vis=contvis,<br />
spwmap=[spwmap,spwmap], # select which spws to apply the solutions for each table<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_apcal')<br />
<br />
# Make amplitude and phase self-calibrated image.<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_ap'+ ext)<br />
<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_ap',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Compare the final image to the initial image and see if the image dynamic range (ratio betwen peak flux and rms noise) has improved and phase- and amplitude-based errors have improved.<br />
<br />
Finally, you should split out the results of your self-calibration for safe-keeping. <br />
<br />
<source lang="python"><br />
# in CASA<br />
split(vis=contvis,<br />
outputvis=contvis+'.selfcal', datacolumn='corrected')<br />
</source><br />
<br />
== Restart Self-Calibration ==<br />
<br />
If you would like to revert to a certain point in the self-cal process, use the following commands to do so.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to a given point in the iterative process (here after pcal2 has been applied)<br />
# flagmanager(vis=contvis, mode='restore',versionname='after_pcal2')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
Then return to the {{applycal}} step that applied the desired calibration table. In the example code above, you would return to where the table pcal2 was applied. <br />
<br />
If you are unhappy with the self-calibration, use the {{clearcal}} and {{delmod}} tasks and restore the original flags to return your ms to it’s original pre-self-cal state.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to pre self-cal ms<br />
# flagmanager(vis=contvis, mode='restore',versionname='before_selfcal')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
<br />
If you have line data, you will subtract the continuum and apply the self-calibration results to the line data on the next page, '''[[Image_Line | Spectral Line Imaging Template]]'''.<br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Self-Calibration_Template_CASA_6.1.1&diff=25749Self-Calibration Template CASA 6.1.12018-11-26T16:04:41Z<p>Jthorley: </p>
<hr />
<div>This guide continues with products created in '''[[Image_Continuum | Image the Continuum Template]]'''. All imaging parameters are set in the previous guide. You will need '''calibrated_final_cont.ms''' to proceed.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Self-Calibration on the Continuum (optional) ==<br />
<br />
If you have a high signal-to-noise detection of your source, you can use the source itself to calibrate the phases and potentially the amplitudes of the visibilities as a function of time. This technique is called self-calibration and takes advantage of the fact that interferometer data is over-constrained (we have more equations than we have solutions). The recommended signal to noise depends on the number of antennas. For an array of 40 antennas, you should have a Peak/RMS of at least 45 in your continuum image to attempt self-calibration. You can use the following relationship to find the minimum Peak/RMS for your dataset.<br />
<br />
<math><br />
\frac{Peak}{RMS} > 3 \sqrt{N-3} \sqrt{\frac{t_{int}}{t_{solint}}}<br />
</math><br />
<br />
<br />
where:<br />
<br />
''Peak'' is the maximum value in the continuum image.<br />
<br />
''RMS'' is the RMS of the non-self-calibrated continuum image.<br />
<br />
''N'' is the number of antennas.<br />
<br />
''t<sub>int</sub>'' is the total on source integration time.<br />
<br />
''t<sub>solint</sub>'' is the solution interval used to calculate the corrections. In this case, use the scan length.<br />
<br />
See the NRAO Live! presentation [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-wm16/Selfcal_Madison.pdf When, why, and how to do self-calibration] for more information on this relationship.<br />
<br />
Self-calibration is an iterative process. You start by generating a model of your source using {{tclean}}. Then you use this model to determine the gains as a function of time using the {{gaincal}} task. Finally you apply these solutions to the data and re-image. These steps are repeated until you are happy with your model or the solution interval is too short to reach the necessary signal-to-noise. In general, you start with phase-only self-calibration and only do amplitude calibration at the end of the self-calibration process if there are amplitude-based gain artifacts in the data (see the [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf Imaging and Deconvolution talk] from the Synthesis Imaging Summer School for more detail. Amplitude calibration should be used with caution because it has the potential to change the fluxes of sources in your data.<br />
<br />
Self-calibration can either be performed with line or continuum data. Here we demonstrate how to do it with continuum data. The principle is the same for line data, except you form your image using the brightest line emission. For an example of self-calibration with line data, see the [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216#UV_Continuum_Subtraction_and_Setting_Up_for_Self-Calibration VLA high frequency spectral line tutorial for IRC+10216].<br />
<br />
----<br />
<br />
The first thing you should do when beginning self-calibration is to save the original flags in your data set. This step is necessary because when you apply the calibration to a data set it flags data that is not associated with a solution. Applying a bad calibration table to your data can result in the excessive flagging of your data. Saving your original flags allows you to restore the original state of your data easily.<br />
We also recommend you save your flags after each {{applycal}} command. This will allow you to go back to a given point in the self-cal process without starting from the beginning. See [[Self_Calibration_Template#Restart_Self-Calibration]] if you need to start over or go back a step in self-cal.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='before_selfcal',merge='replace')<br />
</source><br />
<br />
Now we can set up the parameters for the self calibration. Begin by setting the parameters for your ms and continuum image name. The ms '''calibrated_final_cont.ms''' was created in the previous part of this guide: '''[[Image_Continuum | Image the Continuum Template]]'''.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
If you run the self-calibration process more than once, you will need to remove any models that could be left in the measurement set. This can can be accomplished by using the {{delmod}} task as well as the {{clearcal}} task (which will need to be uncommented in the code below).<br />
<br />
<source lang="python"><br />
# in CASA<br />
# delmod(vis=contvis,field=field,otf=True)<br />
# clearcal(vis=contvis)<br />
</source><br />
<br />
You should use the same reference antenna that was used during calibration. For pipeline reductions, this can be found in the stage '''hif_refant'''. For manual reductions, the reference antenna will be stated near the top of *.ms.scriptForCalibration.py. If there are multiple executions, make sure to use an antenna that has good solutions and is present in all executions. The Analysis Utilities task [https://safe.nrao.edu/wiki/bin/view/ALMA/CommonAntennas au.commonAntennas] can help you find antennas that meet this criteria. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. Tasks such as {{plotants}} or {{listobs}}/{{vishead}} can also be used to find antennas in all executions. <br />
<br />
<source lang="python"><br />
# in CASA<br />
refant = 'DV09' # pick a reference antenna.<br />
</source><br />
<br />
In the example below, we combine the signal from all spectral windows to improve the signal-to-noise for our gain solution. When combining the spectral windows, you need to map the solution from the combined spectral window (0) to the individual spectral windows using the spwmap parameter. This parameter is a list where the index of the element in the list indicates the spectral window and the value for that index the window that it is mapped to. For example, if we have three spectral windows in the original data set and use combine='spw' for our gain solution, we set spwmap=[0,0,0] to map spw=0 to spw=0, spw=1 to spw=0, and spw=2 to spw=0.<br />
<br />
<source lang="python"><br />
# in CASA<br />
spwmap = [0,0,0] # mapping self-calibration solutions to individual spectral windows. Generally an array of n zeroes, where n is the number of spectral windows in the data sets.<br />
</source><br />
<br />
You then begin the process of shallowly cleaning your continuum data to create an initial model for your data in the model column of your data set. Usually you only should do at most a few hundred iterations on the brightest source(s) in the field.<br />
<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shallow clean on the continuum<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p0'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p0',<br />
field=field,<br />
#phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
<br />
</source><br />
<br />
<br />
Next you take that model and use it to determine the per-antenna phase solutions as a function of time using {{gaincal}}. We use the {{rmtables}} command here to completely eradicate any previous solution table from CASA's memory. Note that we start here with a fairly long solution interval that is the length of a scan (solint='inf').<br />
<br />
<source lang="python"><br />
# in CASA<br />
# per scan solution<br />
rmtables('pcal1')<br />
gaincal(vis=contvis,<br />
caltable='pcal1',<br />
field=field,<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6)<br />
</source><br />
<br />
Inspect the logging messages output by {{gaincal}} to see how many solutions were expected/attempted/succeeded. If you have a large number of failed solutions, do not proceed further! This usually means that you do not have enough signal-to-noise on your source to proceed with self-calibration. Note that if you apply a calibration table with many failed solutions to the data, it will flag the data associated with these solutions. You may try changing the minsnr and minblperant parameters in the {{gaincal}} call above to find more solutions, but this option should be used with caution because these parameters are already low. This is especially relevant for 7-meter datasets, where achieving 6 baselines per antenna may be difficult. If you choose to modify these parameters, make sure to examine the results in detail.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Calibration solve statistics per spw: (expected/attempted/succeeded):<br />
Spw 0: 235/235/235<br />
Spw 1: 235/235/235<br />
Spw 2: 235/235/235<br />
</pre><br />
<figure id="Plotcal_image.png"><br />
[[File:Plotcal_image.png|thumb|Figure 1: Solutions from the first round of self-cal.]]<br />
</figure><br />
<br />
You should also check the solutions (above) that were obtained using {{plotcal}}. The solutions should vary smoothly with time and there should not be any large outliers.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Check the solution<br />
plotcal(caltable='pcal1',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
</source><br />
<br />
If you are satisfied with the solutions, apply them to the ms. Note: this step usually takes a while, so go ahead and get a cup of coffee.<br />
<figure id="Pcal1.png"><br />
[[File:Pcal1.png|thumb|Figure 2: Continuum image after the first round of self-cal.]]<br />
</figure><br />
<br />
<source lang="python"><br />
# in CASA<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
field=field,<br />
spwmap=spwmap,<br />
gaintable=['pcal1'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
</source><br />
<br />
Save the flags in case you need to go back to this step.<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal1')<br />
</source><br />
<br />
Using our new gain solutions, we can generate an improved model for our source using {{tclean}}. During this second tclean iteration, you should clean a bit deeper than previously, but not all the way down to the noise. Remember the goal here is to build up a good model for your source, so you don't want to include things that are not real emission.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p1'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p1',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
</source><br />
<br />
You should inspect the new image in the viewer to assess how well self-calibration worked. In general, the noise should be lower and the signal-to-noise ratio higher than in the original image and there should be no major new artifacts in the image. If the signal-to-noise ratio does not increase, you may not have enough signal-to-noise on your target to run self-calibration. If you don't see an improvement in the image, clear the calibration with clearcal (see commands above) and proceed to [[Image_Line#Continuum_Subtraction_for_Line_Emission | continuum subtraction]] (if you are working on a line project).<br />
<br />
If the image has improved you can proceed with the self-cal and generate a new gain solution table. The next {{gaincal}} call uses a shorter solution interval (solint) to generate solutions on a shorter time interval. Note that we always want to generate our model based on the latest gaincal solutions. The calibration tables, however, should be generated by comparing the original visibilities to the model. This prevents bad solutions from propagating through different iterations of self-calibration.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# shorter solution<br />
rmtables('pcal2')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal2',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='30.25s', # solint=30.25s gets you five 12m integrations, while solint=50.5s gets you five 7m integration<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal2',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal2'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal2')<br />
</source><br />
<br />
<br />
Now we can repeat the {{tclean}}/{{gaincal}}/{{applycal}} process until we start seeing many failed solutions and only small improvements to the data. Remember to clean a bit deeper each time to improve your model and be cautious about what emission you are including in your tclean mask. You should also decrease the solution interval each time to better model the gain variations with time. Note that it generally only take 3-4 rounds of phase self-calibration to produce a good solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# clean deeper<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p2'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p2',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
# Note number of iterations performed.<br />
<br />
# shorter solution<br />
rmtables('pcal3')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='pcal3',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='p',<br />
combine='spw',<br />
solint='int',<br />
minsnr=3.0,<br />
minblperant=6)<br />
<br />
# Check the solution<br />
plotcal(caltable='pcal3',<br />
xaxis='time',<br />
yaxis='phase',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,-180,180])<br />
<br />
# apply the calibration to the data for next round of imaging<br />
applycal(vis=contvis,<br />
spwmap=spwmap,<br />
field=field,<br />
gaintable=['pcal3'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_pcal3')<br />
<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_p3'+ ext)<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_p3',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
<br />
# Note number of iterations performed.<br />
</source><br />
<figure id="Imaging-tutorial-selfcal-3.png"><br />
[[File:Imaging-tutorial-selfcal-3.png|thumb|Figure 3: Amplitude based residuals after phase self-cal.]]<br />
</figure><br />
<figure id="Apcal.png"><br />
[[File:Apcal.png|thumb|Figure 4: Image after amplitude self-cal.]]<br />
</figure><br />
<br />
The next section performs an amplitude calibration. This is an optional part of self-calibration. If you are happy with the results of your phase calibration, you can stop here. However, if you see amplitude-based artifacts, you can attempt to improve the situation using amplitude self-calibration. Since amplitude solutions are inherently less constrained than phase solutions, we use a longer solution interval only here. If you have a complex source with lots of extended emission, you may set a uvrange limit on the data to avoid downweighting the large scale emission <br />
<br />
While the phase calibration involved iterating with different solution intervals, the amplitude self-calibration will only use an infinite solution interval.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables('apcal')<br />
gaincal(vis=contvis,<br />
field=field,<br />
caltable='apcal',<br />
gaintype='T',<br />
refant=refant,<br />
calmode='ap',<br />
combine='spw',<br />
solint='inf',<br />
minsnr=3.0,<br />
minblperant=6,<br />
# uvrange='>50m', # may need to use to exclude extended emission<br />
gaintable='pcal3',<br />
spwmap=spwmap,<br />
solnorm=True)<br />
<br />
plotcal(caltable='apcal',<br />
xaxis='time',<br />
yaxis='amp',<br />
timerange='',<br />
iteration='antenna',<br />
subplot=421,<br />
plotrange=[0,0,0.2,1.8])<br />
<br />
applycal(vis=contvis,<br />
spwmap=[spwmap,spwmap], # select which spws to apply the solutions for each table<br />
field=field,<br />
gaintable=['pcal3','apcal'],<br />
gainfield='',<br />
calwt=False,<br />
flagbackup=False,<br />
interp='linearperobs')<br />
<br />
flagmanager(vis=contvis,mode='save',versionname='after_apcal')<br />
<br />
# Make amplitude and phase self-calibrated image.<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename + '_ap'+ ext)<br />
<br />
<br />
tclean(vis=contvis,<br />
imagename=contimagename + '_ap',<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom',<br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting, <br />
robust=robust,<br />
niter=niter, <br />
threshold=threshold, <br />
interactive=True,<br />
gridder=gridder,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Compare the final image to the initial image and see if the image dynamic range (ratio betwen peak flux and rms noise) has improved and phase- and amplitude-based errors have improved.<br />
<br />
Finally, you should split out the results of your self-calibration for safe-keeping. <br />
<br />
<source lang="python"><br />
# in CASA<br />
split(vis=contvis,<br />
outputvis=contvis+'.selfcal', datacolumn='corrected')<br />
</source><br />
<br />
== Restart Self-Calibration ==<br />
<br />
If you would like to revert to a certain point in the self-cal process, use the following commands to do so.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to a given point in the iterative process (here after pcal2 has been applied)<br />
# flagmanager(vis=contvis, mode='restore',versionname='after_pcal2')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
Then return to the {{applycal}} step that applied the desired calibration table. In the example code above, you would return to where the table pcal2 was applied. <br />
<br />
If you are unhappy with the self-calibration, use the {{clearcal}} and {{delmod}} tasks and restore the original flags to return your ms to it’s original pre-self-cal state.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment the following to revert to pre self-cal ms<br />
# flagmanager(vis=contvis, mode='restore',versionname='before_selfcal')<br />
# clearcal(contvis)<br />
# delmod(contvis,field=field,otf=True)<br />
</source><br />
<br />
If you have line data, you will subtract the continuum and apply the self-calibration results to the line data on the next page, '''[[Image_Line | Spectral Line Imaging Template]]'''.<br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25748Image Continuum CASA 6.1.12018-11-26T15:59:40Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 <br />
# and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25747Image Continuum CASA 6.1.12018-11-26T15:52:15Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning automaticly.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25746Image Continuum CASA 6.1.12018-11-26T15:51:19Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the automasking guide [https://casaguides.nrao.edu/index.php/Automasking_Guide Automasking Guide] useful in allowing {{tclean}} to generate the mask used for cleaning.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25745Image Continuum CASA 6.1.12018-11-26T15:50:10Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. You may also find the automasking guide [https://casaguides.nrao.edu/index.php/Automasking_Guide] useful in allowing {{tclean}} to generate the mask used for cleaning.<br />
<br />
We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25744Image Continuum CASA 6.1.12018-11-26T15:48:00Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. In Figure 7 you will see a mosaic field under padded with the edges not visible. Figure 8 shows an image made with a larger imsize of the same mosaic with the edges clearly visible.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as you have likely already regridded to the source velocity in cvel() or can allow tclean to do it on the fly. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and clean the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25743Image Continuum CASA 6.1.12018-11-26T15:45:53Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Bands 7, 8, 9 and 10: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split(vis=finalvis,<br />
spw=contspws, <br />
outputvis=contvis,<br />
width=[256,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Bands 7, 8, 9 and 10.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. See figures 7 and 8 for an example.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and {{tclean}} the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25742Image Continuum CASA 6.1.12018-11-26T15:43:20Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of a spw with and without lines to flag. Figure one shows a clear line at channel 1700 whereas Figure two shows no line emission and just continuum.<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights.<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Band 7: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split2(vis=finalvis,<br />
spw=contspws,<br />
outputvis=contvis,<br />
width=[8,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Band 7.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. See figures 7 and 8 for an example.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and {{tclean}} the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25741Image Continuum CASA 6.1.12018-11-26T15:40:11Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of an spw without a line to flag (Figure 2) and a line which you would need to flag (Figure 1).<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Band 7: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split2(vis=finalvis,<br />
spw=contspws,<br />
outputvis=contvis,<br />
width=[8,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Band 7.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. See figures 7 and 8 for an example.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and {{tclean}} the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Image_Continuum_CASA_6.1.1&diff=25740Image Continuum CASA 6.1.12018-11-26T15:39:42Z<p>Jthorley: </p>
<hr />
<div>This guide should be used after completing '''[[Imaging_Prep | Prepare the data for Imaging]]'''. You should have created '''calibrated_final.ms''' prior to proceeding.<br />
Commands for this guide can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
== Check CASA version ==<br />
<br />
This template is for use in CASA versions 4.4 and greater. The following code checks the version of CASA and exits if it is less than 4.4.0. You can download the appropriate version of CASA from [https://casa.nrao.edu/casa_obtaining.shtml Obtaining CASA] . See [[Guide_NA_ImagingTemplate#Prepare for Imaging | Prepare for Imaging ]] section on the main page of this guide for more information.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import re<br />
import casadef<br />
<br />
if casadef.casa_version < '4.4.0' :<br />
sys.exit("Please use CASA version greater than or equal to 4.4.0 with this script")<br />
</source><br />
<br />
== Create an Averaged Continuum MS ==<br />
<br />
<figure id="Calibrated_final_Field0_Spw0.png"><br />
[[File:Calibrated_final_Field0_Spw0.png|thumb|Figure 1: spw 0]]<br />
</figure><br />
<figure id="Calibrated_final_Field0_Spw3.png"><br />
[[File:Calibrated_final_Field0_Spw3.png|thumb|Figure 2: Plots showing each spectral window for TW Hydra with channel vs amplitude. Spw 0 has a strong spectral line and spw 3 is a continuum only window.]]<br />
</figure><br />
<br />
Appropriate averaging of a measurement set can reduce overall data volume, making imaging faster with {{tclean}}. Since the continuum image is formed by essentially summing the entire bandwidth, we can spectrally average the input measurement set prior to imaging without significantly affecting the final imaging results. Below, we outline a procedure to create a spectrally averaged measurement set for continuum imaging. <br />
<br />
The first step is to identify which spectral windows (spws) you would like to include in the continuum. In general, you should include all spws with bandwidths greater than 250MHz to maximize the available continuum bandwidth. Once you have determined which spws you would like to use to form the continuum ms, set the contspw variable:<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Set spws to be used to form continuum<br />
contspws = '0,1,2,3'<br />
</source><br />
<br />
The next step is to identify and flag the spectral lines in all spectral windows that you will use to make the continuum image. You will split and average the data with the spectral lines flagged so that your final spectrally averaged continuum ms only contains continuum emission. Two methods commonly used to identical spectral line emission are: 1) a channel vs. amplitude plot of the visibilities and 2) a dirty image of the cube.<br />
<br />
To use the first method, create a channel vs. amplitude plot using plotms. An example command is given below. You may wish to change the averaging and the uvrange to identify extended emission. <br />
<br />
Figures 1 and 2 show example plots of an spw without a line to flag (Figure 2) and a line which you would need to flag (Figure 1).<br />
<br />
Warning: If you apply channel averaging greater than 1, the numbers displayed on the channel axis will represent the channel bin number, rather than the averaged channel.<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=finalvis, xaxis='channel', yaxis='amplitude',<br />
ydatacolumn='data',<br />
avgtime='1e8', avgscan=True, avgchannel='1',<br />
iteraxis='spw' )<br />
</source><br />
<br />
The second, and more accurate, method is to use {{tclean}} to make a quick dirty image cube of channels with niter set to zero and mode=’channel’. Inspecting this channel cube for line emission gives a better defined channel range to flag. The basic command to create dirty image cubes is given below. If you are going to use this method, you will need to set the [[Image_Continuum#Image_Parameters | imaging parameters]] before running the {{tclean}} command. This command should be repeated for each spw and science field. <br />
<br />
<source lang="python"><br />
#In CASA <br />
<br />
testimagename=’testImage’<br />
field=[‘0’] #list all target fields<br />
spw=[‘0,1,2,3’] #list all target spw’s<br />
<br />
for i in field:<br />
for j in spw: <br />
tclean(vis=finalvis,<br />
imagename=testimagename+’Field_’+str(i)+’_spw_’+str(j), <br />
field=str(i),<br />
spw=str(j),<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='cube',<br />
veltype=veltype,<br />
nchan=-1,<br />
outframe='REST', <br />
niter=0,<br />
interactive=True,<br />
cell=cell,<br />
imsize=imsize, <br />
weighting=weighting, <br />
robust=robust,<br />
pbcor=True,<br />
restoringbeam='common',<br />
gridder=gridder)<br />
</source><br />
<br />
<br />
<figure id="Wt_vs_Freq_spw0123.png"><br />
[[File:Wt_vs_Freq_spw0123.png|thumb|Figure 3: The weight spectrum vs Frequency for the calibrated_final.ms for each science spectral window. Notice how the weights in each individual spectral window do not vary wildly and have no outliers but the overall weight measure is different for each spectral window due to the different observing frequency.]]<br />
</figure><br />
<br />
The first step to flagging the spectral line channels in your data is to use the {{flagmanager}} task to save the state of the data before any flagging is applied. You will need to revert back to the non spectral line flagged dataset when line imaging is done later on. In addition, if you accidentally flag any data you can easily correct this by restoring the before_cont_flags file using the {{flagmanager}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis=finalvis,mode='save',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
Initialize the per-channel (or spectral) weights in the ms using [https://casa.nrao.edu/docs/TaskRef/initweights-task.html initweights]. This step ensures that when the flagged and unflagged channels are combined, the appropriate weighting is given to the final set of averaged channels. Figure 3 shows a representation of the weightspectrum vs. frequency plot you should see after initializing the spectral weights<br />
<br />
<source lang="python"><br />
# in CASA<br />
initweights(vis=finalvis,wtmode='weight',dowtsp=True)<br />
</source><br />
<br />
The exact spectral window and channel ranges to flag in the flagchannels variable needs to be specified. For example, if spws 2&3 have a line between channels 1201 and 2199 and spectral windows 0 and 1 are line-free the command would be:<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagchannels='2:1201~2199,3:1201~2199' # modify the channel range for your dataset<br />
</source><br />
<br />
<figure id="Calibrated_final_field0_spw0_LineChannelFlagged.png"><br />
[[File:Calibrated_final_field0_spw0_LineChannelFlagged.png|thumb|Figure 4: Amp vs channel for spectral window 0 for TW Hydra with the spectral line flagged out.]]<br />
</figure><br />
<br />
Next, use the task {{flagdata}} to apply these flags. After this is done, check that the flags were applied correctly by using plotms to inspect the flagged ms. Figure 4 shows an example of what you should expect to see.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis=finalvis,mode='manual',<br />
spw=flagchannels,flagbackup=False)<br />
<br />
# check that flags are as expected, NOTE must check reload on plotms<br />
# gui if its still open.<br />
plotms(vis=finalvis,yaxis='amp',xaxis='channel',<br />
avgchannel='1',avgtime='1e8',avgscan=True,iteraxis='spw')<br />
</source><br />
<br />
Now you can spectrally average the channels together to reduce the size of the continuum ms. The number of channels that you can average together is limited by what is referred to as "bandwidth smearing". When creating an interferometer image, we assume that the emission is essentially monochromatic. If you average large numbers of channels together, this is no longer an appropriate assumption and results in radial smearing in the image that increases in magnitude from the delay tracking center. For a detailed discussion, consult [http://adsabs.harvard.edu/abs/1999ASPC..180..371B Bridle and Schwab, 1999, Synthesis Imaging in Radio Astronomy II, 180, 371]. For a short derivation of the relevant quantities, see [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing]. Conservative values for averaging channels in various ALMA bands are suggested below. As a rough guide, the number of channels you can average together is:<br />
* Bands 3, 4, 5, and 6: 125MHz/ (Channel Width (MHz)) <br />
* Band 7: 250MHz/ (Channel Width (MHz))<br />
<br />
In general, you should make sure that the number of channels you are averaging together is an integer multiple of the original total number of channels. For example, if you have 128 channels and a channel width of 15.625 MHz in band 6, you can average together 8 channels at a time. The resulting ms will contain 16 final channels each with a channel width of 125MHz.<br />
<br />
If you want to be more careful, the following table will tell you the maximum bandwidth each averaged channel can be to avoid bandwidth smearing worse than about 1%. For example, at Band 7 (373 GHz) in a compact configuration (Bmax=500m) bandwidth smearing is relatively unimportant even for wide bandwidths (2.1 GHz), whereas for extended configurations (Bmax=10km) the maximum bandwidth at the same Band 7 should be of order 100 MHz or less. <br />
<br />
[[Image:Bandwidthsmearingtable.png|center|frame|1200px]] ''This table lists the maximum bandwidth allowed for a reduction in peak response to a point source over the field of view of 1% for a a square and Gaussian bandpass for various observing frequencies and baselines for different two bandpass types. See [https://safe.nrao.edu/wiki/pub/Main/RadioTutorial/BandwidthSmearing.pdf How to Calculate Bandwidth Smearing] for more information.''<br />
<br />
Finally, the task {{split}} is used to average the channels together to produce the spectrally averaged continuum data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis='calibrated_final_cont.ms'<br />
rmtables(contvis)<br />
os.system('rm -rf ' + contvis + '.flagversions')<br />
split2(vis=finalvis,<br />
spw=contspws,<br />
outputvis=contvis,<br />
width=[8,8,8,8], # number of channels to average together. The final channel width should be less than 125MHz in Bands 3, 4, and 6 and 250MHz in Band 7.<br />
datacolumn='data')<br />
</source><br />
<br />
Now you should check the weights of the new continuum measurement set. The ratio of the weights value between Time Domain Mode (TDM) and Frequency Domain Mode (FDM) windows should be approximately equal to the ratio of the channel widths. For more information on the correlator modes TDM and FDM, see section 5.1 of the [https://almascience.nrao.edu/documents-and-tools/cycle5/alma-technical-handbook ALMA Technical Handbook].In addition, any heavily flagged channels should have their weights scaled by the ratio of the unflagged bandwidth to the bandwidth per output channel. For more information about data weights, see the [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] guide.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update the antenna and field parameters for your dataset<br />
plotms(vis=contvis, yaxis='wtsp',xaxis='freq',spw='',antenna='DA42',field='0') <br />
</source><br />
<br />
Finally, we need to use the {{flagmanager}} tasks to restore the ms file to its original unflagged state, so that later we can do continuum subtraction and line imaging.<br />
<br />
<figure id="Amp_vs_uvdist.png"><br />
[[File:Amp_vs_uvdist.png|thumb|Figure 5: Amplitude vs UVDistance plot of the continuum, colored by spw.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
# If you flagged any line channels, restore the previous flags<br />
flagmanager(vis=finalvis,mode='restore',<br />
versionname='before_cont_flags')<br />
</source><br />
<br />
It is a good practice to inspect the final continuum ms to make sure that it is correct. In general, the distribution of amplitude vs. uv distance should be smooth. Recall this plot will be a horizontal line for a point source, while the short uv-distances will have higher amplitudes for a more extended object. <br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis=contvis,xaxis='uvdist',yaxis='amp',coloraxis='spw')<br />
</source><br />
<br />
== Image Parameters ==<br />
<br />
Before imaging, you should set a few key parameters that you will use throughout the rest of the script. <br />
<br />
Set the field id for the science target you are interested in imaging. You can use the listobs file generated during the imaging prep step to find this information. If you are imaging a mosaic then you will have to select all the fields. For example, field = ‘3~25’. You can also set the field variable to the name of the source, as long as it matches the name in the listobs file. Do not leave the field parameter blank. If you leave the field parameter blank, {{tclean}} will attempt to image all sources in the measurement set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# update for your ms<br />
field='0'<br />
</source><br />
<br />
Uncomment the gridder that is relevant to your dataset. Set the phase center by field id or coordinates if you are imaging a mosaic. Check the spatial setup in the weblog (for pipeline calibrations) or qa2 report (for manual calibrations) to find the phase center. You should choose the central field for the phase center in order to get the best results. <br />
<br />
If you are unsure which field to use for the phase center after looking at the weblog then you may use the following Analysis Utilities command: <br />
<br />
<source lang="python"><br />
au.pickCellSize(‘calibrated_final.ms',imsize=True). <br />
</source><br />
<br />
This will return a four element array with that contains the calculated cell size, the X axis number of pixels, the Y axis number of pixels, and the field number that is most centered in the mosaic. You may use this as the phase center field id in your script. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions.<br />
<br />
Another method of finding the central field number uses the Analysis Utilities [https://casaguides.nrao.edu/index.php/Plotmosaic plotmosaic] au.plotmosaic(‘calibrated_final.ms’). This method will produce a plot of all fields with their corresponding field numbers plotted on the sky. You can also set the phase center with the coordinates at the center of this plot.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# gridder='standard' # uncomment if single field <br />
# gridder='mosaic' # uncomment if mosaic or if combining one 7m and one 12m pointing.<br />
# phasecenter=3 # uncomment and set to field number for phase<br />
# center. Note lack of ''. Use the weblog to<br />
# determine which pointing to use. Remember that the<br />
# field ids for each pointing will be re-numbered<br />
# after your initial split. You can also specify the<br />
# phase center using coordinates, e.g.,<br />
# phasecenter='J2000 19h30m00 -40d00m00'<br />
</source><br />
<figure id="Calibrated_final_AmpVsUVWave.png"><br />
[[File:Calibrated_final_AmpVsUVWave.png|thumb|Figure 6: Amplitude versus UV wave for the calibrated_final.ms showing the maximum uv wave point for determining cell size.]]<br />
</figure><br />
<br />
Next, determine the cell (or pixel) size. To do this, you need to determine the approximate resolution of your observations. Then you divide the resolution in arcsec by 5 to 8 to adequately sample the PSF. The resolution of a particular interferometer observations can be estimated from the length of the longest baseline:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ (observed wavelength) / (length of longest baseline)<br />
</pre><br />
<br />
If the baseline is measured in wavelengths, this becomes<br />
<pre style="background-color: #E0FFFF;"><br />
resolution (radian) ~ 1.0 / (length of longest baseline in wavelengths)<br />
</pre><br />
<br />
To convert from radians to arcsec, we multiple by 206265.0 to obtain:<br />
<pre style="background-color: #E0FFFF;"><br />
resolution(arcsec) ~ 206265.0/(longest baseline in wavelengths) <br />
</pre><br />
<br />
To determine the longest baseline in wavelengths use plotms with xaxis=’uvwave’ and yaxis=’amp’ on your ms file. Figure 6 shows an example of this plot. It is generally better to oversample your beam than to undersample, particularly for observations with poor uv-coverage.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
cellsize(arc seconds) = resolution(arcsec)/7 <br />
</pre><br />
<br />
The next step is to determine the image size in pixels. There are two methods of doing this depending on if you are imaging one field or a mosaic.<br />
<br />
If this is a single field, the image size can usually be approximated to be the same size as the primary beam of the telescope. The ALMA 12m primary beam in arcsec scales as 6300 / nu[GHz] and the ALMA 7m primary beam in arcsec scales as 10608 / nu[GHz], where nu[GHz] is the sky frequency. However, if there is significant point source and/or extended emission beyond the edges of your initial images, you should increase the imsize to incorporate more emission.<br />
<br />
For mosaics, make the image substantially larger than the mosaic footprint. Use au.plotmosaic(finalvis) to find the mosaic footprint in arcseconds. Padding the imsize substantially avoids artifacts in the image. You should be able to see the edges of the outside fields being cut off in an appropriately padded image. See figures 7 and 8 for an example.<br />
<figure id="Antennae_Antennae_North.Cont.Dirty.image.png"><br />
[[File:Antennae_Antennae_North.Cont.Dirty.image.png|thumb|Figure 7]]<br />
</figure><br />
<figure id="Antennae_North.Cont.Dirty.smallIMSize.image.png"><br />
[[File:Antennae_North.Cont.Dirty.smallIMSize.image.png|thumb|Figure 8: A mosaic of Antennae showing under padding and correctly padded images. For the correctly padded image you can see the edges of the primary beam field whereas the under padded does not cut off.]]<br />
</figure><br />
Note that the imsize parameter is in PIXELS, not arcsec, so you will need to divide the image size in arcsec by the pixel size to determine a value for imsize.<br />
<br />
If you would like to check any of these calculations you may use the following command, [https://safe.nrao.edu/wiki/bin/view/ALMA/PickCellSize au.pickCellSize]('calibrated_final.ms', imsize=True), in CASA. If you haven't installed Analysis Utilities, see [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Obtaining Analysis Utilities] for instructions. This will return a four element array of the calculated cell size, the x axis imsize, the y axis imsize, and the central field id number.<br />
<br />
<source lang="python"><br />
# in CASA<br />
cell='1arcsec' # cell size for imaging.<br />
imsize = [128,128] # size of image in pixels.<br />
</source><br />
<br />
When imaging lines, you will need to set two specific velocity parameters called outframe and veltype. Outframe is the coordinate system used for the observation. If you have access to the original proposal, this can be found in the Observing Tool (OT) under field setup. A list of acceptable outframes that can be used in CASA can be found at https://help.almascience.org/index.php?/Knowledgebase/Article/View/86/0/what-are-the-frequency-reference-frames-in-casa. Note: heliocentric(hel) is deprecated in CASA. Use barycentric(bary) in this case. The most common choices are 'bary' and 'lsrk'. Usually 'bary' is used for sources where z>0.2 ('extragalactic") and 'lsrk is used for 'galactic' sources. For ephemeris objects, the outframe should be set to a blank string, for example outframe = <nowiki>''</nowiki>, as the you have likely already regridded to the source velocity. <br />
<br />
You will also have to set the veltype for the {{tclean}} command. This variable has only two options available, radio and optical. Due to an interaction between the ALMA Observing Tool and CASA, set the veltype to radio. Even if the object has an optically defined velocity, the sensitivity calculation uses the radio definition. This will avoid confusion in comparing the achieved sensitivity to the expected sensitivity. <br />
<br />
<source lang="python"><br />
# in CASA<br />
outframe='bary' # velocity reference frame. See science goals.<br />
veltype='radio' # velocity type.<br />
</source><br />
<br />
The last four parameters that must be set are associated with how {{tclean}} will weight and {{tclean}} the data. During the imaging process, the individual visibilities are placed on a uv grid and then combined. Weighting determines how {{tclean}} will combine the uv gridded to produce an image. There are several weighting schemes that can be used:<br />
<br />
* Natural: Each cell in the uv plane is weighted by the number of points in the cell. This weighting scheme is the default in {{tclean}}. It results in a lower noise image at the expense of worse angular resolution.<br />
<br />
* Uniform: Each cell in the uv plane has the same weight. In this case, the sidelobes will be reduced because the imaging plane is filled in more uniformly. This weighting scheme also gives more weight to longer baselines resulting in higher resolution at the expense of higher noise. It can emphasize visibilities with calibration errors.<br />
<br />
* Briggs: This weighting scheme is a combination of natural and uniform weighting. The weighting is controlled by the robust parameter. A robust parameter of 2 gives natural weighting, -2 uniform weighting, and a number in between a combination of natural and uniform. Refer to [http://www.atnf.csiro.au/people/tim.cornwell/research/danthesis.pdf Brigg's Thesis] for more information. Currently, robust is set to 0.5, which gives a good compromise between natural and uniform weighting. You may find, after imaging, that you have to decrease the noise or angular resolution based on the science goals. Playing with the robust parameter can affect your final noise in the image and also the angular resolution. <br />
<br />
The parameters niter and threshold provide two ways to stop the {{tclean}} process. The niter parameter is the maximum number of iterations allowed. After this limit has been reached, {{tclean}} will terminate. The threshold parameter sets a flux density threshold for the {{tclean}}. When the peak residual is below this value, {{tclean}} terminates. When cleaning interactively, we recommend setting the niter parameter to a large(say 1000), but not too large value (say 10000 or 100000) so that {{tclean}} terminates eventually in the case of human error. The threshold can be left at the default of 0.0mJy for interactive tclean. For non-interactive tclean, the recommendation is to set the threshold to several times the noise in the final image. To determine the threshold for cube images, run tclean with niter set to zero and inspect the resulting image in the {{viewer}}. In a line-free channel, select a region and look at the statistics panel to determine the noise level. For more detailed instructions, see the “Image the Spectral Line Data” section of [https://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Imaging_Analysis_IRC%2B10216 EVLA Spectral Line Imaging Analysis IRC+10216].<br />
<br />
<source lang="python"><br />
# in CASA<br />
weighting = 'briggs'<br />
robust=0.5<br />
niter=1000<br />
threshold = '0.0mJy'<br />
</source><br />
<br />
For more information on the various options available in {{tclean}}, refer to [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/documents/wilner_vla16.pdf David Wilner’s Imaging and Deconvolution presentation] from the 2016 Synthesis Imaging Workshop. The table below provides helpful pointers to relevant slides.<br />
<br />
{| class="wikitable"<br />
|+Imaging Parameters<br />
|-<br />
|Pixel and Image Size<br />
|Slides 40-41<br />
|-<br />
|Weighting<br />
|Slides 42-48, 60-61<br />
|-<br />
|Deconvolution Algorithms<br />
|Slides 50-53, 62<br />
|}<br />
<br />
== Imaging the Continuum ==<br />
<br />
<figure id="Cont_before_clean.png"><br />
[[File:Cont_before_clean.png|thumb|Figure 9: During interactive {{tclean}}, the GUI will show an initial dirty image. From this GUI, create the {{tclean}} mask.]]<br />
</figure><br />
<figure id="Cont_before_clean_mask.png"><br />
[[File:Cont_before_clean_mask.png|thumb|Figure 10: After a mask is created, the green arrow will be illuminated. Press this to begin the first 100 iterations. Once cleaning is complete, press the red "X" to finish.]]<br />
</figure><br />
<figure id="Final_Cont_residual.png"><br />
[[File:Final_Cont_residual.png|thumb|Figure 11: The final residual image.]]<br />
</figure><br />
<br />
Now that you have set all of the imaging parameters you will need in {{tclean}}, you can proceed to imaging the continuum. The [https://casaguides.nrao.edu/index.php/First_Look_at_Imaging First Look at Imaging CASAGuide] gives an introduction to cleaning and imaging. We provide an abbreviated set of commands here. <br />
If you are imaging a mosaic, the phasecenter parameter should be set. Refer to the [[Image_Continuum#Image Parameters | Image Parameters]] section of this guide for instructions on how to determine this for your project. Type “help tclean()” in CASA if you would like to explore the possible parameters of {{tclean}}. Specode=’mfs’ sets the spectral gridding type to multi-frequency synthesis and creates a continuum image. If you are imaging the aggregate continuum in Band 3 or 4 and have a fractional bandwidth larger than 10%, you should consider using multi-term multi-frequency synthesis (deconvolver='mtmfs' and nterms=2). This tclean mode accounts for spatial spectral index variations and especially important to include if you have a spatially resolved, high S/N source. For more information on multi-term multi-frequency synthesis, see [https://www.aanda.org/articles/aa/pdf/2011/08/aa17104-11.pdf Rau, U., & Cornwell, T.J. 2011, A&A, 532, AA71].<br />
Clean interactively as the threshold is set at 0 mJy. The mask parameter may also be added if you have an existing file. You can create a mask from the dirty image using the instructions at [[Create_a_Clean_Mask_from_Continuum_Image_or_Moment_Cube]].<br />
<br />
<source lang="python"><br />
# in CASA<br />
contvis = 'calibrated_final_cont.ms' <br />
contimagename = 'calibrated_final_cont'<br />
</source><br />
<br />
<source lang="python"><br />
# in CASA<br />
tclean(vis=contvis,<br />
imagename=contimagename,<br />
field=field,<br />
# phasecenter=phasecenter, # uncomment if mosaic. <br />
specmode='mfs',<br />
deconvolver='hogbom', <br />
# Uncomment the below to image with nterms>1.<br />
#deconvolver='mtmfs',<br />
#nterms=2,<br />
imsize = imsize, <br />
cell= cell, <br />
weighting = weighting,<br />
robust = robust,<br />
niter = niter, <br />
threshold = threshold,<br />
interactive = True,<br />
gridder = gridder,<br />
pbcor = True)<br />
</source><br />
<br />
Figure 9 shows the {{tclean}} GUI that will appear. If no source is apparent, no cleaning should be done. Press the red “X” to complete the task. If a source is apparent, create a mask around it using the mouse. Once a mask is created, the green arrow will be illuminated and you can begin the first round of cleaning. Figure 10 shows what a mask would look like for our example source. The logger window gives you vital information on the progression of {{tclean}}. Once the cycle is complete, the residuals will appear in the GUI. You should continue to iterate until the region inside the mask matches the noise outside the mask. You may need multiple cycles depending on the complexity of the source. Figure 11 shows an example of when we chose to stop cleaning.<br />
<br />
The red "X" will stop {{tclean}} where you are, the blue arrow will stop the interactive part of {{tclean}}, but continue to clean non-interactively until reaching the number of iterations requested (niter) or the flux density threshold (whichever comes first), and the green circle arrow will clean until it reaches the "iterations" parameter on the left side of the green area. These are the only safe exit buttons to use during {{tclean}}. DO NOT CTRL-C OR KILL TCLEAN WHILE IT IS RUNNING. If you do this, it is very likely that your ms will be corrupted.<br />
<br />
[[Image:Final_Continuum_Image.png|center|frame|800px]] ''The final continuum image.''<br />
<br />
After creating the continuum image, check the noise and resolution to make sure the results match the expected values. Use the [https://almascience.nrao.edu/proposing/sensitivity-calculator ALMA Sensitivity Calculator] to estimate the expected sensitivity. <br />
<br />
For each image it creates, {{tclean}} generates several images with the name imagename+extension. If you re-run tclean with the same imagename, {{tclean}} will use the existing files as a starting point, continuing the tclean where you left off. To start completely from scratch, either change the imagename or delete all the files from the previous {{tclean}} run. Note that CASA retains some image information in memory, so to truly delete the images, you need to run the {{rmtables}} command. You will also want to remove datacolumns that were added by tclean with {{clearcal}} and {{delmod}}. See below for an example.<br />
<br />
<source lang="python"><br />
# in CASA<br />
clearcal(contvis)<br />
delmod(contvis)<br />
for ext in ['.image','.mask','.model','.image.pbcor','.psf','.residual','.pb','.sumwt']:<br />
rmtables(contimagename+ext)<br />
</source><br />
<br />
Once you are happy with your continuum image(s), you can continue to '''[[Self_Calibration_Template | Self-Calibration Template]]''' or '''[[Image_Line | Spectral Line Imaging Template]]'''. If you do not wish to self-calibrate or create line cubes, continue with this guide to create primary beam corrected images and fits files.<br />
<br />
== Export the images ==<br />
<br />
Use {{exportfits}} to create fits files of the *.flux and *.pbcor files. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
myimages = glob.glob("*.pbcor")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True)<br />
<br />
myimages = glob.glob("*.pb")<br />
for image in myimages:<br />
exportfits(imagename=image, fitsimage=image+'.fits',overwrite=True) <br />
<br />
</source><br />
<br />
== Create Diagnostic PNGs ==<br />
<br />
[https://casaguides.nrao.edu/index.php/First_Look_at_Image_Analysis The First Look at Image Analysis] guide gives an introduction to a variety of options to begin image analysis, including using {{immoments}} to create moment maps.<br />
The following commands create png files of the continuum image.<br />
<br />
<source lang="python"><br />
# in CASA<br />
#Test<br />
os.system("rm -rf *.png")<br />
mycontimages = glob.glob("*mfs*manual.image")<br />
for cimage in mycontimages:<br />
mymax=imstat(cimage)['max'][0]<br />
mymin=-0.1*mymax<br />
outimage = cimage+'.png'<br />
os.system('rm -rf '+outimage)<br />
imview(raster={'file':cimage,'range':[mymin,mymax]},out=outimage)<br />
</source><br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Imaging_Prep&diff=25739Imaging Prep2018-11-26T13:53:19Z<p>Jthorley: </p>
<hr />
<div>== Imaging Prep Workflow ==<br />
Commands for this page can be found in scriptForImagingPrep_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
[[Image:Imaging_Prep_Flow.png|center|frame|1200px]] ''Use the Imaging Prep workflow to determine which sections of this guide are applicable to your dataset.''<br />
<br />
== Splitting off the calibrated data (Pipeline Calibration) ==<br />
If your measurement set (ms) is pipeline calibrated, use this step to split off the calibrated data. After restoring the calibration using scriptForPI.py, you should have *.ms files which contain the calibrated data in the CORRECTED column. If you already have files with the name *.ms.split.cal, you can proceed to the next step.<br />
This block of code will split off the science spws for the calibrators and science target. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
vislist = glob.glob('*[!_t].ms') # match full ms, not target.ms<br />
<br />
for myvis in vislist:<br />
<br />
msmd.open(myvis)<br />
targetspws = msmd.spwsforintent('OBSERVE_TARGET*') <br />
sciencespws = [] <br />
for myspw in targetspws: <br />
if msmd.nchan(myspw)>4:<br />
sciencespws.append(myspw)<br />
sciencespws = ','.join(map(str,sciencespws))<br />
msmd.close()<br />
<br />
split(vis=myvis,outputvis=myvis+'.split.cal',spw=sciencespws)<br />
</source><br />
<br />
== Get a list of ms files to image ==<br />
<br />
You should now have *.ms.split.cal files for each execution no matter how your dataset was calibrated. Run the following commands to grab the names of all files in the directory that have the extension ‘.ms.split.cal’ and place them into a list so you can easily check the calibration and concatenate the data further on in the script.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
vislist=glob.glob('*.ms.split.cal')<br />
</source><br />
<br />
== Review the Calibration ==<br />
<figure id="Weblog_Home.png"><br />
[[File:Weblog_Home.png|thumb|Figure 1: The Observation Overview page is opened with index.html.]]<br />
</figure><br />
Once the list of ms files have been collected, review the calibration to make sure it appears reasonable. A summary of the calibration are in the qa directory of your delivered package. <br />
If the dataset was pipeline calibrated, download and untar the pipeline weblog in the qa directory by using<br />
<figure id="Weblog_MS_Overview.png"><br />
[[File:Weblog_MS_Overview.png|thumb|Figure 2: The MS Overview gives information specific to each execution.]]<br />
</figure><br />
<source lang="bash"><br />
# in bash<br />
for i in $(ls *.tar); do tar -xvf $i; done<br />
</source><br />
<source lang="python"><br />
# or in CASA<br />
For i in glob.glob(‘*.tar’):<br />
os.system(‘tar -xvf %s’ % (i))<br />
</source><br />
<br />
Once this is done, look within the /html directory for the index.html file. This contains the html code for displaying the contents of the qa directory in a web browser. The command below opens the main page of the weblog in firefox. <br />
<br />
<source lang="bash"><br />
firefox index.html<br />
</source><br />
<figure id="Weblog_By_Task.png"><br />
[[File:Weblog_By_Task.png|thumb|Figure 3: The weblog By Task view shows an overview of QA scores.]]<br />
</figure><br />
The standard opening page has three main sections: observation overview, pipeline summary, and observation summary. This is shown in Figure 1.<br />
<br />
From the opening page, you can navigate to view the calibration '''By Topic''' and '''By Task''' and open observation specific information by clicking on the ms name.<br />
Figure 2 shows an example of an ms summary page.<br />
<br />
Figure 3 shows the '''By Task''' view. Each task can be opened to view important calibration plots, tables, and flagging statistics.<br />
<br />
If the data was manually calibrated, you can review the calibration with the *.png and *.txt files in the qa directory. These display helpful plots and statistics about the calibration.<br />
<br />
In addition, the tasks {{plotms}} and {{plotcal}} are useful if you need to explore the data beyond the plots that the calibration pipeline or QA2 process generates. The [https://casaguides.nrao.edu/index.php/TWHydraBand7_Calibration_4.3 TW Hydra guide] gives some nice examples showing how to use these tasks.<br />
<br />
== Flag bad data (optional) ==<br />
<br />
This section uses plotms to manually review the uvwave vs amp and channel vs amp plots of all field and spectral windows in the MS file. Outliers seen in the calibrator fields of these plots can be flagged either in the flagdata() command below or interactively within the GUI of plotms().<br />
<br />
Save the original flags of each ms prior to flagging any additional data. Without this step, it will be very difficult if you need to remove flags generated later on.<br />
<br />
<source lang="python"><br />
# in CASA<br />
for vis in vislist:<br />
flagmanager(vis=vis,<br />
mode='save',<br />
versionname='original_flags')<br />
</source><br />
<br />
The {{Plotms}} task can be used to find bad data by iterating through fields and spws for the *.ms.split.cal files in the calibrated directory. You can also use the GUI interface to iterate through spectral windows (spws).<br />
Figure 4 shows an example of TW Hydra science spw 2.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fieldlist = ['3'] # change to list of science data fields to inspect<br />
spwlist = ['1'] # change to list of science spws to inspect<br />
<br />
for vis in vislist:<br />
for field in fieldlist:<br />
for spw in spwlist:<br />
plotms(vis=vis,xaxis='uvwave',yaxis='amp',avgtime='3e8',<br />
field=field,spw=spw)<br />
raw_input("push enter to continue")<br />
plotms(vis=vis,xaxis='chan',yaxis='amp',avgtime='3e8',<br />
field=field,spw=spw)<br />
raw_input("push enter to continue")<br />
</source><br />
<br />
<br />
Use {{flagdata}} to flag bad antennas, spws, timeranges, etc. You can use the locate buttons in {{plotms}} and {{plotcal}} to identify what needs to be flagged. Locate will print the information about the selected points into the casalogger. Note that flagging in plotms is generally not recommended because a plotms crash will lose all flagging information.<br />
<br />
To flag data, modify the {{flagdata}} command with the ms you want to flag and the flagging criteria. Flagging criteria can be any antenna, spw, timerange, etc. Once the data is flagged, check the flagging using plotms. The flagged data points should not appear on the plot. You can also plot the flagged data points using the "display" table on the left hand side of the {{plotms}} GUI.<br />
<figure id="TWHydra_corrected_Spw2.png"><br />
[[File:TWHydra_corrected_Spw2.png|thumb|Figure 4: Inspect the data.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis='',mode='manual',action='apply',flagbackup=False)<br />
</source><br />
<br />
If you need to restore original flags, use the following command. You will need to update the ms name in the vis parameter.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis='',mode='restore',versionname='original_flags')<br />
</source><br />
<br />
== Flux Equalization (optional) ==<br />
<br />
If you have multiple executions taken at a similar time with the same phase calibrator, you can rescale the derived fluxes for the phase calibrator so that they are the same in all executions. If the executions are spaced by more than a day or two, it is likely that the flux of the phase calibrator has changed and thus this step is usually unnecessary. You can compare the derived flux densities of your calibrators for each execution block using the "hifa_gfluxscale" step of the weblog (pipeline calibrations) or the *.fluxscale file (manual calibration). <br />
<br />
The following guides may be useful for assessing the derived fluxes of your phase cailbrators. [http://legacy.nrao.edu/alma/memos/html-memos/alma434/memo434vb.pdf ALMA Memo 434] outlines various uncertainties relevant to amplitude calibration. You can refer to the respective cycle’s Proposer’s Guide ([https://almascience.nrao.edu/documents-and-tools/cycle4/alma-proposers-guide Cycle 4]) for expected uncertainties. In addition, the [https://almascience.eso.org/sc/ ALMA Calibrator Source Catalog] can be used to compare variations detected from source monitoring. <br />
<br />
<figure id="Gfluxscale table.png"><br />
[[File:Gfluxscale_table.png|thumb|Figure 5: An example of the table created by hifa_gfluxscale.]]<br />
</figure><br />
<br />
If you have determined flux equalization is required for your data, please file a [https://help.almascience.org Helpdesk ticket] and a NAASC staff member can assist you by generating a script for your measurement sets. In general, the first step in flux equalization is to set the flux density of the phase calibrator in each spectral window to the desired value using {{setjy}}. Then amplitude calibration tables are generated and applied using {{gaincal}} and {{applycal}} respectively. Finally, all calibrated measurement sets will be concatenated using {{concat}}. <br />
<br />
If you have performed flux equalization, you can skip to the [[Imaging_Prep#Splitting off science target data | Splitting off science target data]] section below.<br />
<br />
== Combining measurement sets from multiple executions ==<br />
<br />
If there are multiple *.ms.split.cal files within the calibrated directory, combine them all into one single ms file in order to make later steps in the imaging process easier. Skip this section if you have only one execution. <br />
<br />
Each execution of the scheduling block will generate multiple spectral windows with different sky frequencies, but the same rest frequency, due to the motion of the Earth. Thus, the resulting concatenated file will contain n spws, where n is (number of original science spws) x (number of executions). In other words, the multiple spws associated with a single rest frequency will not be regridded to a single spectral window in the ms. Combine all executions into one ms file, called calibrated.ms, using the {{concat}} command.<br />
<br />
<source lang="python"><br />
# in CASA<br />
concatvis='calibrated.ms'<br />
<br />
rmtables(concatvis)<br />
os.system('rm -rf ' + concatvis + '.flagversions')<br />
concat(vis=vislist,<br />
#forcesingleephemfield='Uranus', # uncomment this line and insert source name if imaging an ephemeris object<br />
concatvis=concatvis)<br />
</source><br />
<br />
== Splitting off science target data ==<br />
<br />
The calibrated.ms produced in the [[#Combining measurement sets from multiple executions | Combining measurement sets from multiple executions]] section, or your original ms file if you only have one execution, will contain the science target(s) as well as all the calibrator sources. At this point, you are only concerned with imaging your science targets so you can split them off from the calibrated.ms, which has both the science and calibrator sources. This will reduce the size of the file and make it more manageable during imaging. Depending on your project, there may be several executions or only one. Uncomment the line that fits with your data to set the concatvis variable properly.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Uncomment following line for single executions<br />
# concatvis = vislist[0]<br />
<br />
# Uncomment following line for multiple executions<br />
# concatvis='calibrated.ms'<br />
</source><br />
<br />
Split out all target fields from the file and copy them, with only the data column, into a new ms file called calibrated_source.ms. Follow [https://casa.nrao.edu/Release4.1.0/doc/UserMan/UserMansu82.html this link] for more information regarding the structure of measurement sets. <br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcevis='calibrated_source.ms'<br />
rmtables(sourcevis)<br />
os.system('rm -rf ' + sourcevis + '.flagversions')<br />
split(vis=concatvis,<br />
intent='*TARGET*', # split off the target sources<br />
outputvis=sourcevis,<br />
datacolumn='data')<br />
</source><br />
<br />
At this point, it is convenient to create a {{listobs}} file with information about the sources and spectral windows to reference during imaging. Inspect the {{listobs}} to make sure the {{split}} and {{concat}} worked as desired.<br />
<br />
<source lang="python"><br />
# in CASA<br />
listobs(vis=sourcevis,listfile=sourcevis+'.listobs.txt')<br />
</source><br />
<br />
An example {{listobs}} file is below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
Observer: Unknown Project: T.B.D. <br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.81015e+09, 4.81015e+09]Unknown T.B.D. <br />
ALMA [ 4.81015e+09, 4.81016e+09]Unknown T.B.D. <br />
ALMA [ 4.81016e+09, 4.81017e+09]Unknown T.B.D. <br />
Data records: 126900 Total elapsed time = 16902.1 seconds<br />
Observed from 22-Apr-2011/00:15:36.7 to 22-Apr-2011/04:57:18.8 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
22-Apr-2011/00:15:36.7 - 00:16:07.0 9 0 TW Hya 540 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
00:20:57.8 - 00:30:43.2 13 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
00:36:49.2 - 00:44:43.5 18 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
00:49:33.9 - 00:59:19.3 22 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
01:05:46.8 - 01:13:41.2 27 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
01:20:07.2 - 01:29:52.6 31 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
01:37:15.6 - 01:40:13.9 36 0 TW Hya 2700 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
<br />
ObservationID = 1 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
22-Apr-2011/02:02:10.9 - 02:02:41.1 44 0 TW Hya 540 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:07:36.7 - 02:17:22.0 48 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:23:35.7 - 02:31:30.0 53 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:36:23.6 - 02:46:09.0 57 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:52:40.2 - 03:00:34.6 62 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
03:05:14.0 - 03:14:59.4 66 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
03:21:21.4 - 03:24:19.6 71 0 TW Hya 2700 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
<br />
ObservationID = 2 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
22-Apr-2011/03:44:46.9 - 03:45:17.1 79 0 TW Hya 540 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
03:50:08.4 - 03:59:53.7 83 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:06:03.7 - 04:13:58.1 88 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:18:49.1 - 04:28:34.4 92 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:34:59.5 - 04:42:53.9 97 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:47:33.5 - 04:57:18.8 101 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 1<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none TW Hya 11:01:51.844983 -34.42.17.16088 J2000 0 126900<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 3840 TOPO 356497.936 122.070 468750.0 356732.2500 XX YY<br />
1 3840 TOPO 357734.314 122.070 468750.0 357968.6279 XX YY<br />
2 3840 TOPO 346034.314 122.070 468750.0 345800.0000 XX YY<br />
3 3840 TOPO 343955.936 122.070 468750.0 343721.6221 XX YY<br />
Sources: 4<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 TW Hya 0 - - <br />
0 TW Hya 1 - - <br />
0 TW Hya 2 - - <br />
0 TW Hya 3 - - <br />
Antennas: 9:<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 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8 -7.2141 -541.3485 15.0178 2225061.036842 -5440128.036234 -2481534.422455<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1 42.8987 -520.1911 15.0694 2225110.551677 -5440116.726350 -2481514.951072<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5 -0.3652 -563.8032 14.9605 2225064.049398 -5440117.310745 -2481555.086720<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9 42.8798 -575.6928 14.6278 2225102.207484 -5440096.375809 -2481565.910698<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3 8.8012 -527.8598 15.0513 2225077.857538 -5440126.858119 -2481522.008896<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6 19.1981 -566.5667 14.9520 2225081.746122 -5440108.902762 -2481557.629365<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1 -23.6269 -582.3103 14.9195 2225039.780230 -5440119.418780 -2481572.120530<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2 -29.1268 -522.7917 15.0566 2225043.501617 -5440143.045000 -2481517.341976<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0 22.2015 -550.2548 14.9948 2225086.942689 -5440113.674706 -2481542.618537<br />
</pre><br />
<br />
== Regridding spectral window (optional) ==<br />
<br />
ALMA does what is called doppler setting, which means it adjusts the observed sky frequency for the motion of the source and the motion of the Earth around the Sun at the beginning of every execution block. Therefore, different execution blocks will have different observed sky frequencies because the vector of the motion of the Earth around the Sun will be different at different times. <br />
<br />
In general, we strongly recommend using the {{tclean}} command to regrid spectral windows to a common velocity/rest frequency scale on the fly. However, you may also regrid the frequency axis of the visibility data using {{cvel}} prior to imaging. The most common use case for this is where the motion of the Earth around the Sun causes the sky frequencies of the lines to shift too much between executions to identify a common channel range for continuum subtraction. If you regrid using {{cvel}} prior to imaging, you should make sure to use the same input parameters to the {{tclean}} task that you used for {{cvel}}. In other words, you shouldn't regrid the data using both {{cvel}} and {{tclean}}.<br />
<br />
You will likely need to regrid if you are imaging an ephemeris object. In this case, the outframe should be set to SOURCE, for example, outframe = 'SOURCE'.<br />
<br />
'''Due to a bug in all versions of CASA prior to 5.0, {{mstransform}} and {{cvel}} should not be used to average greater than 2 channels together. This averaging should be done using {{tclean}} if using a CASA version less than 5.0'''<br />
<br />
We will start by setting the parameters specific to your observations.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcevis='calibrated_source.ms'<br />
regridvis='calibrated_source_regrid.ms'<br />
veltype = 'radio' # Keep set to radio. See notes in imaging section.<br />
width = '0.23km/s' # due to bug in cvel/mstransform, do not regrid > 2 channels<br />
nchan = -1 # leave this as the default<br />
mode='velocity' # see science goals in the OT<br />
start='' # leave this as the default<br />
outframe = 'bary' # velocity reference frame. see science goals in the OT.<br />
restfreq='115.27120GHz' # rest frequency of primary line of interest.<br />
field = '4' # select science fields.<br />
spw = '0,5,10' # spws associated with a single rest frequency. Do not attempt to combine spectral windows associated with different rest frequencies. This will take a long time to regrid and most likely isn't what you want.<br />
</source><br />
<br />
Regridding here uses the {{cvel}} command to regrid multiple spws associated with a single rest frequency into a single spw. To avoid {{tclean}} regridding the image a second time you will need to use the same parameters used for {{cvel}} for {{tclean}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables(regridvis)<br />
os.system('rm -rf ' + regridvis + '.flagversions')<br />
<br />
cvel(vis=sourcevis,<br />
field=field,<br />
outputvis=regridvis,<br />
spw=spw,<br />
mode=mode,<br />
nchan=nchan,<br />
width=width,<br />
start=start,<br />
restfreq=restfreq,<br />
outframe=outframe,<br />
veltype=veltype)<br />
</source><br />
<br />
The resulting ms will contain a single spw. You should regrid spws at different rest frequencies separately.<br />
<br />
== Rename and backup data set ==<br />
<br />
Depending on the different tasks that were performed above, the current measurement set will have a variety of names. For ease of imaging with a common measurement set, rename the file to calibrated_final.ms.<br />
<br />
If you haven’t regridded, your current ms should be named calibrated_source.ms.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment if you haven’t regridded<br />
# os.system('mv -i ' + sourcevis + ' ' + 'calibrated_final.ms')<br />
</source><br />
<br />
If you have regridded, your current ms should be named calibrated_source_regrid.ms.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment if you have regridded<br />
# os.system('mv -i ' + regridvis + ' ' + 'calibrated_final.ms')<br />
</source><br />
<br />
Now that you have a fully calibrated measurement set containing all your science sources to image, we recommend creating a backup of the dataset. It is possible to corrupt a measurement set if you kill {{clean}}, {{tclean}}, or {{uvcontsub}} while they are running.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system('cp -ir calibrated_final.ms calibrated_final.ms.backup')<br />
</source><br />
<br />
== Continue to Imaging ==<br />
<br />
This guide is continued at '''[[Image_Continuum | Image the Continuum Template]]'''. <br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Imaging_Prep&diff=25564Imaging Prep2018-11-09T16:28:11Z<p>Jthorley: </p>
<hr />
<div>== Imaging Prep Workflow ==<br />
Commands for this page can be found in scriptForImagingPrep_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
[[Image:Imaging_Prep_Flow.png|center|frame|1200px]] ''Use the Imaging Prep workflow to determine which sections of this guide are applicable to your dataset.''<br />
<br />
== Splitting off the calibrated data (Pipeline Calibration) ==<br />
If your measurement set (ms) is pipeline calibrated, use this step to split off the calibrated data. After restoring the calibration using scriptForPI.py, you should have *.ms files which contain the calibrated data in the CORRECTED column. If you already have files with the name *.ms.split.cal, you can proceed to the next step.<br />
This block of code will split off the science spws for the calibrators and science target. <br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
<br />
vislist = glob.glob('*[!_t].ms') # match full ms, not target.ms<br />
<br />
for myvis in vislist:<br />
<br />
msmd.open(myvis)<br />
targetspws = msmd.spwsforintent('OBSERVE_TARGET*') <br />
sciencespws = [] <br />
for myspw in targetspws: <br />
if msmd.nchan(myspw)>4:<br />
sciencespws.append(myspw)<br />
sciencespws = ','.join(map(str,sciencespws))<br />
msmd.close()<br />
<br />
split(vis=myvis,outputvis=myvis+'.split.cal',spw=sciencespws)<br />
</source><br />
<br />
== Get a list of ms files to image ==<br />
<figure id="Weblog_Home.png"><br />
[[File:Weblog_Home.png|thumb|Figure 1: The Observation Overview page is opened with index.html.]]<br />
</figure><br />
You should now have *.ms.split.cal files for each execution no matter how your dataset was calibrated. Run the following commands to grab the names of all files in the directory that have the extension ‘.ms.split.cal’ and place them into a list so you can easily check the calibration and concatenate the data further on in the script.<br />
<br />
<source lang="python"><br />
# in CASA<br />
import glob<br />
vislist=glob.glob('*.ms.split.cal')<br />
</source><br />
<br />
== Review the Calibration ==<br />
<br />
Once the list of ms files have been collected, review the calibration to make sure it appears reasonable. A summary of the calibration are in the qa directory of your delivered package. <br />
If the dataset was pipeline calibrated, download and untar the pipeline weblog in the qa directory by using<br />
<figure id="Weblog_MS_Overview.png"><br />
[[File:Weblog_MS_Overview.png|thumb|Figure 2: The MS Overview gives information specific to each execution.]]<br />
</figure><br />
<source lang="bash"><br />
# in bash<br />
for i in $(ls *.tar); do tar -xvf $i; done<br />
</source><br />
<source lang="python"><br />
# or in CASA<br />
For i in glob.glob(‘*.tar’):<br />
os.system(‘tar -xvf %s’ % (i))<br />
</source><br />
<br />
Once this is done, look within the /html directory for the index.html file. This contains the html code for displaying the contents of the qa directory in a web browser. The command below opens the main page of the weblog in firefox. <br />
<br />
<source lang="bash"><br />
firefox index.html<br />
</source><br />
<figure id="Weblog_By_Task.png"><br />
[[File:Weblog_By_Task.png|thumb|Figure 3: The weblog By Task view shows an overview of QA scores.]]<br />
</figure><br />
The standard opening page has three main sections: observation overview, pipeline summary, and observation summary. This is shown in Figure 1.<br />
<br />
From the opening page, you can navigate to view the calibration '''By Topic''' and '''By Task''' and open observation specific information by clicking on the ms name.<br />
Figure 2 shows an example of an ms summary page.<br />
<br />
Figure 3 shows the '''By Task''' view. Each task can be opened to view important calibration plots, tables, and flagging statistics.<br />
<br />
If the data was manually calibrated, you can review the calibration with the *.png and *.txt files in the qa directory. These display helpful plots and statistics about the calibration.<br />
<br />
In addition, the tasks {{plotms}} and {{plotcal}} are useful if you need to explore the data beyond the plots that the calibration pipeline or QA2 process generates. The [https://casaguides.nrao.edu/index.php/TWHydraBand7_Calibration_4.3 TW Hydra guide] gives some nice examples showing how to use these tasks.<br />
<br />
== Flag bad data (optional) ==<br />
<br />
This section uses plotms to manually review the uvwave vs amp and channel vs amp plots of all field and spectral windows in the MS file. Outliers seen in the calibrator fields of these plots can be flagged either in the flagdata() command below or interactively within the GUI of plotms().<br />
<br />
Save the original flags of each ms prior to flagging any additional data. Without this step, it will be very difficult if you need to remove flags generated later on.<br />
<br />
<source lang="python"><br />
# in CASA<br />
for vis in vislist:<br />
flagmanager(vis=vis,<br />
mode='save',<br />
versionname='original_flags')<br />
</source><br />
<br />
The {{Plotms}} task can be used to find bad data by iterating through fields and spws for the *.ms.split.cal files in the calibrated directory. You can also use the GUI interface to iterate through spectral windows (spws).<br />
Figure 4 shows an example of TW Hydra science spw 2.<br />
<br />
<source lang="python"><br />
# in CASA<br />
fieldlist = ['3'] # change to list of science data fields to inspect<br />
spwlist = ['1'] # change to list of science spws to inspect<br />
<br />
for vis in vislist:<br />
for field in fieldlist:<br />
for spw in spwlist:<br />
plotms(vis=vis,xaxis='uvwave',yaxis='amp',avgtime='3e8',<br />
field=field,spw=spw)<br />
raw_input("push enter to continue")<br />
plotms(vis=vis,xaxis='chan',yaxis='amp',avgtime='3e8',<br />
field=field,spw=spw)<br />
raw_input("push enter to continue")<br />
</source><br />
<br />
<br />
Use {{flagdata}} to flag bad antennas, spws, timeranges, etc. You can use the locate buttons in {{plotms}} and {{plotcal}} to identify what needs to be flagged. Locate will print the information about the selected points into the casalogger. Note that flagging in plotms is generally not recommended because a plotms crash will lose all flagging information.<br />
<br />
To flag data, modify the {{flagdata}} command with the ms you want to flag and the flagging criteria. Flagging criteria can be any antenna, spw, timerange, etc. Once the data is flagged, check the flagging using plotms. The flagged data points should not appear on the plot. You can also plot the flagged data points using the "display" table on the left hand side of the {{plotms}} GUI.<br />
<figure id="TWHydra_corrected_Spw2.png"><br />
[[File:TWHydra_corrected_Spw2.png|thumb|Figure 4: Inspect the data.]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
flagdata(vis='',mode='manual',action='apply',flagbackup=False)<br />
</source><br />
<br />
If you need to restore original flags, use the following command. You will need to update the ms name in the vis parameter.<br />
<br />
<source lang="python"><br />
# in CASA<br />
flagmanager(vis='',mode='restore',versionname='original_flags')<br />
</source><br />
<br />
== Flux Equalization (optional) ==<br />
<br />
If you have multiple executions taken at a similar time with the same phase calibrator, you can rescale the derived fluxes for the phase calibrator so that they are the same in all executions. If the executions are spaced by more than a day or two, it is likely that the flux of the phase calibrator has changed and thus this step is usually unnecessary. You can compare the derived flux densities of your calibrators for each execution block using the "hifa_gfluxscale" step of the weblog (pipeline calibrations) or the *.fluxscale file (manual calibration). <br />
<br />
The following guides may be useful for assessing the derived fluxes of your phase cailbrators. [http://legacy.nrao.edu/alma/memos/html-memos/alma434/memo434vb.pdf ALMA Memo 434] outlines various uncertainties relevant to amplitude calibration. You can refer to the respective cycle’s Proposer’s Guide ([https://almascience.nrao.edu/documents-and-tools/cycle4/alma-proposers-guide Cycle 4]) for expected uncertainties. In addition, the [https://almascience.eso.org/sc/ ALMA Calibrator Source Catalog] can be used to compare variations detected from source monitoring. <br />
<br />
<figure id="Gfluxscale table.png"><br />
[[File:Gfluxscale_table.png|thumb|Figure 5: An example of the table created by hifa_gfluxscale.]]<br />
</figure><br />
<br />
If you have determined flux equalization is required for your data, please file a [https://help.almascience.org Helpdesk ticket] and a NAASC staff member can assist you by generating a script for your measurement sets. In general, the first step in flux equalization is to set the flux density of the phase calibrator in each spectral window to the desired value using {{setjy}}. Then amplitude calibration tables are generated and applied using {{gaincal}} and {{applycal}} respectively. Finally, all calibrated measurement sets will be concatenated using {{concat}}. <br />
<br />
If you have performed flux equalization, you can skip to the [[Imaging_Prep#Splitting off science target data | Splitting off science target data]] section below.<br />
<br />
== Combining measurement sets from multiple executions ==<br />
<br />
If there are multiple *.ms.split.cal files within the calibrated directory, combine them all into one single ms file in order to make later steps in the imaging process easier. Skip this section if you have only one execution. <br />
<br />
Each execution of the scheduling block will generate multiple spectral windows with different sky frequencies, but the same rest frequency, due to the motion of the Earth. Thus, the resulting concatenated file will contain n spws, where n is (number of original science spws) x (number of executions). In other words, the multiple spws associated with a single rest frequency will not be regridded to a single spectral window in the ms. Combine all executions into one ms file, called calibrated.ms, using the {{concat}} command.<br />
<br />
<source lang="python"><br />
# in CASA<br />
concatvis='calibrated.ms'<br />
<br />
rmtables(concatvis)<br />
os.system('rm -rf ' + concatvis + '.flagversions')<br />
concat(vis=vislist,<br />
concatvis=concatvis)<br />
</source><br />
<br />
== Splitting off science target data ==<br />
<br />
The calibrated.ms produced in the [[#Combining measurement sets from multiple executions | Combining measurement sets from multiple executions]] section, or your original ms file if you only have one execution, will contain the science target(s) as well as all the calibrator sources. At this point, you are only concerned with imaging your science targets so you can split them off from the calibrated.ms, which has both the science and calibrator sources. This will reduce the size of the file and make it more manageable during imaging. Depending on your project, there may be several executions or only one. Uncomment the line that fits with your data to set the concatvis variable properly.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# Uncomment following line for single executions<br />
# concatvis = vislist[0]<br />
<br />
# Uncomment following line for multiple executions<br />
# concatvis='calibrated.ms'<br />
</source><br />
<br />
Split out all target fields from the file and copy them, with only the data column, into a new ms file called calibrated_source.ms. Follow [https://casa.nrao.edu/Release4.1.0/doc/UserMan/UserMansu82.html this link] for more information regarding the structure of measurement sets. <br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcevis='calibrated_source.ms'<br />
rmtables(sourcevis)<br />
os.system('rm -rf ' + sourcevis + '.flagversions')<br />
split(vis=concatvis,<br />
intent='*TARGET*', # split off the target sources<br />
outputvis=sourcevis,<br />
datacolumn='data')<br />
</source><br />
<br />
At this point, it is convenient to create a {{listobs}} file with information about the sources and spectral windows to reference during imaging. Inspect the {{listobs}} to make sure the {{split}} and {{concat}} worked as desired.<br />
<br />
<source lang="python"><br />
# in CASA<br />
listobs(vis=sourcevis,listfile=sourcevis+'.listobs.txt')<br />
</source><br />
<br />
An example {{listobs}} file is below.<br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
Observer: Unknown Project: T.B.D. <br />
Observation: ALMA<br />
<br />
Telescope Observation Date Observer Project <br />
ALMA [ 4.81015e+09, 4.81015e+09]Unknown T.B.D. <br />
ALMA [ 4.81015e+09, 4.81016e+09]Unknown T.B.D. <br />
ALMA [ 4.81016e+09, 4.81017e+09]Unknown T.B.D. <br />
Data records: 126900 Total elapsed time = 16902.1 seconds<br />
Observed from 22-Apr-2011/00:15:36.7 to 22-Apr-2011/04:57:18.8 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
22-Apr-2011/00:15:36.7 - 00:16:07.0 9 0 TW Hya 540 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
00:20:57.8 - 00:30:43.2 13 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
00:36:49.2 - 00:44:43.5 18 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
00:49:33.9 - 00:59:19.3 22 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
01:05:46.8 - 01:13:41.2 27 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
01:20:07.2 - 01:29:52.6 31 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
01:37:15.6 - 01:40:13.9 36 0 TW Hya 2700 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
<br />
ObservationID = 1 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
22-Apr-2011/02:02:10.9 - 02:02:41.1 44 0 TW Hya 540 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:07:36.7 - 02:17:22.0 48 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:23:35.7 - 02:31:30.0 53 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:36:23.6 - 02:46:09.0 57 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
02:52:40.2 - 03:00:34.6 62 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
03:05:14.0 - 03:14:59.4 66 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
03:21:21.4 - 03:24:19.6 71 0 TW Hya 2700 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
<br />
ObservationID = 2 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
22-Apr-2011/03:44:46.9 - 03:45:17.1 79 0 TW Hya 540 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
03:50:08.4 - 03:59:53.7 83 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:06:03.7 - 04:13:58.1 88 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:18:49.1 - 04:28:34.4 92 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:34:59.5 - 04:42:53.9 97 0 TW Hya 7020 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
04:47:33.5 - 04:57:18.8 101 0 TW Hya 8640 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
(nRows = Total number of rows per scan) <br />
Fields: 1<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none TW Hya 11:01:51.844983 -34.42.17.16088 J2000 0 126900<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 3840 TOPO 356497.936 122.070 468750.0 356732.2500 XX YY<br />
1 3840 TOPO 357734.314 122.070 468750.0 357968.6279 XX YY<br />
2 3840 TOPO 346034.314 122.070 468750.0 345800.0000 XX YY<br />
3 3840 TOPO 343955.936 122.070 468750.0 343721.6221 XX YY<br />
Sources: 4<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 TW Hya 0 - - <br />
0 TW Hya 1 - - <br />
0 TW Hya 2 - - <br />
0 TW Hya 3 - - <br />
Antennas: 9:<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 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8 -7.2141 -541.3485 15.0178 2225061.036842 -5440128.036234 -2481534.422455<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1 42.8987 -520.1911 15.0694 2225110.551677 -5440116.726350 -2481514.951072<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5 -0.3652 -563.8032 14.9605 2225064.049398 -5440117.310745 -2481555.086720<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9 42.8798 -575.6928 14.6278 2225102.207484 -5440096.375809 -2481565.910698<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3 8.8012 -527.8598 15.0513 2225077.857538 -5440126.858119 -2481522.008896<br />
5 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6 19.1981 -566.5667 14.9520 2225081.746122 -5440108.902762 -2481557.629365<br />
6 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1 -23.6269 -582.3103 14.9195 2225039.780230 -5440119.418780 -2481572.120530<br />
7 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2 -29.1268 -522.7917 15.0566 2225043.501617 -5440143.045000 -2481517.341976<br />
8 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0 22.2015 -550.2548 14.9948 2225086.942689 -5440113.674706 -2481542.618537<br />
</pre><br />
<br />
== Regridding spectral window (optional) ==<br />
<br />
ALMA does what is called doppler setting, which means it adjusts the observed sky frequency for the motion of the source and the motion of the Earth around the Sun at the beginning of every execution block. Therefore, different execution blocks will have different observed sky frequencies because the vector of the motion of the Earth around the Sun will be different at different times. <br />
<br />
In general, we strongly recommend using the {{tclean}} command to regrid spectral windows to a common velocity/rest frequency scale on the fly. However, you may also regrid the frequency axis of the visibility data using {{cvel}} prior to imaging. The most common use case for this is where the motion of the Earth around the Sun causes the sky frequencies of the lines to shift too much between executions to identify a common channel range for continuum subtraction. If you regrid using {{cvel}} prior to imaging, you should make sure to use the same input parameters to the {{tclean}} task that you used for {{cvel}}. In other words, you shouldn't regrid the data using both {{cvel}} and {{tclean}}.<br />
<br />
You will likely need to regrid if you are imaging an ephemeris object. In this case, the outframe should be set to SOURCE, for example, outframe = 'SOURCE'.<br />
<br />
'''Due to a bug in all versions of CASA prior to 5.0, {{mstransform}} and {{cvel}} should not be used to average greater than 2 channels together. This averaging should be done using {{tclean}} if using a CASA version less than 5.0'''<br />
<br />
We will start by setting the parameters specific to your observations.<br />
<br />
<source lang="python"><br />
# in CASA<br />
sourcevis='calibrated_source.ms'<br />
regridvis='calibrated_source_regrid.ms'<br />
veltype = 'radio' # Keep set to radio. See notes in imaging section.<br />
width = '0.23km/s' # due to bug in cvel/mstransform, do not regrid > 2 channels<br />
nchan = -1 # leave this as the default<br />
mode='velocity' # see science goals in the OT<br />
start='' # leave this as the default<br />
outframe = 'bary' # velocity reference frame. see science goals in the OT.<br />
restfreq='115.27120GHz' # rest frequency of primary line of interest.<br />
field = '4' # select science fields.<br />
spw = '0,5,10' # spws associated with a single rest frequency. Do not attempt to combine spectral windows associated with different rest frequencies. This will take a long time to regrid and most likely isn't what you want.<br />
</source><br />
<br />
Regridding here uses the {{cvel}} command to regrid multiple spws associated with a single rest frequency into a single spw. To avoid {{tclean}} regridding the image a second time you will need to use the same parameters used for {{cvel}} for {{tclean}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
rmtables(regridvis)<br />
os.system('rm -rf ' + regridvis + '.flagversions')<br />
<br />
cvel(vis=sourcevis,<br />
field=field,<br />
outputvis=regridvis,<br />
spw=spw,<br />
mode=mode,<br />
nchan=nchan,<br />
width=width,<br />
start=start,<br />
restfreq=restfreq,<br />
outframe=outframe,<br />
veltype=veltype)<br />
</source><br />
<br />
The resulting ms will contain a single spw. You should regrid spws at different rest frequencies separately.<br />
<br />
== Rename and backup data set ==<br />
<br />
Depending on the different tasks that were performed above, the current measurement set will have a variety of names. For ease of beginning imaging with a common measurement set, rename the file to calibrated_final.ms.<br />
<br />
If you haven’t regridded, your current ms should be named calibrated_source.ms.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment if you haven’t regridded<br />
# os.system('mv -i ' + sourcevis + ' ' + 'calibrated_final.ms')<br />
</source><br />
<br />
If you have regridded, your current ms should be named calibrated_source_regrid.ms.<br />
<br />
<source lang="python"><br />
# in CASA<br />
# uncomment if you have regridded<br />
# os.system('mv -i ' + regridvis + ' ' + 'calibrated_final.ms')<br />
</source><br />
<br />
Now that you have fully calibrated measurement set containing all your science sources to image, we recommend creating a backup of the dataset. It is possible to corrupt a measurement set if you kill {{clean}}, {{tclean}}, and {{uvcontsub}} while they are running.<br />
<br />
<source lang="python"><br />
# in CASA<br />
os.system('cp -ir calibrated_final.ms calibrated_final.ms.backup')<br />
</source><br />
<br />
== Continue to Imaging ==<br />
<br />
This guide is continued at '''[[Image_Continuum | Image the Continuum Template]]'''. <br />
<br />
'''[[Guide_NA_ImagingTemplate | Return to the Main Page]]'''</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=Guide_to_the_NA_Imaging_Template&diff=25562Guide to the NA Imaging Template2018-11-09T16:07:26Z<p>Jthorley: </p>
<hr />
<div>== About this Guide ==<br />
<br />
This guide describes the template scripts used to manually image data for quality assurance by the North America ALMA Science Center (NAASC). This script is designed to guide the user through the decisions needed when imaging ALMA data. It should not be applied blindly; some editing of the scripts will be required in almost all cases. Not all sections of the template are relevant for all data sets. It can be adapted for use with partial pipeline processing of images. For example, you could do continuum subtraction in the pipeline, but use the scripts here as a template for manual imaging. See the [[ALMA_Imaging_Pipeline_Reprocessing | ALMA Imaging Pipeline Reprocessing]] guide for information on pipeline processed images.<br />
<br />
A current version of the script can be found on [https://github.com/aakepley/ALMAImagingScript github]. A description of how the script is used at the NAASC can be found in [http://adsabs.harvard.edu/abs/2016SPIE.9910E..0CK Kepley et al. Proceedings of the SPIE, 9910, 99100C ].<br />
<br />
More information on the ALMA Quality Assurance procedure and standards can be found on the [https://almascience.nrao.edu/ ALMA Science Portal].<br />
<br />
All example images were produced using ALMA Science Verification Data of TW Hya. More information along with the dataset can be obtained from the [https://casaguides.nrao.edu/index.php/TWHydraBand7 TW Hydra Band 7 Calibration and Imaging Guide].<br />
<br />
== Prepare for Imaging ==<br />
<br />
Before you begin imaging, determine whether the dataset was manually or pipeline calibrated. The README file should state how the dataset was calibrated. If it does not, look in the script directory of the delivered data package. If you see a file named <ASDM UID>.ms.scriptForCalibration.py, the dataset was manually calibrated. If you see a filename PPR_*.xml, the dataset was pipeline calibrated.<br />
<br />
If the data was calibrated prior to CASA 4.3, we recommend that you image the data in the same version of CASA that it was calibrated in because the weighting scheme for the data in CASA was in limbo. See [https://casaguides.nrao.edu/index.php/DataWeightsAndCombination Data Weights and Combination] for more information. If the data was calibrated in CASA version 4.3 or later, imaging the data in a later version of CASA should work but we recommend using the same version of Casa used for calibration when imaging since Casa is not guaranteed to be backwards compatible. The README or CASA log file will indicate which CASA version was used to calibrate the data. Different versions of CASA can be obtained from [https://casa.nrao.edu/casa_obtaining.shtml Download CASA]. Remember to check the operating system requirements before proceeding with the installation. <br />
<br />
Instructions on restoring the calibrated measurement set should be found in the README of your delivered dataset. For most cases, this can be done by running CASA in the script directory and executing scriptForPI.py in CASA:<br />
<br />
<source lang="python"><br />
# in CASA<br />
execfile(“scriptForPI.py”)<br />
</source><br />
<br />
== Attached Scripts ==<br />
<br />
Two template scripts (scriptForImagingPrep_template.py and scriptForImaging_template.py) are available for this guide. These contain commands with minimal instructions and are intended to be used by those more familiar with imaging.<br />
A current version of the scripts can be found on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
== Obtaining Analysis Utilities ==<br />
<br />
Some optional steps in this guide use the [https://casaguides.nrao.edu/index.php?title=Analysis_Utilities Analysis Utilities] package. If you wish to use any of these tasks, follow the link above for download and installation instructions.<br />
<br />
== Background Information ==<br />
<br />
This guide assumes that you are familiar with basic Python. If you need more information about python, see the official [https://docs.python.org/2/tutorial/ Python 2.7 tutorial]<br />
<br />
If you are new to interferometry or CASA, we recommend you follow the [https://casaguides.nrao.edu/index.php?title=ALMAguides “First Look” Imaging Tutorials]. The [https://science.nrao.edu/science/meetings/2016/15th-synthesis-imaging-workshop/lectures Synthesis Imaging Summer School Lectures] provide a wealth of information on interferometry.<br />
<br />
In addition, many frequently asked questions can be found in the [https://help.almascience.org/index.php?/default/Knowledgebase/List ALMA Knowledgebase]. If you have additional questions after reviewing this guide, please contact the [https://help.almascience.org ALMA Helpdesk].<br />
<br />
== Guide Contents ==<br />
<br />
This guide has been split into 4 sections:<br />
<br />
#'''[[Imaging_Prep | Prepare the data for Imaging]]''' This page creates the calibrated_final.ms that will be used for imaging. Commands can be found in scriptForImagingPrep_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
#'''[[Image_Continuum | Image the Continuum]]''' This page creates a continuum measurement set (MS) named calibrated_final_cont.ms and continuum images using the MS created in [[Imaging_Prep | Prepare the data for imaging]] section. Commands can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
#'''[[Self_Calibration_Template | Self-Calibration]]''' This page provides a basic template for phase and amplitude self calibration of the continuum using the MS created in [[Image_Continuum | Image the Continuum]] section. Commands can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
#'''[[Image_Line | Spectral Line Imaging]]''' This page performs continuum subtraction and creates spectral line cubes using the MS created in [[Imaging_Prep | Prepare the data for imaging]] section. Commands can be found in scriptForImaging_template.py available on [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
The NA imaging workflow used with these scripts is shown below.<br />
<br />
[[Image:Imaging_WorkFlow.png|center|frame|1200px]]<br />
<br />
==How to Use A CASA Guide==<br />
<br />
See the [http://casaguides.nrao.edu/index.php?title=EVLA_Spectral_Line_Calibration_IRC%2B10216#How_to_Use_This_casaguide EVLA Spectral Line Calibration page for IRC+10216] page for tips on using CASA and ways CASA can be run.<br />
<br />
See [http://casaguides.nrao.edu/index.php?title=Extracting_scripts_from_these_tutorials Extracting Scripts From These Tutorials] for information on how to download the scripts from these tutorials. Note that the full scripts can be downloaded via [https://github.com/aakepley/ALMAImagingScript github].<br />
<br />
Within the guides:<br />
<source lang="python"><br />
# Regions of this color are CASA commands (or definitions) that need to be cut and <br />
# pasted in sequence. Wait until one command is finished before pasting another. <br />
# Tabs matter in python, make sure that commands that span more than one line and <br />
# "for" loops keep their spacing. Sometimes (especially "for" loops) you may need to <br />
# explicitly hit enter twice to get the command going.<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
Information in this color shows excerpts from the CASA Logger output<br />
</pre><br />
<br />
<pre style="background-color: #E0FFFF;"><br />
This color shows you background information about the data or other types of reference material<br />
</pre></div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=File:Imaging_WorkFlow.png&diff=22891File:Imaging WorkFlow.png2017-11-21T22:59:27Z<p>Jthorley: Jthorley uploaded a new version of File:Imaging WorkFlow.png</p>
<hr />
<div></div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=IRAS16293_Band9_-_Calibration_for_CASA_4.5&diff=21253IRAS16293 Band9 - Calibration for CASA 4.52017-04-04T17:15:19Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded IRAS16293_Band9_UnCalibratedMS.tgz from [[IRAS16293Band9#Obtaining the Data]]'''.<br />
<br />
*'''Details of the ALMA observations are provided at [[IRAS16293Band9]].<br />
<br />
*'''This portion of the guide covers calibration of the raw visibility data. To skip to the imaging portion of the guide, see: [[IRAS16293 Band9 - Imaging for CASA 4.5]]'''.<br />
<br />
<pre style="background-color: #ffa07a;"><br />
WARNING: On June 15, 2012 the calibration guide and the final data products (calibrated science <br />
data: IRAS16293_Band9_CalibratedMS_FIXED.tgz and reference images: IRAS16293_Band9_ReferenceImages_FIXED.tgz)) <br />
were changed to correct for a 1.2" position error in the phase calibrator (1625-254). Without <br />
correction, the science images will suffer from a similar offset. <br />
</pre><br />
<br />
==Overview==<br />
<br />
This part of the casa guide will guide you through the basic inspection of the data, paying special attention to identifying data that needs to be flagged. The guide shows the complete process to get fully calibrated data.<br />
<br />
The general procedure in this guide follows the other ALMA CASA guides: [[NGC3256Band3]] and [[AntennaeBand7]].<br />
<br />
<br />
==Unpack the Data==<br />
<br />
Once you have downloaded the IRAS16293_Band9_UnCalibratedMS.tgz, unpack the file in a terminal outside CASA using<br />
<br />
<source lang="bash"><br />
<br />
tar -xvzf IRAS16293_Band9_UnCalibratedMS.tgz<br />
<br />
cd IRAS16293_Band9_UnCalibratedMS<br />
<br />
</source><br />
<br />
You have a number of files with extensions ".ms", which are CASA measurement set (MS) files. You will also see files containing system temperature (Tsys), water vapor radiometer (WVR), and antenna position information.<br />
<br />
To start CASA type<br />
<br />
<source lang="bash"><br />
casapy<br />
</source><br />
<br />
Be sure that you are using the right version indicated for this guide.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. Please confirm your version before proceeding. This guide will not work in earlier versions (< r19874).<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.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 />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see a CASA 3.3 version of one of the other ALMA guides for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, it's probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Initial Inspection==<br />
<br />
The first step we will do through all the calibration process is to define an array with the uid's that correspond to the dataset names. This will allow us to make the calibration of the four datasets one after another, using a for-loop inside python. We will then calibrate the data individually and concatenate them at the end, before proceeding with the imaging part.<br />
<br />
Note that if you exit CASA and want to continue with the calibration using these arrays, you will have to re-issue the command again to make it available for the current CASA execution.<br />
<br />
To start, and give an example of this process, we will create txt format files for the output of the {{listobs}} task, which will give us useful information about the observations.<br />
<br />
<source lang="python"><br />
# Array containing the uid names<br />
<br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# We create the text files for listobs for each dataset<br />
<br />
for data in rawdata:<br />
listobs(vis=data,listfile=data+'.listobs')<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to make the command execute. The output will be sent to the CASA logger. Next, we show an example of a useful part of the output that the first listobs command produces.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 11<br />
ID Code Name RA Decl Epoch SrcId nVis <br />
0 none 1924-292 19:24:51.05600 -29.14.30.1280 J2000 0 169125 <br />
1 none nrao530 ph 17:33:02.72400 -13.04.49.4860 J2000 1 289170 <br />
2 none Juno 16:25:31.63031 -05.49.08.9209 J2000 2 82890 <br />
3 none 1625-254 16:25:46.98000 -25.27.38.3300 J2000 3 276480 <br />
4 none IRAS16293-2422-a 16:32:22.99200 -24.28.36.0000 J2000 4 132450 <br />
5 none IRAS16293-2422-a 16:32:22.47925 -24.28.36.0000 J2000 4 99915 <br />
6 none IRAS16293-2422-a 16:32:22.73563 -24.28.36.0000 J2000 4 99960 <br />
7 none IRAS16293-2422-a 16:32:22.73563 -24.28.32.5000 J2000 4 99915 <br />
8 none IRAS16293-2422-a 16:32:22.47925 -24.28.29.0000 J2000 4 99945 <br />
9 none IRAS16293-2422-a 16:32:22.73563 -24.28.29.0000 J2000 4 99945 <br />
10 none IRAS16293-2422-a 16:32:22.99200 -24.28.29.0000 J2000 4 99915 <br />
(nVis = Total number of time/baseline visibilities per field) <br />
Spectral Windows: (25 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 231257.813 15625 2000000 XX YY <br />
2 1 TOPO 232234.375 1796875 1796875 XX YY <br />
3 128 TOPO 229257.813 15625 2000000 XX YY <br />
4 1 TOPO 230234.375 1796875 1796875 XX YY <br />
5 128 TOPO 217242.188 15625 2000000 XX YY <br />
6 1 TOPO 216234.375 1796875 1796875 XX YY <br />
7 128 TOPO 215242.188 15625 2000000 XX YY <br />
8 1 TOPO 214234.375 1796875 1796875 XX YY <br />
9 128 TOPO 703257.813 15625 2000000 XX YY <br />
10 1 TOPO 704234.375 1796875 1796875 XX YY <br />
11 128 TOPO 692492.188 15625 2000000 XX YY <br />
12 1 TOPO 691484.375 1796875 1796875 XX YY <br />
13 128 TOPO 690492.188 15625 2000000 XX YY <br />
14 1 TOPO 689484.375 1796875 1796875 XX YY <br />
15 128 TOPO 688492.188 15625 2000000 XX YY <br />
16 1 TOPO 687484.375 1796875 1796875 XX YY <br />
17 3840 TOPO 703312.744 488.28125 1875000 XX YY <br />
18 1 TOPO 704249.756 1875000 1875000 XX YY <br />
19 3840 TOPO 692237.256 488.28125 1875000 XX YY <br />
20 1 TOPO 691299.756 1875000 1875000 XX YY <br />
21 3840 TOPO 690437.256 488.28125 1875000 XX YY <br />
22 1 TOPO 689499.756 1875000 1875000 XX YY <br />
23 3840 TOPO 688437.256 488.28125 1875000 XX YY <br />
24 1 TOPO 687499.756 1875000 1875000 XX YY <br />
<br />
Antennas: 15:<br />
ID Name Station Diam. Long. Lat. <br />
0 DA41 A003 12.0 m -067.45.16.5 -22.53.27.0 <br />
1 DA43 A075 12.0 m -067.45.17.9 -22.53.21.4 <br />
2 DA47 A026 12.0 m -067.45.18.8 -22.53.28.3 <br />
3 DV02 A077 12.0 m -067.45.10.1 -22.53.25.9 <br />
4 DV03 A137 12.0 m -067.45.15.2 -22.53.22.7 <br />
5 DV05 A082 12.0 m -067.45.08.3 -22.53.29.2 <br />
6 DV07 A076 12.0 m -067.45.20.5 -22.53.33.8 <br />
7 DV09 A046 12.0 m -067.45.17.0 -22.53.29.3 <br />
8 DV10 A071 12.0 m -067.45.19.9 -22.53.23.5 <br />
9 DV12 A011 12.0 m -067.45.14.4 -22.53.28.4 <br />
10 DV13 A072 12.0 m -067.45.12.6 -22.53.24.0 <br />
11 DV14 A025 12.0 m -067.45.18.7 -22.53.27.4 <br />
12 DV15 A074 12.0 m -067.45.12.1 -22.53.32.0 <br />
13 DV17 A138 12.0 m -067.45.17.1 -22.53.34.4 <br />
14 DV18 A053 12.0 m -067.45.17.3 -22.53.31.2 <br />
</pre><br />
<br />
In the previous output you can see the ID that is assigned to each source, starting with the number 0. 1924-292 and 3c279 are the calibrators for bandpass, Juno for amplitude (flux), 1625-254 is our phase calibrator and nrao530 ph serves as a check (phase calibrator) source. The remaining 7 fields of IRAS16293-2422-a are the seven pointings for our mosaic of the target source.<br />
<br />
Spectral windows are also marked with numbers from 0 to 24, with number 0 containing WVR information. Spws 17, 19, 21, and 23 contain the science data (FDM mode). The CO (6-5) line emission is contained in spw 19. Spw 18, 20, 22, and 24 contain channel averages of the data from spectral windows 17, 19, 21, 23, respectively. These spws will not be used for the offline data reduction. All the remaining spws that appear in the section of "Sources", and that do not appear in the "Spectral Windows" section are related to WVR measurements for each antenna, so you will not need them for the calibration either. Spws 9, 11, 13, and 15 are associated with tsys measurements, and we will apply these measurements to the science spws later.<br />
<br />
Finally before we go further we explicitly save the current flag state of the data. If you ever decide to start completely over, you should substitute 'restore' for 'save' in the command below to restore the flag state to its original value.<br />
<br />
<source lang="python"><br />
# Use flagmanager to save current flag state.<br />
<br />
for vis in rawdata:<br />
flagmanager(vis=vis,mode='save',versionname='OriginalFlagState')<br />
</source><br />
<br />
== Generation and visualization of the antenna positions, Tsys and WVR tables ==<br />
<br />
Next we will generate the tables we need to apply to the data: antenna position, system temperature and water vapor radiometer. Once the tables are generated we will produce plots of them and inspect them to make sure whether they have issues that might affect their application to the data. Whenever we see an odd behavior in the tables we need to flag the corresponding science data to prevent wrong results in the calibration steps. <br />
<br />
=== System Temperature ===<br />
We produce the Tsys tables with the next command<br />
<br />
<source lang="python"><br />
# Create Tsys<br />
os.system('rm -rf *tdm.tsys')<br />
for vis in rawdata:<br />
print "Creating TDM Tsys Table for "+vis<br />
gencal(vis=vis,caltable=vis+'.tdm.tsys',spw='9,11,13,15',caltype='tsys')<br />
</source><br />
<br />
The next command will plot the tsys in the next way: it will produce many plots, each one of them will show an antenna, with the four spws that the tsys tables cover, for all the targets, and with different colors for different times, so you can trace the behavior for tsys with time, among others.<br />
Note that in spw 19, the overlap with the tsys spw (11) is not set correctly. This is due to an error in the frequencies for the tsys when the observations were done. You do not have to worry about this, since any issue coming from that error has already been fixed. Note, however that the portions of the spectra that do not have tsys information cannot be used. This does not represent a problem, since that part corresponds to the edge of the baseband. Also note that the CO (6-5) line is not affected by this.<br />
In Figure 1 you will see the corresponding plot for one of the datasets (X90c) showing antenna 0 (DA41).<br />
<br />
[[File:uid___A002_X3d55cb_X90c.mstsys.DA41.spw0.png|200px|thumb|right|'''Fig. 1.''' Example for the output of the command that plots the tsys spws. Find a description in the text.]]<br />
<br />
<br />
<source lang="python"><br />
# Plot TDM Tsys tables with times overlayed for each antenna<br />
os.system('rm -rf Tsysplots/*time*')<br />
for vis in rawdata:<br />
plotbandpass(caltable=vis+'.tdm.tsys',vis=vis,<br />
overlay='time', xaxis='freq', showatm=True,<br />
yaxis='amp',subplot=22,interactive=False,<br />
chanrange='5~122',showfdm=True,<br />
figfile='Tsysplots/'+vis+'.time.tdm.tsys.png')<br />
</source><br />
<br />
Another useful set of plots is generated by the next command. Each resulting plot shows all the antennas in a scan, for one spectral windows. This is useful to check Tsys for all the antennas in a certain time. In Figure 2 you can see an example.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.ms.antenna.tdm.tsys.spw9.t1.png|200px|thumb|right|'''Fig. 2.''' Second sample plot for tsys plotting. The first four scans of the observations for spw 17 are shown, with all the antennas per plot.]]<br />
<br />
<source lang="python"><br />
# Plot TDM Tsys tables with antennas overlayed for each time <br />
os.system('rm -rf Tsysplots/*antenna*')<br />
for vis in rawdata:<br />
plotbandpass(caltable=vis+'.tdm.tsys',vis=vis,<br />
overlay='antenna', xaxis='freq', showatm=True,<br />
yaxis='amp',subplot=22,interactive=False,<br />
chanrange='5~122',showfdm=True,<br />
figfile='Tsysplots/'+vis+'.antenna.tdm.tsys.png')<br />
</source><br />
<br />
Go through all the plots and make sure you notice all the next issues, since we will need to flag the corresponding science data.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
X90c<br />
DV05 ripples all spw <br />
Otherwise 600 to 1200 47 to 57% transmission<br />
<br />
X575<br />
Otherwise 1300 to 3000 28 to 39% transmission<br />
DV05 ripples all spw <br />
<br />
Xb50<br />
800 to 2500 37 to 47% transmission<br />
DV05 ripples all spw <br />
<br />
X39b<br />
500 to 800 56 to 65%<br />
DA43 Tsys extremely high for spw=23<br />
DV05 ripples all spw and one time with bad YY <br />
DV18 extremely high for spw=23<br />
</pre><br />
<br />
=== Water Vapor Radiometer ===<br />
We now generate the WVR tables by executing <br />
<br />
<source lang="python"><br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# Other values can be left at defaults<br />
os.system('rm -rf *.wvrgcal')<br />
for vis in rawdata:<br />
wvrgcal(vis=vis,caltable=vis+'.wvr',toffset=-1)<br />
</source><br />
<br />
The integration time for the science spectral windows is 6.048 seconds. So we need to average the WVR 1 second solutions to match.<br />
<br />
<source lang="python"><br />
# Smoothing the data<br />
for vis in rawdata:<br />
print "Smoothing wvr table for "+vis<br />
smoothcal(vis=vis,tablein=vis+'.wvr',caltable=vis+'.wvr.smooth',<br />
smoothtype='mean',smoothtime=6.048)<br />
</source><br />
<br />
Now, for the plotting of the wvr tables, we will employ the Analysis utils package. This command will create a directory with all the plots inside, each one of them corresponding to different datasets, baselines and targets, using different colors. In Figure 3 you can see an example of the output for spectral window 1. Note that the command below only creates the plots for that spw, since the others are the same except for a scale factor that is the ratio of frequencies.<br />
Note that in all datasets, DV15 has bad wvr behavior.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.ms.wvr.smooth.2.png|200px|thumb|right|'''Fig. 3.''' Phase corrections as function of time for the dataset X90c, where you can see an example of the odd behavior of DV15-related baselines.]]<br />
<br />
<source lang="python"><br />
# Plotting wvr tables for spw 1<br />
os.system('rm -rf WVRplots')<br />
for vis in rawdata:<br />
au.plotWVRSolutions(caltable=vis+'.wvr.smooth',<br />
yrange=[-180,180],figfile='WVRplots/'+vis+'.wvr.smooth.png',<br />
ms=vis,spw='1',interactive=False)<br />
</source><br />
<br />
=== Antenna position ===<br />
Finally, we need to create the tables to correct for the antenna positions. For that, execute<br />
<br />
<source lang="python"><br />
# Generate the tables for antenna positions<br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# For the data taken on April 16<br />
antennas='DV18,DV12,DV09,DV10,DV13,DV05,DA41,DV14,DA43,DV17,DV07,DV15'<br />
parameter=[0.00684754783288,-0.0188271608204,-0.00732900947332,<br />
0.000481227821554,-2.48519197708e-05,-0.00048066949752,<br />
0.000741523189806,-0.000843518709779,-0.000409113120338,<br />
0.00111751207514,-0.000891124202747,-0.000492116263895,<br />
0.00100313175518,-0.00084909900337,-0.000594194887412,<br />
0.00105206234994,-0.000857719516042,-0.00059565765641,<br />
0.00060776527971,-0.000525096431375,-0.000386487226933,<br />
0.000521688542419,-0.000144920371688,-0.000258341151538,<br />
0.00104740676978,-0.000899314162014,-0.000483014592547,<br />
0.000920921096116,-0.00106288533016,-0.000546355296173,<br />
0.000867350985729,-0.000990079062422,-0.00038123971161,<br />
0.000567245762795,-0.000422531738877,-0.000741700641811]<br />
gencal(vis = 'uid___A002_X3d4118_X39b.ms',<br />
caltable = 'uid___A002_X3d4118_X39b.ms.antpos',<br />
caltype = 'antpos',antenna=antennas,parameter=parameter)<br />
<br />
# and for April 17<br />
antennas='DV05,DV09,DV10,DV13,DV12,DA41,DV14,DA43,DV17,DV07,DV15'<br />
parameter=[0.00105206234994,-0.000857719516042,-0.00059565765641,<br />
0.000741523189806,-0.000843518709779,-0.000409113120338,<br />
0.00111751207514,-0.000891124202747,-0.000492116263895,<br />
0.00100313175518,-0.00084909900337,-0.000594194887412,<br />
0.000481227821554,-2.48519197708e-05,-0.00048066949752,<br />
0.00060776527971,-0.000525096431375,-0.000386487226933,<br />
0.000521688542419,-0.000144920371688,-0.000258341151538,<br />
0.00104740676978,-0.000899314162014,-0.000483014592547,<br />
0.000920921096116,-0.00106288533016,-0.000546355296173,<br />
0.000867350985729,-0.000990079062422,-0.00038123971161,<br />
0.000567245762795,-0.000422531738877,-0.000741700641811]<br />
for vis in range(1,4):<br />
gencal(vis=rawdata[vis],<br />
caltable=rawdata[vis]+'.antpos',<br />
caltype ='antpos',antenna=antennas,parameter=parameter)<br />
</source><br />
<br />
Now, based on the behavior of the tsys and wvr tables, we will flag the corresponding data, using the next commands. You can employ similar executions to flag other data you might want to remove.<br />
<br />
<source lang="python"><br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
<br />
# Flagging corresponding science data for tsys and wvr showing problems<br />
for vis in rawdata:<br />
flagdata(vis=vis,autocorr = True,flagbackup = False)<br />
flagdata(vis=vis,mode='shadow',flagbackup=False)<br />
flagdata(vis=vis,antenna='DV05,DV15',flagbackup=False)<br />
<br />
vis='uid___A002_X3d4118_X39b.ms'<br />
flagdata(vis=vis,antenna='DA43,DV18',spw='23',flagbackup=False)<br />
<br />
</source><br />
<br />
== Applying antpos, tsys, and wvr tables and splitting the data ==<br />
<br />
To apply the Tsys tables we need to separate sources that have Tsys measurements of their own from those that do not. Since only one IRAS16293 field (id=4) has Tsys, it goes into<br />
the "not" category. As you probably noted from the messages from<br />
plotbandpass, the Tsys measurements on Juno did not yield usable<br />
values, causing them to be flagged, so we will apply the nearest<br />
source in elevation to it: IRAS16293 field id=4. This can be checked <br />
with the plots generated by the following {{plotms}} commands. <br />
In Figure 4 you can see the output of this command for Xb50.<br />
<br />
[[File:uid___A002_X3d55cb_Xb50.antwvrtsys.mselevation.png|200px|thumb|right|'''Fig. 4.''' Elevation for all the sources versus time for Xb50. Note that this dataset has very low elevations.]]<br />
<br />
<source lang="python"><br />
# Re-entering our array<br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# Elevation plots to understand what the elevation range for each dataset is.<br />
for vis in rawdata:<br />
plotms(vis=vis, <br />
field='',xaxis='time', yaxis='elevation',antenna='',<br />
spw='17', avgchannel='3840',coloraxis='field',<br />
ydatacolumn='data',plotfile=vis+'elevation.png',title=vis, showgui = True)<br />
</source><br />
<br />
To apply the Tsys we need to explicitly tell {{applycal}} which TDM (128<br />
channels) spws go with which FDM spw (3840 channels). An entry is needed<br />
for every spw, because the position in the list corresponds to the<br />
spw id to be corrected.<br />
There is a helper function to assist you in figuring this out. <br />
<br />
<source lang="python"><br />
from recipes.almahelpers import tsysspwmap<br />
tsysspwmap(vis='uid___A002_X3d4118_X39b.ms',<br />
tsystable='uid___A002_X3d4118_X39b.ms.tdm.tsys')<br />
<br />
# This will print:<br />
# [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,19,20,13,13,15,15]<br />
</source><br />
<br />
The helper gets a little confused in this case with spws 19 and 20<br />
because the FDM was not perfectly positioned within the TDM window<br />
as you can see from the Tsys plots. In a case like this, we need to<br />
put in by hand the TDM window that should match the FDM window.<br />
<br />
As you could see from the first run of listobs, 1924-292 is the bandpass calibrator for three of the datasets, and 3c279 is for one of them. For this reason, the application of the tables is split into two parts.<br />
<br />
For the {{applycal}} task, note that the first value in the interp parameter for each gaintable gives the desired time interpolation type. The second parameter indicates the<br />
desired frequency axis interpolation. If the second value is not set<br />
it is assumed to be linear, but only if the input table has a<br />
frequency axis (like Tsys and Bandpass). Spline seems to work best<br />
for the Tsys TDM to FDM frequency interpolation.<br />
<br />
<source lang="python"><br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
tsysspw=[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 />
<br />
# Datasets with 1924-292 as the bandpass calibrator<br />
for vis in [rawdata[0],rawdata[2],rawdata[3]]:<br />
print "Applying calibration for "+vis<br />
field_Tsys=['1924-292','nrao530 ph']<br />
for field in field_Tsys:<br />
print "For Field= "+field<br />
applycal(vis=vis,field=field,<br />
spw = '17,19,21,23',<br />
gaintable = [vis+'.tdm.tsys', <br />
vis+'.wvr.smooth', <br />
vis+'.antpos'],<br />
gainfield = [field,field,''],<br />
spwmap=[tsysspw,[],[]],<br />
interp = ['linear,spline','nearest',''],calwt = True,<br />
flagbackup = False)<br />
<br />
<br />
# This next applycal takes care of the fact that one dataset has 3C279<br />
# instead of 1924-292 as the bandpass calibrator <br />
<br />
for vis in [rawdata[1]]:<br />
print "Applying calibration for "+vis<br />
field_Tsys=['3c279','nrao530 ph']<br />
for field in field_Tsys:<br />
print "For Field= "+field<br />
applycal(vis=vis,field=field,<br />
spw = '17,19,21,23',<br />
gaintable = [vis+'.tdm.tsys', <br />
vis+'.wvr.smooth', <br />
vis+'.antpos'],<br />
gainfield = [field,field,''],<br />
spwmap=[tsysspw,[],[]],<br />
interp = ['linear,spline','nearest',''],calwt = True,<br />
flagbackup = False)<br />
<br />
# Next we do the "noTsys" sources for all datasets<br />
<br />
for vis in rawdata:<br />
print "Applying calibration for "+vis<br />
field_noTsys=['Juno','1625-254','IRAS16293*']<br />
for field in field_noTsys:<br />
print "For Field= "+field<br />
applycal(vis =vis,field=field,<br />
spw = '17,19,21,23',<br />
gaintable = [vis+'.tdm.tsys', <br />
vis+'.wvr.smooth', <br />
vis+'.antpos'],<br />
gainfield = ['4',field,''],<br />
spwmap=[tsysspw,[],[]],<br />
interp = ['linear,spline','nearest',''],calwt = True,<br />
flagbackup = False)<br />
<br />
# Splitting the science spws<br />
<br />
for vis in rawdata:<br />
split(vis=vis,outputvis=('%s.antwvrtsys.ms'%(vis.split('.')[0])),<br />
datacolumn='corrected',spw='17,19,21,23',keepflags=False)<br />
</source><br />
<br />
== Fix Phase Calibrator Position ==<br />
<br />
The position used for the phase calibrator (1625-254) in these observations is offset by about 1.2"<br />
toward postive R.A from its correct position. Below we correct the data for this offset. It is best to do this step before doing any of the gain calibration. It is notable that simply shifting the images for this offset will not give as correct a result due to phase delays caused by sky rotation during the course of each observation.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms']<br />
</source><br />
<br />
List the data to see current position of 1625-254<br />
<br />
<source lang="python"><br />
for vis in data:<br />
listobs(vis=vis,listfile=vis+'.listobs',verbose=True)<br />
</source><br />
<br />
Incorrect position from listobs: 1625-254 16h25m46.98000s -25d27m38.3300s J2000<br />
<br />
From the [http://www.vla.nrao.edu/astro/calib/manual/csource.html<br />
EVLA calibrator manual] we find that the correct position is: 16h25m46.891639s -25d27m38.326880s J2000<br />
<br />
Next use the task fixvis to correct the position of the calibrator in<br />
the data and the header. It will also recalculate UVWs, but this<br />
correction is very small for a 1.2" shift.<br />
<br />
<source lang="python"><br />
for vis in data:<br />
fixvis(vis=vis,outputvis=vis+'.fixed',field='1625-254',reuse=False,<br />
phasecenter='J2000 16h25m46.891639s -25d27m38.326880s',<br />
datacolumn='DATA')<br />
</source><br />
<br />
== Data inspection ==<br />
<br />
We now need to check for any bad behavior in the data through several plots. Once problems are identified, data can be flagged. But before that, we need to run again {{listobs}} to check that the split and calibrator position correction worked as expected. We will define our new array of split and corrected datasets.<br />
<br />
<source lang="python"><br />
# New array of datasets <br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
<br />
for vis in data:<br />
listobs(vis=vis,listfile=vis+'.listobs',verbose=True)<br />
</source><br />
<br />
You can explore any of the output files by doing <tt>cat file.listobs</tt> or using any other text reader from a terminal not running CASA. Next you can see the output for X90c, and you will see the change in the spw naming, among others.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 11<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 1924-292 19:24:51.05600 -29.14.30.1280 J2000 0 11000 <br />
1 none nrao530 ph 17:33:02.72400 -13.04.49.4860 J2000 1 19800 <br />
2 none Juno 16:25:05.61170 -05.43.27.9210 J2000 2 8800 <br />
3 none 1625-254 16:25:46.89164 -25.27.38.3269 J2000 3 22000 <br />
4 none IRAS16293-2422-a 16:32:22.99200 -24.28.36.0000 J2000 4 9900 <br />
5 none IRAS16293-2422-a 16:32:22.47925 -24.28.36.0000 J2000 4 9900 <br />
6 none IRAS16293-2422-a 16:32:22.73563 -24.28.36.0000 J2000 4 9900 <br />
7 none IRAS16293-2422-a 16:32:22.73563 -24.28.32.5000 J2000 4 9900 <br />
8 none IRAS16293-2422-a 16:32:22.47925 -24.28.29.0000 J2000 4 8800 <br />
9 none IRAS16293-2422-a 16:32:22.73563 -24.28.29.0000 J2000 4 8800 <br />
10 none IRAS16293-2422-a 16:32:22.99200 -24.28.29.0000 J2000 4 8800 <br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 703312.744 488.28125 1875000 XX YY <br />
1 3840 TOPO 692237.256 -488.28125 1875000 XX YY <br />
2 3840 TOPO 690437.256 -488.28125 1875000 XX YY <br />
3 3840 TOPO 688437.256 -488.28125 1875000 XX YY <br />
Sources: 20<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 1924-292 0 - - <br />
0 1924-292 1 - - <br />
0 1924-292 2 - - <br />
0 1924-292 3 - - <br />
1 Juno 0 - - <br />
1 Juno 1 - - <br />
1 Juno 2 - - <br />
1 Juno 3 - - <br />
2 1625-254 0 - - <br />
2 1625-254 1 - - <br />
2 1625-254 2 - - <br />
2 1625-254 3 - - <br />
3 nrao530 ph 0 - - <br />
3 nrao530 ph 1 - - <br />
3 nrao530 ph 2 - - <br />
3 nrao530 ph 3 - - <br />
4 IRAS16293-2422-a 0 - - <br />
4 IRAS16293-2422-a 1 - - <br />
4 IRAS16293-2422-a 2 - - <br />
4 IRAS16293-2422-a 3 - - <br />
Antennas: 11:<br />
ID Name Station Diam. Long. Lat. <br />
0 DA41 A003 12.0 m -067.45.16.5 -22.53.27.0 <br />
1 DA43 A075 12.0 m -067.45.17.9 -22.53.21.4 <br />
2 DV02 A077 12.0 m -067.45.10.1 -22.53.25.9 <br />
3 DV03 A137 12.0 m -067.45.15.2 -22.53.22.7 <br />
5 DV07 A076 12.0 m -067.45.20.5 -22.53.33.8 <br />
6 DV09 A046 12.0 m -067.45.17.0 -22.53.29.3 <br />
7 DV10 A071 12.0 m -067.45.19.9 -22.53.23.5 <br />
8 DV12 A011 12.0 m -067.45.14.4 -22.53.28.4 <br />
9 DV13 A072 12.0 m -067.45.12.6 -22.53.24.0 <br />
10 DV14 A025 12.0 m -067.45.18.7 -22.53.27.4 <br />
12 DV17 A138 12.0 m -067.45.17.1 -22.53.34.4 <br />
</pre><br />
<br />
Next, we give you a set of useful {{plotms}} commands which will help you to analyze all the data in several ways. You can save a copy of the output, so you do not have to run them again every time you want to check them. This is especially useful for the plots that take a lot of time to generate. To save time we only plot data from the 1st of our 4 measurement sets. In a real data reduction process you would want to inspect plots for all your measurement sets.<br />
<br />
In Figure 5 you can see the output of the following plotms command for data set X39b. By clicking the green arrows in the plotms window you can access all the spws.<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.time.spw0.png|200px|thumb|right|'''Fig. 5.''' {{plotms}} result for amplitude vs time for all the sources, which are displayed with different colors. The plot shows spw 0 for the dataset X39b.]]<br />
<br />
<source lang="python"><br />
# Check overall behavior with time<br />
vis=data[0]<br />
plotms(vis=vis, <br />
field='',xaxis='time', yaxis='amp',antenna='',<br />
spw='', avgchannel='3840',coloraxis='field',<br />
iteraxis='spw',ydatacolumn='data',yselfscale=True, showgui = True)<br />
</source><br />
For the next set of plotms commands, inspect each dataset, noting any problems that you notice.<br />
<br />
<source lang="python"><br />
# For at least one spw go antenna by antenna to look for dropouts not<br />
# obvious in previous plot<br />
vis=data[0]<br />
plotms(vis=vis, <br />
field='',xaxis='time', yaxis='amp',antenna='',<br />
spw='2', avgchannel='3840',coloraxis='field',<br />
iteraxis='antenna',ydatacolumn='data', showgui = True)<br />
<br />
# Check out spectral properties of each source for problems<br />
vis=data[0]<br />
plotms(vis=vis, <br />
field='',xaxis='freq', yaxis='amp',antenna='',<br />
spw='', avgtime='1e8',avgscan=True,coloraxis='spw',<br />
iteraxis='field',ydatacolumn='data',yselfscale=True, showgui = True)<br />
<br />
# Examine phase of the bandpass calibrator for any problems<br />
vis=data[0]<br />
bp='1924-292'<br />
plotms(vis=vis, <br />
field=bp,xaxis='freq', yaxis='phase',antenna='',<br />
spw='', avgtime='1e8',avgscan=True,avgchannel='10',coloraxis='spw',<br />
iteraxis='baseline',ydatacolumn='data',yselfscale=True, showgui = True)<br />
</source><br />
<br />
== Flagging ==<br />
<br />
Next, based on our inspection we will proceed with the corresponding flagging. But before that, we will save the current flags state, so we can recover it later, if needed.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
<br />
# Back up flag state in case you want to start over.<br />
for vis in data:<br />
flagmanager(vis=vis,mode='save',versionname='Original')<br />
<br />
# If you do start over run this first<br />
for vis in data:<br />
flagmanager(vis=vis,mode='restore',versionname='Original')<br />
</source><br />
<br />
During the procedure of calibration, below, some problems in the data will show up. Those data need to be flagged and then the calibration should be repeated. In order to save you time, we will flag those data now.<br />
<br />
<source lang="python"><br />
# PROBLEMS DISCOVERED AFTER INITIAL CALIBRATION INSPECTION<br />
<br />
# flag low elevation scans on 1625-254 and IRAS16293<br />
flagdata(vis='uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed',<br />
timerange='>11:54:00', field='',flagbackup=False)<br />
<br />
# flag low gains on DV02 on Juno<br />
flagdata(vis='uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed',<br />
antenna='DV02', field='Juno',flagbackup=False)<br />
<br />
flagdata(vis='uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
antenna='DV02', field='Juno',flagbackup=False)<br />
</source><br />
<br />
== Calibration ==<br />
<br />
Now we can start with the calibration itself. First, we will perform the bandpass calibration using 1924-292 and 3c279. As before, we define our list of data and match the sources with intents. Also, we will set our reference antenna (one close to the center of the array and without problems, like delays). As you can see, two different intervals for channels are used, which will make sense in a bit.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
calfields=['1924-292,Juno,1625-254,nrao530*',<br />
'3c279,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*']<br />
<br />
# Setup calibration parameters<br />
prebpchan='0~3:1200~1500'<br />
calchan='0~3:20~3820'<br />
refant='DV14'<br />
gaps=5<br />
os.system('rm -rf *cal')<br />
</source><br />
Note that if at some point during the calibration process you need to start over, then you will need to clear all the columns for solutions in the data, as shown next.<br />
<br />
<source lang="python"><br />
for vis in range(len(data)):<br />
delmod(vis=data[vis])<br />
setjy(vis=data[vis],field=fluxcal,standard='Butler-JPL-Horizons 2010',<br />
scalebychan=True,usescratch=False)<br />
</source><br />
<br />
[[File:Horizons2010JunoCASA4.0.png|200px|thumb|right|'''Fig. 6.''' Plot of Juno model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.]]<br />
<br />
[[File:Horizons2012JunoCASA4.0.png|200px|thumb|right|'''Fig. 7.''' Juno model produced by 'Butler-JPL-Horizons 2012'.]]<br />
<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. Figure 7 shows the Juno model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
<br />
Now we proceed with the bandpass calibration, which will be done in two steps. In the first one, we will use a small block of channels in the center of the spws, 1200~1500, to calculate gains in phase, using a solution interval of 30 seconds. This will give us the variation of the phase throughout the observation. We will use this table later to execute the {{bandpass}} itself. Note that we are using a minimum signal to noise ratio of 2 to accept the solutions. This is low but necessary since the calibrators are not very strong in band 9.<br />
<br />
<source lang="python"><br />
# Calculating phase variation with time<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.bpphase.gcal',<br />
field=bpcal[vis],spw=prebpchan,refant=refant,<br />
calmode='p',solint='30s',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
Next, we set our bandpass command to use our previously generated gain tables. Since we do not have a high signal to noise ratio per channel, we use a polynomial option to calculate the solutions for the bandpass. In the {{bandpass}} task, the options degamp and degphase will set the maximum degree of the polynomial that the task can use to calculate solutions. In the work log you can note what is the actual degree that the task is using. Note that the combination of solint='inf' and combine='scan' will result in one solution per scan for the calibrator.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.bandpass_bpoly.DV09.spw0.t1_34.png|200px|thumb|right|'''Fig. 8.''' Bandpass solutions for the dataset X90c (all 4 spws) showing antenna DV09. Both amplitude and phases solutions are plotted. These data use the weaker bandpass calibrator J1924-224.]]<br />
<br />
[[File:uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.bandpass_bpoly.DV09.spw0.t1.png|200px|thumb|right|'''Fig. 9.''' Bandpass solutions for the dataset X575 (all 4 spws) showing antenna DV09. Both amplitude and phases solutions are plotted. These data use the stronger bandpass calibrator 3C279.]]<br />
<br />
<br />
<source lang="python"><br />
# Bandpass calibration using previous tables as input<br />
for vis in range(len(data)):<br />
bandpass(vis=data[vis],caltable=data[vis]+'.bandpass.bcal',<br />
field=bpcal[vis],spw='',combine='scan',refant=refant,<br />
solint='inf',solnorm=True,minblperant=4,fillgaps=gaps,<br />
gaintable=[data[vis]+'.bpphase.gcal'])<br />
<br />
for vis in range(len(data)):<br />
bandpass(vis=data[vis],caltable=data[vis]+'.bandpass_bpoly.bcal',<br />
field=bpcal[vis],spw='',combine='scan',refant=refant,<br />
solint='inf',solnorm=True,minblperant=4,fillgaps=gaps,<br />
bandtype='BPOLY',degamp=7,degphase=7,<br />
gaintable=[data[vis]+'.bpphase.gcal'])<br />
</source><br />
<br />
To plot all our tables we will use plotbandpass and {{plotcal}}. The plotbandpass command will create plot files for each combination of dataset and antenna, for both amplitude and phase. Inspect all these plots to make sure that the bandpass solutions look good.<br />
In Figures 8 and 9 we show an output sample for this command for the two bandpass calibrators used -- note how noisy the weaker bandpass calibrator (J1924) is without BPOLY.<br />
<br />
<source lang="python"><br />
# Set some plotting things<br />
SPW=['0','1','2','3']<br />
numants=15 # max for any of the input datasets<br />
os.system('rm -rf cal_plots')<br />
os.system('mkdir cal_plots')<br />
<br />
os.system('rm -rf cal_plots/*bandpass_bpoly.bcal.*png')<br />
for vis in range(len(data)):<br />
plotbandpass(caltable=data[vis]+'.bandpass.bcal',<br />
caltable2=data[vis]+'.bandpass_bpoly.bcal',<br />
field=bpcal[vis],xaxis='freq',yaxis='both',<br />
figfile='cal_plots/'+data[vis]+'.bandpass_bpoly.png',<br />
interactive=False,subplot=42)<br />
</source><br />
<br />
The next step in the calibration is to calculate amplitude and phase gains vs time for our calibrators. The ideal case here is to have a solution per integration of the data, but in this case we will need to use a solution interval of 30 seconds to avoid having many failed solutions, especially in the weak phase calibrator. First, we will calculate gains for phase and later using that information, we will solve for amplitude and phase. In all the next three executions we are using the bandpass calibration table, as it provides the gains for phase and amplitude vs frequency.<br />
<br />
<source lang="python"><br />
#Using 30s (5 integrations) per solution to avoid many failed solution of the weak calibrator.<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.intphase.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='p',solint='30s',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal'])<br />
</source><br />
To plot our *.intphase.gcal tables we use the next command, which will create files containing the phase gains vs time for all the antennas and for all the datasets.<br />
In Figure 10 we show an example of such plots. Again, you will need to check all plots to make sure the solutions are good. To speed things up, we will loop over the antenna indices and plot 5 antennas per page. Some of the antennas were completely flagged prior to running {{split}}; plots for those antennas will be empty.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.intphase.gcal.spw0.ant5_9.png|200px|thumb|right|'''Fig. 10.''' Phase gain solutions vs time for 5 antennas for all calibrators in the case of X90c.]]<br />
<br />
<source lang="python"><br />
# Plotting phase gains vs time<br />
os.system('rm -rf cal_plots/*intphase*png')<br />
for vis in data:<br />
for spw in SPW:<br />
for antenna in range(0,numants,5): <br />
plotcal(caltable=vis+'.intphase.gcal',<br />
xaxis='time',yaxis='phase',antenna='%d~%d'%(antenna,antenna+4),<br />
iteration='antenna',subplot=511,poln='',spw=spw,<br />
showgui=False,<br />
figfile='cal_plots/'+vis+'.intphase.gcal.spw%s.ant%d_%d.png'%(spw,antenna,antenna+4),<br />
fontsize=8.0,plotrange=[0,0,-180,180])<br />
</source><br />
Next we will use gaincal to solve for gain phases for all the calibrators, but this time we will get one single solution per scan.<br />
<br />
<source lang="python"><br />
# Gaincal execution as before, but to get a single solution per scan<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.scanphase.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal'])<br />
</source><br />
The next command will produce many plots, and like the previous one, you will get one for each dataset and for each antenna. See example in Figure 11.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.scanphase.gcal.spw0.ant5_9.png|200px|thumb|right|'''Fig. 11.''' Phase gain solutions vs time for all the calibrators in the case of X90c showing the same 5 antennas from previous figure. Note that there is only one solution per scan for each source.]]<br />
<br />
<source lang="python"><br />
# Phase vs time plotting for our calibrators<br />
os.system('rm -rf cal_plots/*scanphase*png')<br />
for vis in data:<br />
for spw in SPW:<br />
for antenna in range(0,numants,5):<br />
plotcal(caltable=vis+'.scanphase.gcal',<br />
xaxis='time',yaxis='phase',antenna='%d~%d'%(antenna,antenna+4),<br />
iteration='antenna',subplot=511,poln='',spw=spw,<br />
showgui=False,<br />
figfile='cal_plots/'+vis+'.scanphase.gcal.spw%s.ant%d_%d.png'%(spw,antenna,antenna+4),<br />
fontsize=8.0,plotrange=[0,0,-180,180])<br />
</source><br />
<br />
Finally, in the next {{gaincal}} we will solve for amplitude and phase. We will use the gain phase calibration table produced before. We will get one solution per scan for all our calibrators.<br />
<br />
<source lang="python"><br />
# Gaincal solving for amplitude and phase vs time.<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.amp.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal'])<br />
</source><br />
<br />
We now can check the resulting plots with the next plotcal executions. In Figure 12 we show an example of these plots.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.amp.gcal.spw0.ant5_9.png|200px|thumb|right|'''Fig. 12.''' Gain amplitudes for all the calibrators, as function of time. A plot for X90c is shown with 5 antennas in it. As in the previous plot, there is only one solution per scan for each source.]]<br />
<br />
<source lang="python"><br />
# Plotting gain amplitudes as function of time.<br />
os.system('rm -rf cal_plots/*amp*png')<br />
for vis in data: <br />
for spw in SPW:<br />
for antenna in range(0,numants,5):<br />
plotcal(caltable=vis+'.amp.gcal',<br />
xaxis='time',yaxis='amp',antenna='%d~%d'%(antenna,antenna+4),<br />
iteration='antenna',subplot=511,poln='',spw=spw,<br />
figfile='cal_plots/'+vis+'.amp.gcal.spw%s.ant%d_%d.png'%(spw,antenna,antenna+4),<br />
fontsize=8.0, showgui = True)<br />
</source><br />
<br />
We can plot the same tables but in a different way that will allow us to look for higher abnormal gains in the solutions. With the next command we will get only four plots for each spw. Each of those plots shows all the gains for all the antennas for all the sources (See Figure 13 for an example). Below in the box, there are some comments to focus you on some data, so you can double check. Before continuing, make sure you check all the calibration tables.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.amp.png|200px|thumb|right|'''Fig. 13.''' Gain amplitudes for all the calibrators, as function of time (X90c), all antennas for each spw. Check for higher gains that deviate from the average.]]<br />
<br />
<source lang="python"><br />
# Look for low or high gains compared to other data<br />
os.system('rm -rf *amp.png')<br />
for vis in data:<br />
plotcal(caltable=vis+'.amp.gcal',<br />
xaxis='time',yaxis='amp',antenna='',field='',<br />
iteration='spw',subplot=411,poln='',spw='',<br />
showgui=False,figfile=vis+'.amp.png')<br />
# X90c good<br />
# X575 one antenna spw=0<br />
# Xb50 end times bad all spws (low el), spw=0 more; low DV02 on Juno<br />
# X39b low DV02 on Juno<br />
</source><br />
<br />
==== Set Absolute Flux Scale ====<br />
<br />
Now that the gain calibration is done, we need to set the flux for our calibrators. For this we will use Juno, our primary flux calibrator. We will do this by using {{fluxscale}}. <br />
We then will transfer the flux information from our phase calibrator to our science target.<br />
For these datasets, we note the following for this step:<br />
The derived flux densities for X39b, X90c, and Xb50 are quite<br />
reasonable. The results for X575 are a little high, probably because<br />
Juno was at low elevation for these observations.<br />
<br />
<source lang="python"><br />
# Setting fluxes<br />
<br />
for vis in range(len(data)):<br />
fluxscale(vis=data[vis],caltable=data[vis]+'.amp.gcal',<br />
fluxtable=data[vis]+'.flux.cal',reference=fluxcal)<br />
</source><br />
<br />
Below we copy the fluxscale numbers from the logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed",caltable="uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.flux.cal",reference="Juno", transfer=[''],listfile="",<br />
append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 1924-292 nrao530 ph 1625-254<br />
Flux density for 1924-292 in SpW=0 is: 2.26282 +/- 0.0615171 (SNR = 36.7836, N = 24)<br />
Flux density for 1924-292 in SpW=1 is: 2.34321 +/- 0.0706187 (SNR = 33.1811, N = 24)<br />
Flux density for 1924-292 in SpW=2 is: 2.20448 +/- 0.056128 (SNR = 39.2759, N = 24)<br />
Flux density for 1924-292 in SpW=3 is: 2.27766 +/- 0.0682751 (SNR = 33.3601, N = 20)<br />
Flux density for nrao530 ph in SpW=0 is: 0.621106 +/- 0.0366187 (SNR = 16.9615, N = 24)<br />
Flux density for nrao530 ph in SpW=1 is: 0.621617 +/- 0.0406897 (SNR = 15.277, N = 24)<br />
Flux density for nrao530 ph in SpW=2 is: 0.60858 +/- 0.0324375 (SNR = 18.7616, N = 24)<br />
Flux density for nrao530 ph in SpW=3 is: 0.61897 +/- 0.0407009 (SNR = 15.2078, N = 20)<br />
Flux density for 1625-254 in SpW=0 is: 0.375472 +/- 0.0270986 (SNR = 13.8558, N = 24)<br />
Flux density for 1625-254 in SpW=1 is: 0.386889 +/- 0.0274299 (SNR = 14.1047, N = 24)<br />
Flux density for 1625-254 in SpW=2 is: 0.409608 +/- 0.0213044 (SNR = 19.2264, N = 24)<br />
Flux density for 1625-254 in SpW=3 is: 0.377672 +/- 0.030287 (SNR = 12.4698, N = 20)<br />
Fitted spectrum for 1924-292 with fitorder=1: Flux density = 2.26513 +/- 0.0349352 (freq=693.582 GHz) spidx=0.146731 +/- 1.8366<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.61668 +/- 0.00356153 (freq=693.582 GHz) spidx=0.518398 +/- 0.692498<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.391202 +/- 0.00893717 (freq=693.582 GHz) spidx=-2.61617 +/- 2.96819<br />
Storing result in uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
##########################################<br />
<br />
##########################################<br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed",caltable="uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.flux.cal",reference="Juno",transfer=[''],listfile="",append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 3c279 nrao530 ph 1625-254<br />
Flux density for 3c279 in SpW=0 is: 10.0473 +/- 0.170083 (SNR = 59.0728, N = 22)<br />
Flux density for 3c279 in SpW=1 is: 10.6211 +/- 0.204771 (SNR = 51.8683, N = 22)<br />
Flux density for 3c279 in SpW=2 is: 10.439 +/- 0.190577 (SNR = 54.7761, N = 22)<br />
Flux density for 3c279 in SpW=3 is: 9.8948 +/- 0.213262 (SNR = 46.3974, N = 22)<br />
Flux density for nrao530 ph in SpW=0 is: 0.900648 +/- 0.0469511 (SNR = 19.1827, N = 22)<br />
Flux density for nrao530 ph in SpW=1 is: 0.954835 +/- 0.0576885 (SNR = 16.5516, N = 22)<br />
Flux density for nrao530 ph in SpW=2 is: 0.868769 +/- 0.0634537 (SNR = 13.6914, N = 22)<br />
Flux density for nrao530 ph in SpW=3 is: 0.898756 +/- 0.0667589 (SNR = 13.4627, N = 22)<br />
Flux density for 1625-254 in SpW=0 is: 0.608887 +/- 0.0545965 (SNR = 11.1525, N = 22)<br />
Flux density for 1625-254 in SpW=1 is: 0.600939 +/- 0.0564496 (SNR = 10.6456, N = 22)<br />
Flux density for 1625-254 in SpW=2 is: 0.564227 +/- 0.0523831 (SNR = 10.7712, N = 22)<br />
Flux density for 1625-254 in SpW=3 is: 0.56677 +/- 0.0646495 (SNR = 8.76681, N = 22)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2668 +/- 0.190218 (freq=693.582 GHz) spidx=-0.993535 +/- 2.11611<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.909081 +/- 0.0219124 (freq=693.582 GHz) spidx=-0.229624 +/- 2.6073<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.585089 +/- 0.00864407 (freq=693.582 GHz) spidx=3.22022 +/- 1.73489<br />
Storing result in uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
##########################################<br />
<br />
##########################################<br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed",caltable="uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.flux.cal",reference="Juno",transfer=[''],listfile="",append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 1924-292 nrao530 ph 1625-254<br />
Flux density for 1924-292 in SpW=0 is: 2.03239 +/- 0.0804821 (SNR = 25.2527, N = 22)<br />
Flux density for 1924-292 in SpW=1 is: 2.14333 +/- 0.0688452 (SNR = 31.1326, N = 22)<br />
Flux density for 1924-292 in SpW=2 is: 2.27019 +/- 0.0630149 (SNR = 36.0262, N = 22)<br />
Flux density for 1924-292 in SpW=3 is: 2.29756 +/- 0.0628644 (SNR = 36.5479, N = 22)<br />
Flux density for nrao530 ph in SpW=0 is: 0.615295 +/- 0.0392509 (SNR = 15.6759, N = 22)<br />
Flux density for nrao530 ph in SpW=1 is: 0.616158 +/- 0.0358843 (SNR = 17.1707, N = 22)<br />
Flux density for nrao530 ph in SpW=2 is: 0.673485 +/- 0.0318436 (SNR = 21.1498, N = 22)<br />
Flux density for nrao530 ph in SpW=3 is: 0.657576 +/- 0.0347543 (SNR = 18.9207, N = 22)<br />
Flux density for 1625-254 in SpW=0 is: 0.414261 +/- 0.0339788 (SNR = 12.1917, N = 22)<br />
Flux density for 1625-254 in SpW=1 is: 0.407031 +/- 0.0278748 (SNR = 14.6021, N = 22)<br />
Flux density for 1625-254 in SpW=2 is: 0.421672 +/- 0.0308659 (SNR = 13.6614, N = 22)<br />
Flux density for 1625-254 in SpW=3 is: 0.408483 +/- 0.0285555 (SNR = 14.3049, N = 22)<br />
Fitted spectrum for 1924-292 with fitorder=1: Flux density = 2.18517 +/- 0.0270747 (freq=693.582 GHz) spidx=-5.83258 +/- 1.68869<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.642359 +/- 0.0134547 (freq=693.582 GHz) spidx=-3.62214 +/- 2.75328<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.412532 +/- 0.00412088 (freq=693.582 GHz) spidx=0.237612 +/- 1.29441<br />
Storing result in uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
##########################################<br />
<br />
##########################################<br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed",caltable="uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.flux.cal",reference="Juno",transfer=[''],listfile="",append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 1924-292 nrao530 ph 1625-254<br />
Flux density for 1924-292 in SpW=0 is: 2.43493 +/- 0.0655999 (SNR = 37.118, N = 22)<br />
Flux density for 1924-292 in SpW=1 is: 2.44094 +/- 0.0478862 (SNR = 50.9739, N = 22)<br />
Flux density for 1924-292 in SpW=2 is: 2.27421 +/- 0.0538595 (SNR = 42.2248, N = 22)<br />
Flux density for 1924-292 in SpW=3 is: 2.32056 +/- 0.0551078 (SNR = 42.1094, N = 22)<br />
Flux density for nrao530 ph in SpW=0 is: 0.702695 +/- 0.0511122 (SNR = 13.7481, N = 22)<br />
Flux density for nrao530 ph in SpW=1 is: 0.677135 +/- 0.0392508 (SNR = 17.2515, N = 22)<br />
Flux density for nrao530 ph in SpW=2 is: 0.675852 +/- 0.0422636 (SNR = 15.9913, N = 22)<br />
Flux density for nrao530 ph in SpW=3 is: 0.672319 +/- 0.0403538 (SNR = 16.6606, N = 22)<br />
Flux density for 1625-254 in SpW=0 is: 0.506353 +/- 0.0507682 (SNR = 9.97382, N = 22)<br />
Flux density for 1625-254 in SpW=1 is: 0.479865 +/- 0.0293747 (SNR = 16.336, N = 22)<br />
Flux density for 1625-254 in SpW=2 is: 0.439463 +/- 0.0365189 (SNR = 12.0339, N = 22)<br />
Flux density for 1625-254 in SpW=3 is: 0.444093 +/- 0.0326742 (SNR = 13.5916, N = 22)<br />
Fitted spectrum for 1924-292 with fitorder=1: Flux density = 2.3764 +/- 0.0422989 (freq=693.582 GHz) spidx=2.43015 +/- 2.40572<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.681796 +/- 0.000887152 (freq=693.582 GHz) spidx=2.09606 +/- 0.171843<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.470153 +/- 0.00954831 (freq=693.582 GHz) spidx=6.41113 +/- 2.92508<br />
Storing result in uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
</pre><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, in the case of measurement set X575, 3c279 in spectral window 2 has a flux of 10.8 Jy using the 2010 standard and 9.7 Jy using the 2012 standard; as a second example, for measurement set X39b, 1924-292 in SPW 0 has a flux of 2.3 Jy (2010 standard) and 2.1 Jy (2012 standard). <br />
</div><br />
<br />
When derived fluxes are too high and nothing else appears wrong with<br />
the data, the cause (especially at Band 9) is likely to be decorrelation. So<br />
we will favor the average of the lower values to explicitly set the<br />
flux densities based on the {{fluxscale}} results. We set the flux of the two<br />
bandpass calibrators for the convenience of having a fully calibrated<br />
dataset. The only ones that really matter are 1625 as the gain<br />
calibrator and the check source nrao530.<br />
Based on this, we proceed as follows to make the changes that are needed:<br />
<br />
<source lang="python"><br />
# Fixing the fluxes<br />
flux1924=[2.3,0,0,0]<br />
flux1625=[0.43,0,0,0]<br />
fluxnrao530=[0.66,0,0,0]<br />
flux3c279=[10.5,0,0,0]<br />
<br />
datawith1924=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
for vis in datawith1924:<br />
setjy(vis=vis,field='1924-292',fluxdensity=flux1924,usescratch=False)<br />
setjy(vis=vis,field='1625-254',fluxdensity=flux1625,usescratch=False)<br />
setjy(vis=vis,field='nrao530*',fluxdensity=fluxnrao530,usescratch=False)<br />
<br />
datawith3c279=['uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed']<br />
for vis in datawith3c279:<br />
setjy(vis=vis,field='3c279',fluxdensity=flux3c279,usescratch=False)<br />
setjy(vis=vis,field='1625-254',fluxdensity=flux1625,usescratch=False)<br />
setjy(vis=vis,field='nrao530*',fluxdensity=fluxnrao530,usescratch=False)<br />
</source><br />
<br />
We now need to re-run the amplitude calibration step.<br />
<br />
<source lang="python"><br />
#This new amplitude calibration will be used in the applycal.<br />
<br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
calfields=['1924-292,Juno,1625-254,nrao530*',<br />
'3c279,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*']<br />
<br />
calchan='0~3:20~3820'<br />
refant='DV14'<br />
<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.amp.final.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal'])<br />
</source><br />
<br />
== Application of calibration tables ==<br />
<br />
Now that we have all the calibration tables with the results, both for gains and flux, we need to apply all the tables to the data. First, we save the state of the flags.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
<br />
for vis in range(len(data)):<br />
flagmanager(vis=data[vis],mode='save',versionname='beforeapplycal')<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=bpcal[vis],<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=[bpcal[vis],bpcal[vis],bpcal[vis]],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=pcal,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=[bpcal[vis],pcal,pcal],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=fluxcal,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=[bpcal[vis],fluxcal,fluxcal],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=science,<br />
interp=['nearest','linear','linear'],<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.scanphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
gainfield=[bpcal[vis],pcal,pcal],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=check,<br />
interp=['nearest','linear','linear'],<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.scanphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
gainfield=[bpcal[vis],pcal,pcal],flagbackup=False,calwt=False)<br />
</source><br />
<br />
<br />
== Plot corrected data ==<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.cal.time.spw1.png|200px|thumb|right|'''Fig. 14.''' This plot shows amplitude (flux) versus time for the dataset X90c in spw 1.]]<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.cal.time.phase.spw1.png|200px|thumb|right|'''Fig. 15.''' Phase vs time for all the sources in X90c (spw 1).]]<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.cal.freq.amp.1625-254.png|200px|thumb|right|'''Fig. 16.''' Amplitude (flux) vs frequency for 1625-254 in X39b.]]<br />
<br />
[[File:uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.cal.freq.phase.3c279.png|200px|thumb|right|'''Fig. 17.''' Phase vs frequency for 3c279 in X575.]]<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.science.freq.amp1.png|200px|thumb|right|'''Fig. 18.''' Amplitude vs frequency for the science target, colored by fields for X39b and spw 1, showing CO (6-5).]]<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.science.freq.amp3.png|200px|thumb|right|'''Fig. 19.''' Amplitude vs frequency as for Figure 15, but for spw 3.]]<br />
<br />
The next commands will help you visualize the result of the application of the calibration tables to the data. You can check if the amplitudes and phases vs time and frequency look reasonable for all the sources, in particular for the science target fields.<br />
<br />
The next command will produce four plots, as the one we showed in Figure 5, but the amplitude in this new plots corresponds to flux because we now have calibrated data.<br />
See Figure 14 for an example of it. It is important to check that all the sources have similar amplitude (flux) in the different spws and datasets.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
calfields=['1924-292,Juno,1625-254,nrao530*',<br />
'3c279,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*']<br />
# Set some plotting things<br />
SPW=['0','1','2','3']<br />
<br />
os.system('rm -rf aftercal_plots')<br />
os.system('mkdir aftercal_plots')<br />
<br />
os.system('rm -rf aftercal_plots/*cal.time*.png')<br />
for vis in range(len(data)):<br />
for spw in SPW:<br />
plotms(vis=data[vis],spw=spw,xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.time.spw%s.png'%(spw), showgui = True)<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
It is also important to check the phases vs time for all the sources. The next command will get you the corresponding plots, four for each dataset. You can see that while the bandpass and amplitude calibrator have very concentrated phases around 0 degrees, the phase calibrator and the science target do not.<br />
In Figure 15 we show an example of these plots for spw 1 in the dataset X90c.<br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*cal.time.phase*.png')<br />
for vis in range(len(data)):<br />
for spw in SPW:<br />
plotms(vis=data[vis],spw=spw,xaxis='time',yaxis='phase',field='',avgchannel='3840',<br />
coloraxis='field',ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.time.phase.spw%s.png'%(spw), showgui = True)<br />
</source><br />
<br />
We now check the amplitude of the sources vs frequency. This is important since we expect that all the spw have very similar behavior. You will have one plot for each field for each dataset. In Figure 16 we show the case for 1625-254, our phase calibrator, for X39b.<br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*cal.freq.amp*.png')<br />
for vis in range(len(data)):<br />
for field in calfields[vis].split(','):<br />
plotms(vis=data[vis],field='%s'%field,xaxis='freq', yaxis='amp',<br />
spw='',avgtime='1e8',avgscan=True,<br />
coloraxis='spw',xselfscale=True,ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.freq.amp.'+field+'.png', showgui = True)<br />
</source><br />
The next command will produce similar plots but this time of phase vs frequency (see Figure 17 for an example).<br />
You will notice that only strong sources, like 3c279, will show clearly phases concentrated around 0 degrees.<br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*cal.freq.phase*.png')<br />
for vis in range(len(data)):<br />
for field in calfields[vis].split(','):<br />
plotms(vis=data[vis],field='%s'%field,xaxis='freq', yaxis='phase',<br />
spw='',avgtime='1e8',avgscan=True,<br />
coloraxis='spw',xselfscale=True,ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.freq.phase.'+field+'.png', showgui = True)<br />
</source><br />
<br />
Finally, for our science target, we plot amplitude (flux) vs frequency for all the spectral windows. See an example of this is Figure 18 and 19. If you look carefully at these plots, you will notice that the datasets at low elevation show much more line emission - this is due to the <br />
shorter projected baselines present for these datasets (X39b and Xb50). In contrast, you start to see some weak absorption for the dataset at high elevation: X90c. <br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*science.freq.amp*.png')<br />
for vis in range(len(data)):<br />
for spw in SPW: <br />
plotms(vis=data[vis],field=science,xaxis='freq', yaxis='amp',<br />
spw=spw,avgtime='1e8',avgscan=True,<br />
coloraxis='field',xselfscale=True,ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.science.freq.amp'+spw+'.png',<br />
title=data[vis].split('_')[-1].split('.')[0]+'.IRAS16293_spw'+spw, showgui = True)<br />
</source><br />
<br />
Next, we put a list of additional plotms commands that do not produce .png files, but that you can explore and save a copy of the output file if you are interested.<br />
<br />
<source lang="python"><br />
# Additional manual plots<br />
vis=data[0]<br />
plotms(vis=vis,spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',ydatacolumn='corrected',iteraxis='spw', showgui = True)<br />
<br />
vis=data[1]<br />
plotms(vis=vis,field=bpcal[1],xaxis='freq', yaxis='amp',<br />
spw='2',avgtime='1e8',avgscan=True,iteraxis='antenna',<br />
coloraxis='field',xselfscale=True,ydatacolumn='corrected', showgui = True)<br />
<br />
vis=data[1]<br />
plotms(vis=vis,field=calfields[1],xaxis='freq', yaxis='amp',<br />
spw='',avgtime='1e8',avgscan=True,<br />
coloraxis='field',xselfscale=True,ydatacolumn='corrected', showgui = True)<br />
</source><br />
<br />
== Split and concatenate the calibrated data ==<br />
<br />
You are ready now to extract the final calibrated data for the science target. Of course, you can do something similar for the calibrators if you are interested.<br />
<br />
<source lang="python"><br />
# Splitting final calibrated datasets<br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
<br />
for vis in data:<br />
split(vis=vis,outputvis='%s.cal.IRAS16293.ms.fixed'%(vis.split('.')[0]),<br />
datacolumn='corrected',field='IRAS16293*',keepflags=False)<br />
</source><br />
<br />
There are now four datasets fully calibrated. We finally will merge these datasets into a single one, in order to proceed with the analysis and imaging in both continuum and spectral line.<br />
<br />
<source lang="python"><br />
# Concatenating the final split files<br />
concatdata=['uid___A002_X3d4118_X39b.cal.IRAS16293.ms.fixed',<br />
'uid___A002_X3d55cb_X575.cal.IRAS16293.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.cal.IRAS16293.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.cal.IRAS16293.ms.fixed']<br />
<br />
concat(vis=concatdata,concatvis='IRAS16293_Band9.fixed.ms')<br />
</source><br />
<br />
To speed up imaging we apply 60 second time averaging to the concatenated dataset.<br />
<br />
<source lang="python"><br />
# 60s time averaging<br />
split(vis='IRAS16293_Band9.fixed.ms', datacolumn='data', timebin='60s', <br />
outputvis='IRAS16293_Band9.fixed.rebin.ms')<br />
</source><br />
<br />
As a final step, we zero the rows of the pointing table because it is<br />
quite large and is not currently needed by the imaging software for<br />
mosaics -indeed its presence will cause an error during imaging if you<br />
skip this step.<br />
<br />
<source lang="python"><br />
# Remove rows of pointing table<br />
tb.open('IRAS16293_Band9.fixed.rebin.ms/POINTING', nomodify = False)<br />
a = tb.rownumbers()<br />
tb.removerows(a)<br />
tb.close() <br />
</source><br />
<br />
Now you have completed the calibration and have everything you need to carry out the imaging stage. Follow [[IRAS16293 Band9 - Imaging for CASA 4.5]] to go to the imaging section of this casaguide.<br />
<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=M100_Band3_Combine_4.5&diff=21252M100 Band3 Combine 4.52017-04-04T17:10:47Z<p>Jthorley: </p>
<hr />
<div><pre style="background-color: #ffa07a;"><br />
WARNING: Note that this guide has been prepared exclusively for the 2016 Synthesis Imaging Summer School and is not intended for general use. <br />
<br />
The currently maintained combination CASAguide, written for CASA 4.3.0, can be found here: https://casaguides.nrao.edu/index.php/M100_Band3_Combine_4.3<br />
</pre><br />
<br />
<br />
= Overview =<br />
<br />
This guide describes how to combine the 7m and 12m interferometric data and then how to feather the resulting image with the total power TP image. All of the data for this SV project can be found at https://almascience.nrao.edu/alma-data/science-verification. '''This guide has been written for data reduced in CASA 4.5.0''' and assumes that all calibration tables (Tsys and gain tables) have been applied to the visibility weights using calwt=True. If either of these is not the case for your data, do not follow this guide, instead look at https://casaguides.nrao.edu/index.php/DataWeightsAndCombination for methods to correct the data weights for data reduced in earlier versions of CASA.<br />
<br />
In order to run this guide you will need the following three files:<br />
* 12m array calibrated data: M100_Band3_12m_CalibratedData.ms<br />
* 7m array calibrated data: M100_Band3_7m_CalibratedData.ms<br />
* Total Power image: M100_TP_CO_cube.bl.image<br />
<br />
To obtain the '''fully calibrated 12m data''' M100_Band3_12m_CalibratedData.ms, either download the file M100_Band3_12m_CalibratedData.tgz or download the uncalibrated 12m data (M100_Band3_12m_UnalibratedData.tgz) and execute the calibration scripts (M100_Band3_12m_CalibrationScripts.tgz). How to obtain the data is described in [[M100_Band3#Obtaining the Data]]. An overview of the 12m data and its calibration is located at [[M100_Band3]].<br />
<br />
<pre style="background-color: #ffa07a;"><br />
WARNING: Note that the imaging presented in this Guide uses the new calibration (using CASA 4.5)<br />
of the same 12-m array data that were released previously (using CASA 3.3).<br />
<br />
Do not use the previously released CASA 3.3 version of the calibrated 12-m data (either downloaded <br />
before 28 July 2015 or identified by the suffix "_CASA3.3" after 28 July 2015) for this tutorial.<br />
</pre><br />
<br />
To obtain the '''fully calibrated 7m data''' M100_Band3_7m_CalibratedData.ms, either download the file M100_Band3_7m_CalibratedData.tgz or download the uncalibrated 7m data (M100_Band3_7m_UnalibratedData.tgz) and execute the calibration scripts (M100_Band3_7m_CalibrationScripts.tgz). How to obtain the data is described in [[M100_Band3#Obtaining the Data]]. An overview of the 7m data and its calibration is located at [[M100_Band3]].<br />
<br />
To obtain the '''Total Power image''' M100_TP_CO_cube.bl.image, either run the [[M100_Band3_SingleDish_4.5]] guide to calibrate and image the Total Power data or download the image file from M100_ACA_ReferenceImages.tgz. How to obtain the data is described in [[M100_Band3#Obtaining the Data]]. An overview of the Total Power data and its calibration is located at [[M100_Band3]].<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
= Combine and Image the 7m+12m Interferometric Data =<br />
<br />
<br />
== Split off CO spectral windows (SPWs) ==<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf m100_*m.ms.listobs')<br />
listobs('M100_Band3_12m_CalibratedData.ms',listfile='M100_12m.ms.listobs')<br />
listobs('M100_Band3_7m_CalibratedData.ms',listfile='M100_7m.ms.listobs')<br />
</source><br />
<br />
Running the task "listobs" provides the setups used in the observations at a glance. Below are the first target scans of the 12m and 7m observations and the spectral window tables as generated by listobs; these are excerpts from the complete files obtained in each case. Notice that the six 7m data sets were taken with two slightly different correlator setups (one with four SPWs and the other with two SPWs), so the concatenated data set has six total SPWs. <br />
<br />
12m data:<br />
<pre style="background-color: #fffacd;"><br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
10-Aug-2011/19:38:05.8 - 19:50:22.8 11 1 M100 1500 [0,1,2,3] [6.05, 6.05, 6.05, 6.05] [CALIBRATE_WVR#ON_SOURCE,OBSERVE_TARGET#ON_SOURCE]<br />
<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs<br />
0 3840 TOPO 113726.419 488.281 1875000.0 114663.6750 1 XX YY<br />
1 3840 TOPO 111851.419 488.281 1875000.0 112788.6750 2 XX YY<br />
2 3840 TOPO 103663.431 -488.281 1875000.0 102726.1750 3 XX YY<br />
3 3840 TOPO 101850.931 -488.281 1875000.0 100913.6750 4 XX YY<br />
</pre><br />
<br />
<br />
7m data:<br />
<pre style="background-color: #fffacd;"><br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
17-Mar-2013/04:44:04.3 - 04:50:43.7 11 1 M100 261 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
<br />
Spectral Windows: (6 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs<br />
0 ALMA_RB_03#BB_1#SW-01#FULL_RES 4080 TOPO 101945.850 -488.281 1992187.5 100950.0000 1 XX YY<br />
1 ALMA_RB_03#BB_2#SW-01#FULL_RES 4080 TOPO 103761.000 -488.281 1992187.5 102765.1500 2 XX YY<br />
2 ALMA_RB_03#BB_3#SW-01#FULL_RES 4080 TOPO 111811.300 488.281 1992187.5 112807.1500 3 XX YY<br />
3 ALMA_RB_03#BB_4#SW-01#FULL_RES 4080 TOPO 113686.300 488.281 1992187.5 114682.1500 4 XX YY<br />
4 ALMA_RB_03#BB_1#SW-01#FULL_RES 4080 TOPO 111798.250 488.281 1992187.5 112794.1000 1 XX YY<br />
5 ALMA_RB_03#BB_2#SW-01#FULL_RES 4080 TOPO 113673.250 488.281 1992187.5 114669.1000 2 XX YY<br />
</pre><br />
<br />
<figure id="12m_mosaic.png"><br />
[[Image:12m_mosaic.png|300px|thumb|right|<caption>FOV of 12m mosaic.</caption>]]<br />
</figure><br />
<br />
<figure id="7m_mosaic.png"><br />
[[Image:7m_mosaic.png|300px|thumb|right|<caption>FOV of 7m mosaic.</caption>]]<br />
</figure><br />
<br />
Examination of the listobs files shows that the CO is in SPW='0' for the 12m data and in SPW='3,5' for the 7m data. There are two SPWs containing CO in the 7m data due to the slightly differing correlator setups.<br />
<br />
Also note that the integration time per visibility (average interval parameter in listobs) is different:<br />
6.05s for the 12m data and 10.1s for the 7m. This will be important to know later when we check the visibility weights. <br />
<br />
Next we split out the CO spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_12m_CO.ms')<br />
split(vis='M100_Band3_12m_CalibratedData.ms',<br />
outputvis='M100_12m_CO.ms',spw='0',field='M100',<br />
datacolumn='data',keepflags=False)<br />
os.system('rm -rf M100_7m_CO.ms')<br />
split(vis='M100_Band3_7m_CalibratedData.ms',<br />
outputvis='M100_7m_CO.ms',spw='3,5',field='M100',<br />
datacolumn='data',keepflags=False)<br />
</source><br />
<br />
Also of interest is that the 12m data has 47 fields and the 7m has 23 fields (not shown in the excerpts above). The difference in number of pointings is because the 7m antennas have a FWHP (full width half power) primary beam diameter that is 12/7 times larger than the 12m antennas. '''One easy way to see how the mosaics compare is to install the AnalysisUtils package (see [[Analysis_Utilities]] for information on how to download and import AnalysisUtils)'''. Then with AnalysisUtils you can make the following plots (look at the listobs to obtain the sourceid):<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf *m_mosaic.png')<br />
au.plotmosaic('M100_12m_CO.ms',sourceid='0',figfile='12m_mosaic.png')<br />
au.plotmosaic('M100_7m_CO.ms',sourceid='0',figfile='7m_mosaic.png')<br />
</source><br />
<br />
We see that the mosaics cover a common area but that the 7m mosaic is a bit larger. This means that the outer edges of the combined mosaic will be noisier than expected if they overlapped perfectly; this is just something to keep in mind. If you had the case where the mosaic coverages are dramatically different, it would be best to exclude the completely non-overlapping fields from the combination.<br />
<br />
NOTE: At this stage one would typically do continuum subtraction (if there is any). However we already know from the individual data reductions that the 3mm continuum emission is quite weak and does not significantly contribute to a 5km/s channel, so we will forgo the the continuum subtraction step. Examples of how to do this if you are so inclined are located in various other ALMA CASAguides.<br />
<br />
== Checking the weights and concatenating the data ==<br />
<br />
<figure id="7m_WT.png"><br />
[[File:12m_WT.png|200px|thumb|right|<caption> 12m weights.</caption>]]<br />
</figure><br />
<br />
<figure id="12m_WT.png"><br />
[[File:7m_WT_update.png|200px|thumb|right|<caption> 7m weights.</caption>]]<br />
</figure><br />
<br />
When combining data with disparate properties it is very important that the relative weights of each visibility be in the correct proportion to the other data according to the radiometer equation. Formally, the<br />
visibility weights should be proportional to 1/sigma<sup>2</sup> where sigma is the variance or rms noise of a given visibility.<br />
<br />
The rms noise in a single channel for a single visibility is:<br />
<br />
<math> <br />
\sigma_{ij} (Jy) =\frac{2k}{\eta_{q}\eta_{c}A_{eff}} <br />
</math><br />
<math> <br />
\sqrt{\frac{T_{sys,i} T_{sys,j}}{2\Delta\nu_{ch} t_{ij}}}<br />
</math><br />
<math> <br />
\times 10^{26},<br />
</math><br />
<br />
where:<br />
<br />
''k'' is Boltzmann's constant. <br />
<br />
''A<sub>eff</sub>'' is the effective antenna area which is equal to the aperture efficiency x the geometric area of the antenna. The aperture efficiency depends on the rms antenna surface accuracy. <br />
<br />
''&eta;<sub>q</sub>'' and ''&eta;<sub>c</sub>'' are the quantization and correlator efficiencies, respectively. These have values near 1 and will be ignored for the purposes of this casaguide, but see the ALMA Technical Handbook for more information.<br />
<br />
''T<sub>sys,i</sub>'' is the system temperature for antenna i, and ''T<sub>sys,j</sub>'' is the system temperature for antenna j<br />
<br />
''&Delta;&nu;<sub>ch</sub>'' is the channel frequency width.<br />
<br />
''t<sub>ij</sub>'' is the integration time per visibility. <br />
<br />
As of CASA 4.3.1, weights are initially scaled by 2&Delta;&nu;<sub>ch</sub>&Delta;t<sub>ij</sub>, and after the Tsys table applycal step of the calibration process, it further scales the weights by 1/[(Tsys(i) * Tsys(j)] as long as calwt=True. In the subsequent amplitude gain calibration table applycal step of the calibration, the weights are further scaled by a factor of [gain(i)<sup>2</sup> * gain(j)<sup>2</sup>] if calwt=True. This step up-weights data from the best performing antennas from the gain point of view, and importantly for data combination, makes the weights correctly proportional to the antenna size. <br />
<br />
In the calibration scripts for all executions of the 12m and 7m data, both applycal steps set calwt=True. To verify that the weights come out as expected, we plot the weights of the 7m and 12m data and measure their ratio to be, on average, 7m/12m ~ 0.055/0.3 ~ 0.18. Note that in the plots the points are colored by SPW, so there is only one 12m CO SPW but there are two 7m CO SPWs, and that no averaging can be turned on when plotting the weights. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 7m_WT.png 12m_WT.png')<br />
plotms(vis='M100_12m_CO.ms',yaxis='wt',xaxis='uvdist',spw='0:200',<br />
coloraxis='spw',plotfile='12m_WT.png', showgui = True)<br />
#<br />
plotms(vis='M100_7m_CO.ms',yaxis='wt',xaxis='uvdist',spw='0~1:200',<br />
coloraxis='spw',plotfile='7m_WT.png', showgui = True)<br />
</source><br />
<br />
<figure id="combine_CO_WT.png"><br />
[[File:combine_CO_WT_update.png|200px|thumb|right|<caption> 7m and 12m weights after concatenation.</caption>]]<br />
</figure><br />
<br />
The two key things that are different between the 7m and 12m-array data are that the effective dish areas are different by (7/12)<sup>2</sup>, and the integration times are different by (10.1/6.05). Since the dish area and the integration time per visibility are in the denominator of the radiometer equation, and assuming the weight of an individual visibility is proportional to 1/sigma<sup>2</sup>, the ratio of the weights should be (7./12.)<sup>4</sup> x (10.1/6.05) = 0.19. This is very close to the value we measure for the ratio of the weights, particularly given that the 7m flux calibration relied on a source which changed substantially over the course of the six 7m-array observations. <br />
<br />
Now concatenate the two data sets and plot the concatenated weights to verify that they are as expected.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Concat and scale weights<br />
os.system('rm -rf M100_combine_CO.ms')<br />
concat(vis=['M100_12m_CO.ms','M100_7m_CO.ms'],<br />
concatvis='M100_combine_CO.ms')<br />
<br />
# In CASA<br />
os.system('rm -rf combine_CO_WT.png')<br />
plotms(vis='M100_combine_CO.ms',yaxis='wt',xaxis='uvdist',spw='0~2:200',<br />
coloraxis='spw',plotfile='combine_CO_WT.png', showgui = True)<br />
</source><br />
<br />
Here, we create more instructive plots of the combined data to check that things are in order. (''Let each plot finish before cutting and pasting next plot. If plotms gui disappears, exit CASA and restart.'')<br />
<br />
<figure id="M100_combine_vel.png"><br />
[[File:M100_combine_vel_update.png|200px|thumb|right|<caption> Amplitude as a function of velocity.</caption>]]<br />
</figure><br />
<br />
One way to assess the relative noise in the combined data is to plot amplitude as a function of uv-distance. Here, it's clear that the 7m data is noisier than the 12m data (note also that this plot is not shown):<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_uvdist.png')<br />
plotms(vis='M100_combine_CO.ms',yaxis='amp',xaxis='uvdist',spw='', avgscan=True,<br />
avgchannel='5000', coloraxis='spw',plotfile='M100_combine_uvdist.png', showgui = True) <br />
</source><br />
<br />
A fairer comparison of these data is achieved by isolating the brightest line channels in individual 12m and 7m data sets (i.e., not the concatenated data sets) and comparing only those channels in amplitude vs. uv-distance. Here the agreement is better, as it is less dominated by the scatter among the several 7m executions.<br />
<br />
To plot the CO line as a function of velocity (this plot takes a while):<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_vel.png')<br />
plotms(vis='M100_combine_CO.ms',yaxis='amp',xaxis='velocity',spw='', avgtime='1e8',avgscan=True,coloraxis='spw',avgchannel='5',<br />
transform=True,freqframe='LSRK',restfreq='115.271201800GHz', plotfile='M100_combine_vel.png', showgui = True)<br />
</source><br />
<br />
To see each spectral window independently in plotms, run the command again but remove the call to "plotfile" and add " iteraxis='spw' ".<br />
<br />
== Image The Combined Data ==<br />
<br />
The commands in this section enable the user to choose between interactive cleaning -- i.e., building your own cleaning mask -- and using a provided mask to do the cleaning. Imaging this data requires using the imagemode='mosaic' mode of clean. This mode automatically calculates the correct convolution of the primary beam response of the mosaic when different antenna dish diameters are present. '''NOTE:''' even if these data had only been comprised of a single pointing of 7m and 12m-array data, the imagemode='mosaic' mode would be needed to correctly image data with different antenna sizes.<br />
<br />
Any time it is necessary to enter a long series of commands, typing '''cpaste''' before the start of the series and '''--''' at the end of the series lets CASA know that there are more commands coming. This can be very helpful when needing to cut and paste a lot of lines at once. These commands are not explicitly included in any of the sets of commands below, but they can be applicable for any of them. <br />
<br />
=== Define Parameters ===<br />
<br />
<source lang="python"><br />
<br />
### Define clean parameters<br />
vis='M100_combine_CO.ms'<br />
prename='M100_combine_CO_cube'<br />
myimage=prename+'.image'<br />
imsize=[540,600]<br />
cell='0.5arcsec'<br />
minpb=0.2<br />
restfreq='115.271201800GHz'<br />
outframe='LSRK'<br />
spw='0~2:1500~2500'<br />
width='5km/s'<br />
start='1400km/s'<br />
nchan=70<br />
robust=0.5<br />
phasecenter='J2000 12h22m54.3 +15d48m46.7'<br />
scales=[0]<br />
smallscalebias=0.6<br />
thresh=0.04502129927277565<br />
<br />
</source><br />
<br />
=== Interactive Cleaning ===<br />
<br />
To create your own clean mask, run the following clean command with interactive=True. <br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf M100_combine_CO_cube*')<br />
clean(vis=vis,imagename='M100_combine_CO_cube',<br />
imagermode='mosaic',ftmachine='mosaic',minpb=minpb,<br />
imsize=imsize,cell=cell,spw=spw,<br />
weighting='briggs',robust=robust,phasecenter=phasecenter,<br />
mode='velocity',width=width,start=start,nchan=nchan,<br />
restfreq=restfreq,outframe=outframe,veltype='radio',<br />
multiscale=scales,smallscalebias=smallscalebias,<br />
interactive = True,<br />
niter = 10000,threshold = str(thresh) +'Jy/beam')<br />
<br />
</source><br />
<br />
The viewer will pop up and allow you to draw regions around emission (or absorption!) peaks that you believe to be real. The tools for drawing elliptical, rectangular, or polygonal regions are located at the top of the viewer window. You have the option to clean "all channels" or a "single channel" at a time; for M100, where the emission moves spatially from channel to channel, make sure to select the option to clean one channel at a time. Click through the channels with the channel iterator on the right in the viewer window to draw per channel clean boxes. Once you're satisfied with the boxes drawn in each channel, click the green arrow button to continue to the next major cycle of cleaning. Iterate through this process until the residual image returned looks like noise. You'll need several iterations of this process. <br />
<br />
Once you're satisfied that you have cleaned all of the emission that needs cleaning, hit the red X to finish the process. The outputs of clean include several useful image cubes: the cleaned image (.image), the final mask created from all of your rounds of cleaning (.mask), the map of all of the clean components used in the model (.model), the beam (.psf), and the residuals remaining after all of your rounds of clean (.residual).<br />
<br />
Another option: instead of starting your own mask from scratch, you could also use the provided mask as a starting place to do interactive cleaning. It is possible to "reuse" and change a mask anytime you create one. To use the provided mask, M100_combine_CO_provided.mask, as a starting place, use the following command with interactive=True. <br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf M100_combine_CO_cube*')<br />
clean(vis=vis,imagename='M100_combine_CO_cube',<br />
imagermode='mosaic',ftmachine='mosaic',minpb=minpb,<br />
imsize=imsize,cell=cell,spw=spw,<br />
weighting='briggs',robust=robust,phasecenter=phasecenter,<br />
mode='velocity',width=width,start=start,nchan=nchan,<br />
restfreq=restfreq,outframe=outframe,veltype='radio',<br />
multiscale=scales,smallscalebias=smallscalebias,<br />
mask = 'M100_combine_CO_provided.mask',<br />
interactive = True,<br />
niter = 10000,threshold = str(thresh) +'Jy/beam')<br />
<br />
</source><br />
<br />
=== Non-Interactive Cleaning ===<br />
<br />
If you would instead prefer to use the provided per channel mask, M100_combine_CO_provided.mask, you can find it in your directory. In this case, the mask file is specified and the clean command uses interactive=False.<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf M100_combine_CO_cube*')<br />
clean(vis=vis,imagename='M100_combine_CO_cube',<br />
imagermode='mosaic',ftmachine='mosaic',minpb=minpb,<br />
imsize=imsize,cell=cell,spw=spw,<br />
weighting='briggs',robust=robust,phasecenter=phasecenter,<br />
mode='velocity',width=width,start=start,nchan=nchan,<br />
restfreq=restfreq,outframe=outframe,veltype='radio',<br />
multiscale=scales,smallscalebias=smallscalebias,<br />
mask = 'M100_combine_CO_provided.mask',<br />
interactive = False,<br />
niter = 10000,threshold = str(thresh) +'Jy/beam')<br />
<br />
</source><br />
<br />
== Image Analysis for the 7m+12m Data ==<br />
<br />
=== Moment Maps for 7m+12m CO (1-0) Cube ===<br />
<br />
Start by examining the final image cube. Determine the start and stopping channels for the line emission -- this will be used in the "chans" parameter of immoments.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('M100_combine_CO_cube.image')<br />
</source><br />
<br />
Next determine the rms noise per channel and use that to exclude pixels from the moment images. All images are shown in the gallery at the end of the following section.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myimage='M100_combine_CO_cube.image'<br />
chanstat=imstat(imagename=myimage,chans='4')<br />
rms1= chanstat['rms'][0]<br />
chanstat=imstat(imagename=myimage,chans='66')<br />
rms2= chanstat['rms'][0]<br />
rms=0.5*(rms1+rms2)<br />
print 'rms in a channel = '+str(rms) <br />
</source><br />
<br />
Next make the moment maps. For the integrated intensity: moment 0, a 2 sigma cut often considerably improves the appearance of the image with little effect on the integrated intensity as long as emission free channels are excluded. For higher order moments it is necessary to exclude all low S/N data. Typically 5-6 sigma for the higher moments works well. We also apply further masking based on the .flux image because the edges of the combined mosaic are especially noisy because the 7m mosaic is somewhat larger than the 12m mosaic as described above (see Figures 1 & 2). <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom0')<br />
immoments(imagename = 'M100_combine_CO_cube.image',<br />
moments = [0],<br />
axis = 'spectral',chans = '9~61',<br />
mask='M100_combine_CO_cube.flux>0.3',<br />
includepix = [rms*2,100.],<br />
outfile = 'M100_combine_CO_cube.image.mom0')<br />
<br />
os.system('rm -rf M100_combine_CO_cube.image.mom1')<br />
immoments(imagename = 'M100_combine_CO_cube.image',<br />
moments = [1],<br />
axis = 'spectral',chans = '9~61',<br />
mask='M100_combine_CO_cube.flux>0.3',<br />
includepix = [rms*5.5,100.],<br />
outfile = 'M100_combine_CO_cube.image.mom1')<br />
<br />
</source><br />
<br />
Now we can make some figures showing the moment maps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom*.png')<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom0',<br />
'range': [-0.3,25.],'scaling': -1.3,'colorwedge': T}],<br />
zoom={'blc': [48,46],'trc': [488,569]},<br />
out='M100_combine_CO_cube.image.mom0.png')<br />
<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom1',<br />
'range': [1440,1695],'colorwedge': T}],<br />
zoom={'blc': [48,46],'trc': [488,569]}, <br />
out='M100_combine_CO_cube.image.mom1.png')<br />
<br />
</source><br />
<br />
If you plan to use your moment 0 image to make measurements, it needs to be primary beam corrected first. First we need to subimage the .flux cube to extract a single plane that can be used to primary beam correct the moment 0 image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.flux.1ch')<br />
imsubimage(imagename='M100_combine_CO_cube.flux',<br />
outfile='M100_combine_CO_cube.flux.1ch',<br />
chans='35')<br />
</source><br />
<br />
Next, primary beam correct the moment 0 image. This is the version that would be used for measurements, though the uncorrected one can be useful for figures. The difference is clear in the images seen below in the following section.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom0.pbcor')<br />
immath(imagename=['M100_combine_CO_cube.image.mom0', \<br />
'M100_combine_CO_cube.flux.1ch'],<br />
expr='IM0/IM1',<br />
outfile='M100_combine_CO_cube.image.mom0.pbcor')<br />
</source><br />
<br />
Have a look at the difference the primary beam correction makes. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom0',<br />
'range': [-0.3,25.],'scaling': -1.3},<br />
{'file': 'M100_combine_CO_cube.image.mom0.pbcor',<br />
'range': [-0.3,25.],'scaling': -1.3}],<br />
zoom={'blc': [48,46],'trc': [488,569]})<br />
</source><br />
<br />
With the viewer open, you can flip back and forth between the images to compare them. Next, make a figure.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom0.pbcor.png')<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom0.pbcor',<br />
'range': [-0.3,25.],'scaling': -1.3,'colorwedge': T}],<br />
zoom={'blc': [48,46],'trc': [488,569]},<br />
out='M100_combine_CO_cube.image.mom0.pbcor.png')<br />
<br />
</source><br />
<br />
=== Comparison with 7m, 12m Moment Maps ===<br />
<br />
Below the moment maps from the 7m-only and the 12m-only data are shown for comparison. The moment maps were made using clean masks drawn by hand. Details on the creation of these images (masking, thresholding, and the number of iterations of clean) can be found within the 12m and 7m imaging scripts available with the downloaded package. The range and scaling for the 12m-only figures are the same as that used for the 7m+12m figures for ease of comparison.<br />
<br />
As expected, the 7m+12m image shows considerably more extended emission than the 12m-only data and finer detail than the 7m-only data. For comparison, the 7m+12m synthesized beam is 3.82"x2.55", while the 12m-only beam is 3.46"x2.37" and the 7m-only beam is 12.72"x10.12".<br />
<br />
<gallery widths=300px heights=300px><br />
File:12m.png | Moment 0 for 12m data alone (no primary beam correction).<br />
File:7m_mom0.png | Moment 0 for 7m data alone (no primary beam correction).<br />
File:combined.png | Moment 0 for 12m+7m data (no primary beam correction).<br />
File:combine_pbcor.png | Moment 0 for 12m+7m data with primary beam correction.<br />
</gallery><br />
<br />
<gallery widths=300px heights=300px><br />
File:12m_mom1.png | Moment 1 for 12m data alone.<br />
File:7m_mom1.png | Moment 1 for 7m data alone.<br />
File:combine_mom1.png | Moment 1 for 12m+7m data.<br />
</gallery><br />
<br />
=== Convert 7m+12m Images to Fits Format ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf *.fits')<br />
exportfits(imagename='M100_combine_CO_cube.image',fitsimage='M100_combine_CO_cube.image.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.flux',fitsimage='M100_combine_CO_cube.flux.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.image.mom0',fitsimage='M100_combine_CO_cube.image.mom0.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.image.mom0.pbcor',fitsimage='M100_combine_CO_cube.image.mom0.pbcor.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.image.mom1',fitsimage='M100_combine_CO_cube.image.mom1.fits')<br />
<br />
</source><br />
<br />
= Feathering the Total Power and 7m+12m Interferometric Images =<br />
<br />
In this section the interferometric (7m+12m) image produced above is combined with the Total Power (single dish) image.<br />
The "feather" algorithm is employed, in which the two images are combined in the spatial frequency domain, i.e.,<br />
the low and high spatial frequency components are predominantly taken from the TP and interferometric images, respectively.<br />
<br />
== Prepare Images for Feathering ==<br />
<br />
Regrid the TP image to match the shape of the 7m+12m image using the task {{imregrid}}.<br />
The TP image is resampled onto the same grid as that of the "template" 7m+12m image along the first two axes of the cube (i.e., RA and Dec; it is not necessary to regrid the velocity axis, since the axis is already common to the both images).<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_TP_CO_cube.regrid')<br />
imregrid(imagename='M100_TP_CO_cube.bl.image',<br />
template='M100_combine_CO_cube.image',<br />
axes=[0, 1],<br />
output='M100_TP_CO_cube.regrid')<br />
</source><br />
<br />
Now we trim the 7m+12m and (regridded) TP images, in order to exclude the regions masked by the {{clean}} task with minpb=0.2 and/or noisy edge regions in the TP image. The {{viewer}} task can be used to determine the trimming box. Here we use (x, y) = (48,46) and (488,569) [pixels] as the bottom-left and top-right corners, respectively, and set these values to the "box" parameter of the {{imsubimage}} task.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim')<br />
imsubimage(imagename='M100_TP_CO_cube.regrid',<br />
outfile='M100_TP_CO_cube.regrid.subim',<br />
box='48,46,488,569')<br />
os.system('rm -rf M100_combine_CO_cube.image.subim')<br />
imsubimage(imagename='M100_combine_CO_cube.image',<br />
outfile='M100_combine_CO_cube.image.subim',<br />
box='48,46,488,569')<br />
</source><br />
<br />
While the 7m+12m image (before the primary-beam correction) has non-uniform primary beam response (i.e., lower response in the outskirts of the mosaic field), the TP image does not have such non-uniformity.<br />
In order to feather the TP and 7m+12m images together, they should have the common response on the sky.<br />
Hence we need to multiply the TP image by the 7m+12m primary beam response before proceeding.<br />
To do this, create the subimage of the 7m+12m response,<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_combine_CO_cube.flux.subim')<br />
imsubimage(imagename='M100_combine_CO_cube.flux',<br />
outfile='M100_combine_CO_cube.flux.subim',<br />
box='48,46,488,569')<br />
</source><br />
<br />
then multiply it and the TP image using the task {{immath}}.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.depb')<br />
immath(imagename=['M100_TP_CO_cube.regrid.subim',<br />
'M100_combine_CO_cube.flux.subim'],<br />
expr='IM0*IM1',<br />
outfile='M100_TP_CO_cube.regrid.subim.depb')<br />
</source><br />
<br />
As a result, the feathered image will have the same response as that of the 7m+12m image.<br />
The primary-beam correction can be done after the feathering process (see below).<br />
<br />
== Feather TP Cube with 7m+12m Cube ==<br />
<br />
Now we are ready to execute the {{feather}} task to combine the TP and 7m+12m images.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_Feather_CO.image')<br />
feather(imagename='M100_Feather_CO.image',<br />
highres='M100_combine_CO_cube.image.subim',<br />
lowres='M100_TP_CO_cube.regrid.subim.depb')<br />
</source><br />
<br />
The task produces the combined image in the following way:<br />
* Convert the input images specified by the "highres" and "lowres" parameters onto the spatial frequency plane.<br />
* Combine them on the spatial frequency plane. The weighting is determined by the beam sizes/shapes of the input images.<br />
* Convert it back to the image plane.<br />
Please refer to the online help and documents for the details.<br />
<br />
== Make Moment Maps of the Feathered Images ==<br />
<br />
We will use the same technique as the [[#Moment_Maps_for_7m.2B12m_CO_.281-0.29_Cube|7m+12m image analysis above]] to make moment maps.<br />
<br />
First (but optionally; this is solely for comparison to the feathered images and not needed to create the final feathered images), make moment maps for the (regridded) TP image.<br />
<br />
<source lang="python"><br />
#In CASA<br />
myimage = 'M100_TP_CO_cube.regrid.subim'<br />
chanstat = imstat(imagename=myimage,chans='4')<br />
rms1 = chanstat['rms'][0]<br />
chanstat = imstat(imagename=myimage,chans='66')<br />
rms2 = chanstat['rms'][0]<br />
rms = 0.5*(rms1+rms2) <br />
<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.mom0')<br />
immoments(imagename='M100_TP_CO_cube.regrid.subim',<br />
moments=[0],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*2., 50],<br />
outfile='M100_TP_CO_cube.regrid.subim.mom0')<br />
<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.mom1')<br />
immoments(imagename='M100_TP_CO_cube.regrid.subim',<br />
moments=[1],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*5.5, 50],<br />
outfile='M100_TP_CO_cube.regrid.subim.mom1')<br />
<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.mom*.png')<br />
imview(raster=[{'file': 'M100_TP_CO_cube.regrid.subim.mom0',<br />
'range': [0., 1080.],<br />
'scaling': -1.3,<br />
'colorwedge': T}],<br />
out='M100_TP_CO_cube.regrid.subim.mom0.png')<br />
<br />
imview(raster=[{'file': 'M100_TP_CO_cube.regrid.subim.mom1',<br />
'range': [1440, 1695],<br />
'colorwedge': T}], <br />
out='M100_TP_CO_cube.regrid.subim.mom1.png')<br />
</source><br />
<br />
Then make moment maps for the feathered image.<br />
<br />
<source lang="python"><br />
#In CASA<br />
myimage = 'M100_Feather_CO.image'<br />
chanstat = imstat(imagename=myimage,chans='4')<br />
rms1 = chanstat['rms'][0]<br />
chanstat = imstat(imagename=myimage,chans='66')<br />
rms2 = chanstat['rms'][0]<br />
rms = 0.5*(rms1+rms2) <br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom0')<br />
immoments(imagename='M100_Feather_CO.image',<br />
moments=[0],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*2., 50],<br />
outfile='M100_Feather_CO.image.mom0')<br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom1')<br />
immoments(imagename='M100_Feather_CO.image',<br />
moments=[1],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*5.5, 50],<br />
outfile='M100_Feather_CO.image.mom1')<br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom*.png')<br />
imview(raster=[{'file': 'M100_Feather_CO.image.mom0',<br />
'range': [-0.3, 25.],<br />
'scaling': -1.3,<br />
'colorwedge': T}],<br />
out='M100_Feather_CO.image.mom0.png')<br />
<br />
imview(raster=[{'file': 'M100_Feather_CO.image.mom1',<br />
'range': [1440, 1695],<br />
'colorwedge': T}], <br />
out='M100_Feather_CO.image.mom1.png')<br />
</source><br />
<br />
=== Correct the Primary Beam Response ===<br />
<br />
Apply the primary beam response to the feathered image using the task {{immath}},<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_Feather_CO.image.pbcor')<br />
immath(imagename=['M100_Feather_CO.image',<br />
'M100_combine_CO_cube.flux.subim'],<br />
expr='IM0/IM1',<br />
outfile='M100_Feather_CO.image.pbcor')<br />
</source><br />
<br />
and also to the moment 0 image.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_combine_CO_cube.flux.1ch.subim')<br />
imsubimage(imagename='M100_combine_CO_cube.flux.subim',<br />
outfile='M100_combine_CO_cube.flux.1ch.subim',<br />
chans='35')<br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom0.pbcor')<br />
immath(imagename=['M100_Feather_CO.image.mom0',<br />
'M100_combine_CO_cube.flux.1ch.subim'],<br />
expr='IM0/IM1',<br />
outfile='M100_Feather_CO.image.mom0.pbcor')<br />
</source><br />
<br />
Save the primary-beam corrected moment 0 image to a PNG file.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_Feather_CO.image.mom0.pbcor.png')<br />
imview(raster=[{'file': 'M100_Feather_CO.image.mom0.pbcor',<br />
'range': [-0.3, 25.],<br />
'scaling': -1.3,<br />
'colorwedge': T}],<br />
out='M100_Feather_CO.image.mom0.pbcor.png')<br />
</source><br />
<br />
=== Compare the Various Images ===<br />
<br />
Now we compare all the images:<br />
<br />
<gallery perrow=3 widths=300px heights=300px><br />
File:12m_pbcor.png | Primary beam corrected moment 0 for the 12m data.<br />
File:7m_pbcor.png | Primary beam corrected moment 0 for the 7m data.<br />
File:TP_CO_cube_Jy.regrid.subim.mom0.png | Moment 0 for the TP data.<br />
File:combine_pbcor.png | Primary beam corrected moment 0 for 7m+12m data.<br />
File:M100_Feather_CO.mom0.pbcor.png | Primary beam corrected moment 0 for TP+7m+12m data.<br />
</gallery><br />
<br />
<gallery perrow=3 widths=300px heights=300px><br />
File:12m_mom1.png | Moment 1 for 12m data.<br />
File:7m_mom1.png | Moment 1 for 7m data.<br />
File:TP_CO_cube_Jy.regrid.subim.mom1.png | Moment 1 for the TP data.<br />
File:combine_mom1.png | Moment 1 for 7m+12m data.<br />
File:M100_Feather_CO.mom1.png | Moment 1 for TP+7m+12m data.<br />
</gallery><br />
<br />
You can see that more extended emission is recovered by adding the TP data to the interferometric data.<br />
<br />
For quantitative comparison, we measure the total line fluxes of the various images.<br />
The task {{imstat}} can be used to do this.<br />
For example, for the subimage of the 7m+12m image,<br />
<br />
<source lang="python"><br />
#In CASA<br />
imstat('M100_combine_CO_cube.image.subim')<br />
</source><br />
<br />
yields the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '12:23:01.990, +15.46.39.692, I, 1.14733e+11Hz',<br />
'flux': array([ 1031.66933033]),<br />
'max': array([ 0.67689651]),<br />
'maxpos': array([195, 312, 0, 49], dtype=int32),<br />
'maxposf': '12:22:55.235, +15.49.15.700, I, 1.14639e+11Hz',<br />
'mean': array([ 0.00060066]),<br />
'medabsdevmed': array([ 0.00857783]),<br />
'median': array([-0.00013253]),<br />
'min': array([-0.0872678]),<br />
'minpos': array([273, 316, 0, 25], dtype=int32),<br />
'minposf': '12:22:52.533, +15.49.17.700, I, 1.14685e+11Hz',<br />
'npts': array([ 15434710.]),<br />
'q1': array([-0.00867673]),<br />
'q3': array([ 0.00847944]),<br />
'quartile': array([ 0.01715617]),<br />
'rms': array([ 0.01700558]),<br />
'sigma': array([ 0.01699497]),<br />
'sum': array([ 9270.95406483]),<br />
'sumsq': array([ 4463.55839316]),<br />
'trc': array([440, 523, 0, 69], dtype=int32),<br />
'trcf': '12:22:46.746, +15.51.01.192, I, 1.146e+11Hz'}<br />
<br />
</pre><br />
<br />
The 'flux' value in the result is the total integrated line flux in Jy km/s. Note that these values are the ones obtained using the provided mask file and interactive=False cleaning. If you adjusted the masking of the 12m+7m cleaning run, your results may vary here. <br />
<br />
Similarly, the total line fluxes of the TP image (after multiplying the 7m+12m primary beam response), feathered image, and feathered image after the primary-beam correction are<br />
<br />
<source lang="python"><br />
#In CASA<br />
imstat('M100_TP_CO_cube.regrid.subim.depb')['flux']<br />
imstat('M100_Feather_CO.image')['flux']<br />
imstat('M100_Feather_CO.image.pbcor')['flux']<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
array([ 2934.61181467])<br />
array([ 2931.0992893])<br />
array([ 3402.22025601])<br />
</pre><br />
<br />
We see the followings from these values:<br />
* The flux recovered by the 7m+12m observations is about a third of the total flux (998/2931).<br />
* The feathering process preserves the flux of the TP data.<br />
* The flux of the primary-beam corrected feathered image is consistent with the values from the literature (2972 +/- 319 Jy km/s from the BIMA SONG; Helfer et al. 2003).<br />
<br />
{{Checked 4.5.2}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.5&diff=212513C286 Band6Pol Imaging for CASA 4.52017-04-04T17:04:38Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.5.'''<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.5]]''' 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', showgui = True)<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 />
interactive = True)<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.5 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', showgui = True)<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', showgui = True)<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.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.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.5&diff=212503C286 Band6Pol Calibration for CASA 4.52017-04-04T17:02:20Z<p>Jthorley: </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.5]]'''.<br />
<br />
'''This guide is designed for CASA 4.5.'''<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.5. 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.5.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=False)<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=False)<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=False)<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.5 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', showgui = True)<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.5#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 = True,<br />
flagbackup = False)<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 = True,<br />
flagbackup = False)<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 = True,<br />
flagbackup = False)<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=True, avgbaseline=True, avgtime='1e8', avgscan=True, coloraxis='spw', showgui = True)<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=True, avgchannel='128', coloraxis='field', spw='0', showgui = True)<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=True, avgchannel='128', avgtime='1e8', coloraxis='antenna1', showgui = True)<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.5 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.5#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=True, <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=True: 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=True,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=False)<br />
<br />
</source><br />
<br />
*calwt=True: 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=True, avgchannel='128', avgbaseline=True, coloraxis='corr', showgui = True)<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.5#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=True,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=False)<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', showgui = True)<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 />
showgui = True)<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=True,<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=True: 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=True,<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=True,<br />
correlation='XY,YX',<br />
spw='3', <br />
coloraxis='corr',<br />
plotrange=[-0.06,0.06,-0.06,0.06], <br />
showgui = True)<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, showgui = True)<br />
plotcal('3c286_Band6.ms.XY0','freq','phase',antenna='0',poln='X',subplot=122, showgui = True)<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=True)<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=True: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=True 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, showgui = True)<br />
plotcal('3c286_Band6.ms.G2.polcal','time','amp',field='J1337-1257',poln='/',subplot=122, showgui = True)<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], showgui = True)<br />
plotcal('3c286_Band6.ms.Df0','freq','amp', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,0,0.06], showgui = True)<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06], showgui = True)<br />
plotcal('3c286_Band6.ms.Df0','freq','real', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06], showgui = True)<br />
<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='0,1', iteration='antenna',subplot=231, plotrange=[223000,227000,-0.06,0.06], showgui = True)<br />
plotcal('3c286_Band6.ms.Df0','freq','imag', spw='2,3', iteration='antenna',subplot=231, plotrange=[239000,243000,-0.06,0.06], showgui = True)<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=True)<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=True, 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=True)<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=True,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=True)<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=True, <br />
coloraxis='corr', showgui = True)<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=True)<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=True: 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=True, plotrange=[-1,1,-1,1], <br />
coloraxis='corr', showgui = True)<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.5 |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.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.5&diff=21248AntennaeBand7 Imaging 4.52017-04-04T15:15:37Z<p>Jthorley: </p>
<hr />
<div>* '''This guide is designed for CASA 4.5.0. If you are using an older version of CASA please see [[AntennaeBand7_Imaging_4.3]].<br />
* '''This tutorial picks up where [[AntennaeBand7_Calibration_4.5]] leaves off: with fully calibrated, split science target measurement sets. If you wish to skip the Calibration guide: obtain the calibrated data from [[AntennaeBand7#Obtaining_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
* '''Details of the ALMA data are provided at [[AntennaeBand7]]'''.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
== Imaging Mosaics ==<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean, pause here and <br />
review for example http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
Mosaics like other kinds of images are created in the CASA task {{clean}}. To invoke mosaic mode, you simply set the parameter '''imagermode='mosaic''''. The default subparameter '''ftmachine='mosaic'''' is then automatically set. This is a joint deconvolution algorithm that works in the uv-plane. A convolution of the primary beam patterns for each pointing in the mosaic is created: the primary beam response function. The corresponding image of the mosaic response function will be called ''<imagename>.flux.pbcoverage'' and ''<imagename>.flux'' (where the latter differs from the former only if the sensitivity of each field in the mosaic varies).<br />
<br />
Well-sampled mosaics like the patterns observed for the Northern and Southern Antennae mosaics shown on the [[AntennaeBand7#ALMA_Data_Overview | Overview]] page are well-suited to joint deconvolution. However, if you have a poorly-sampled, or very irregular mosaic you may need to use the slower '''ftmachine='ft'''' which combines data in the image plane, similar to what is done in other packages like ''MIRIAD''. <br />
<br />
Additionally, for mosaics it is essential to pick the center of the region to be imaged explicitly using the '''phasecenter''' parameter. Otherwise it will default to the first pointing included in the '''field''' parameter -- since this is often at one corner of the mosaic, the image will not be centered. For the Northern mosaic, the center pointing corresponds to field id 12. Note that during the final '''split''' in the calibration section that selected only the Antennae fields, the field ids were renumbered, so that the original centers (shown in the [[AntennaeBand7#ALMA_Data_Overview | Overview]]) have changed: field id 14 becomes 12 for the Northern mosaic and field 18 becomes 15 for the Southern mosaic. You can also set an explicit coordinate (see the {{clean}} help for syntax).<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you want to learn more about mosaicing, pause here and <br />
review for example http://www.aoc.nrao.edu/events/synthesis/2010/lectures/jott-mosaicking-school-04.pdf<br />
</pre><br />
<br />
== Continuum Imaging ==<br />
<figure id="Antennae_South-AMPvsCH.png"><br />
[[File:Antennae_South-AMPvsCH.png|200px|thumb|right|<caption>Southern mosaic: Amplitude vs. channel. The CO(3-2) line is seen from 50 to 100</caption>]]<br />
</figure><br />
<figure id="Antennae_North-AMPvsCH.png"><br />
[[File:Antennae_North-AMPvsCH.png|200px|thumb|right|<caption>Northern mosaic: Amplitude vs. channel. The CO(3-2) line is seen from 70 to 100</caption>]]<br />
</figure><br />
<br />
We will make 345 GHz continuum images for the two regions covered by the mosaics. We use the task {{clean}} over the channels that are free of the line emission; we avoid the edge channels which tend to be noisier due to bandpass rolloff effects. The line-free channels are found by plotting the average spectrum (all fields). We find the CO(3-2) line from channels 50 to 100 in the southern mosaic (<xr id="Antennae_South-AMPvsCH.png"/>), and from 70 to 100 in the northern mosaic (<xr id="Antennae_North-AMPvsCH.png"/>). <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North-AMPvsCH.png')<br />
plotms(vis='Antennae_North.cal.ms',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=True,plotfile='Antennae_North-AMPvsCH.png', showgui = True)<br />
</source><br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South-AMPvsCH.png')<br />
plotms(vis='Antennae_South.cal.ms',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=True,plotfile='Antennae_South-AMPvsCH.png', showgui = True)<br />
</source><br />
<br />
The '''avgtime''' is set to a large value so that it averages over all the integrations, and '''avgscan''' is set to allow averaging of the different scans.<br />
<br />
Next we create continuum images from the line-free channels. <br />
<br />
==== Northern Continuum Mosaic ====<br />
<br />
For illustrative purposes we first make a dirty image to see if there is emission and what the exact beam size is. It should be on the order of 1" but this will vary a bit according to the uv-coverage in the actual data. We will start with a '''cell''' size of 0.2" to oversample the beam by a factor of 5. The '''imsize''' needs to be large enough given the cell size to comfortably encompass the mosaic. From the mosaic footprints shown in the [[AntennaeBand7#ALMA_Data_Overview | overview]], we can see that the Northern mosaic '''imsize''' needs to be about 1 arcmin. With 0.2" pixels, this requires '''imsize=300'''. <br />
<br />
Other essential {{clean}} parameters for this case include:<br />
*'''vis='Antennae_North.cal.ms' ''': The calibrated dataset on the science target. {{clean}} will always use the CORRECTED DATA column (if it exists).<br />
*'''imagename='Antennae_North.Cont.Dirty' ''': The base name of the output images:<br />
** <imagename>.image # the final restored image<br />
** <imagename>.flux # the effective primary beam response (where '''pbcor=True''')<br />
** <imagename>.flux.pbcoverage # the primary beam coverage ('''ftmachine=’mosaic’ ''' only)<br />
** <imagename>.model # the model image<br />
** <imagename>.residual # the residual image<br />
** <imagename>.psf # the synthesized (dirty) beam<br />
*'''spw='0:1~50;120~164' ''': To specify only the line-free channels of spectral window 0.<br />
*'''mode='mfs' ''': Multi-Frequency Synthesis: The default mode, which produces one image from all the specified data combined. This will grid each channel independently before imaging. For wide bandwidths this will give a far superior result compared to averaging the channels and then imaging. <br />
*'''restfreq='345.79599GHz' ''': The rest frequency of CO(3-2) can be found with [http://www.splatalogue.net/ splatalogue].<br />
*'''niter=0''': Maximum number of clean iterations. ('''niter=0 will do no cleaning''')<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.Cont.Dirty*')<br />
clean(vis='Antennae_North.cal.ms',imagename='Antennae_North.Cont.Dirty',<br />
field='',phasecenter='12',<br />
mode='mfs',restfreq='345.79599GHz',<br />
spw='0:1~50;120~164',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=300,cell='0.2arcsec',<br />
interactive=False,niter=0)<br />
</source><br />
<br />
The reported beam size is about 1.27" x 0.71" P.A. 86.142 degrees. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_North.Cont.Dirty.image')<br />
</source><br />
<br />
<!-- COMMENT OUT VIEWER VIDEO. UNCOMMENT WHEN A MORE UP-TO-DATE VIDEO IS AVAILABLE.<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the CASA viewer it is a good idea to pause here and watch the demo at <br />
http://casa.nrao.edu/CasaViewerDemo/casaViewerDemo.html<br />
</pre> --><br />
<br />
<figure id="North_cont_clean.png"><br />
[[Image:North_cont_clean.png|200px|thumb|right|<caption>Residual for Northern continuum mosaic after 100 iterations; the clean mask is shown by the white contour.</caption>]]<br />
</figure><br />
<br />
Yes there is definitely a detection in the vicinity of the Northern nucleus (see <xr id="North_contstat.png"/> and <xr id="Antennae_North.Cont.Clean.image.png"/> below). Using the square region icon, and drawing a box near but not including the emission, we find the rms noise is about 0.4 mJy/beam in the dirty image.<br />
<br />
Next we switch to refined values of '''cell='0.13arcsec' ''' and '''imsize=500''' based on the observed beam size. We also switch to interactive mode so that you can create a clean mask using the polygon tool (note you need to double click inside the polygon region to activate the mask). See [[TWHydraBand7_Imaging_3.4#Image_and_Self-Calibrate_the_Continuum | TWHya casaguide]] for a more complete description of interactive clean and mask creation. <br />
<br />
*'''niter=1000''': Maximum number of clean iterations -- '''we will stop interactively'''<br />
*'''threshold='0.4mJy' ''': Stop cleaning if the maximum residual is below this value (the dirty rms noise)<br />
*'''interactive=True''': Clean will be periodically interrupted to show the residual clean image. Interactive clean mask can be made. If no mask is created, no cleaning is done.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.Cont.Clean*')<br />
clean(vis='Antennae_North.cal.ms',imagename='Antennae_North.Cont.Clean',<br />
field='',phasecenter='12',<br />
mode='mfs',restfreq='345.79599GHz',<br />
spw='0:1~50;120~164',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=500,cell='0.13arcsec',<br />
interactive=True, <br />
niter=1000, threshold='0.4mJy')<br />
</source><br />
<br />
The residuals are "noise-like" after only 100 iterations (see <xr id="North_cont_clean.png"/>), so hit the red X symbol in the interactive window to stop cleaning here. <br />
<br />
Note that if you run the {{clean}} task again with the same '''imagename''', without deleting the existing <imagename>.* files, {{clean}} assumes that you want to continue cleaning the existing images. We put an <tt>rm</tt> command before the {{clean}} command to guard against this, but sometimes this is what you want.<br />
<br />
==== Southern Continuum Mosaic ====<br />
<br />
<figure id="South_cont_clean.png"><br />
[[Image:South_cont_clean.png|200px|thumb|right|<caption>Residual for Southern continuum mosaic after 100 iterations; the clean mask is shown by the white contour.</caption>]]<br />
</figure><br />
<br />
For the southern mosaic we modify the '''phasecenter''', mosaic '''imsize''', and the line-free channels ('''spw''') to be consistent for this mosaic. We also bypass the dirty image step we did above for the Northern mosaic. As above, the mosaic size can be judged from the [[AntennaeBand7#ALMA_Data_Overview | Overview]]. We expect the beam to be about the same and use the same '''cell''' size. During {{clean}}, we repeat the process of making a clean mask. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South.Cont.Clean*')<br />
clean(vis='Antennae_South.cal.ms',imagename='Antennae_South.Cont.Clean',<br />
field='',phasecenter='15',<br />
mode='mfs',restfreq='345.79599GHz',<br />
spw='0:1~30;120~164',<br />
imagermode='mosaic',<br />
imsize=750,cell='0.13arcsec',<br />
interactive=True, usescratch=False,<br />
niter=1000, threshold='0.4mJy')<br />
</source><br />
<br />
The beam size reported in the logger for the Southern mosaic: 1.11"x 0.71", and P.A.=65 deg; which is a little better than the beam for the North owing to better uv-coverage.<br />
<br />
Stop after 100 iterations (<xr id="South_cont_clean.png"/>).<br />
<br />
==== Image Statistics ====<br />
<br />
<figure id="North_contstat.png"><br />
[[File:North_contstat.png|200px|thumb|right|<caption>Example polygon for rms determination using the viewer.</caption>]]<br />
</figure><br />
<br />
<br />
You can determine statistics for the images using the task {{imstat}}:<br />
<source lang="python"><br />
# In CASA<br />
imstat('Antennae_North.Cont.Clean.image')<br />
imstat('Antennae_South.Cont.Clean.image')<br />
</source><br />
<br />
From this we find, that for the Northern continuum image the peak is 3.66 mJy/beam and the rms is 0.47 mJy/beam. For the Southern continuum we find a peak of 4.49 mJy/beam and an rms of 0.45 mJy/beam. <br />
<br />
However, the calculation of the rms comes with a couple of caveats. First, the mosaic primary beam response rolls off toward the edges of the mosaic, as do correspondingly the flux density and rms. Thus if you don't restrict the measurement to areas of full sensitivity, the apparent rms is skewed downward. Second, since there is real emission in the image, the rms will be skewed upward (with the error increasing with brighter emission). Both can be solved by picking boxes that exclude the edges of the mosaic and the real emission. <br />
<br />
It is often easier to use either the {{viewer}} directly or {{imview}} (a task wrapper for the {{viewer}}; see '''help imview''' for more info) to display the image and then interactively use the region tools to get the statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_North.Cont.Clean.image')<br />
</source><br />
<br />
Adjust colorscale using the middle mouse button (or reassign to a different mouse button by clicking on "plus" symbol icon). Next, select the polygon tool by clicking on its symbol with a mouse button. Then draw a region that avoids edges and emission (see <xr id="North_contstat.png"/>), then double click inside the polygon to have the statistic printed to the screen. You may measure an rms that differs by a few percent from the value reported by imstat.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_South.Cont.Clean.image')<br />
</source><br />
<br />
<figure id="Antennae_North.Cont.Clean.image.png"><br />
[[File:Antennae_North.Cont.Clean.image.png|200px|thumb|right|<caption>345 GHz continuum image of the northern mosaic made with {{imview}}.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.Cont.Clean.image.png"><br />
[[File:Antennae_South.Cont.Clean.image.png|200px|thumb|right|<caption>345 GHz continuum image of the southern mosaic made with {{imview}}.</caption>]]<br />
</figure><br />
<br />
Again, you may measure an rms slightly different than what we got from using {{imstat}} with no constraints. <br />
<br />
How does this compare to theory? You can find out using the [https://almascience.nrao.edu/call-for-proposals/sensitivity-calculator ALMA sensitivity calculator]. The continuum bandwidth of the Northern mosaic is about 1 GHz and about 0.85 GHz for the Southern mosaic. The number of antennas is about 12 and the time on a single pointing is about 300s. This yields an expected rms of about 1 mJy/beam. However, this needs to be decreased by about a factor of 2.5 near the center of the mosaic due to the hexagonal Nyquist sampling of the mosaic (radial spacing~0.37*HPBW) for a theoretical rms of about 0.4 mJy/beam, in good agreement with observation. <br />
<br />
Next make hardcopy plots of the continuum images using {{imview}}. To make the contrast a bit better, set the data range from -1 x sigma to the peak determined above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (<br />
raster={'file': 'Antennae_North.Cont.Clean.image',<br />
'colorwedge':T,'range':[-0.00048,0.00380]},<br />
zoom=1, out='Antennae_North.Cont.Clean.image.png')<br />
imview (<br />
raster={'file': 'Antennae_South.Cont.Clean.image',<br />
'colorwedge':T,'range':[-0.00050,0.00523]},<br />
zoom=1, out='Antennae_South.Cont.Clean.image.png')<br />
</source><br />
<br />
==Continuum subtraction ==<br />
<br />
In these data, the continuum emission is too weak to contaminate the line emission (i.e. the peak continuum emission is less than the rms noise in the spectral line channels). Nevertheless, for illustrative purposes we demonstrate how to subtract the continuum emission in the uv-domain using the task {{uvcontsub}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='Antennae_North.cal.ms',fitspw='0:1~50;120~164',fitorder = 1)<br />
# In CASA<br />
uvcontsub(vis='Antennae_South.cal.ms',fitspw='0:1~30;120~164',fitorder = 1)<br />
</source><br />
<br />
Here, '''fitspw''' gives the line-free channels for each mosaic and '''fitorder=1'''. Higher order fits are not recommended. If you do not have line-free channels on both sides of the line '''fitorder=0''' is recommended. The output MS will have ''.contsub'' appended to the name.<br />
<br />
== CO(3-2) Imaging ==<br />
<br />
<figure id="North_CO3_2_vel.png"><br />
[[Image:North_CO3_2_vel.png|thumb|<caption>Northern CO(3-2) uv-spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="South_CO3_2_vel.png"><br />
[[Image:South_CO3_2_vel.png|thumb|<caption>Southern CO(3-2) uv-spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for scientific analysis. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
To see what velocity parameters you want to set in {{clean}}, it is useful to make a plot in {{plotms}} in the desired output frame. Note these plots take a little longer because of the frame shift. In order to compare with recent SMA data, we chose LSRK, but it should be noted that many papers of this source are in the BARY frame. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf North_CO3_2_vel.png')<br />
plotms(vis='Antennae_North.cal.ms.contsub/',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=True,transform=True,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotfile='North_CO3_2_vel.png', showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf South_CO3_2_vel.png')<br />
plotms(vis='Antennae_South.cal.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=True,transform=True,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotfile='South_CO3_2_vel.png', showgui = True) <br />
</source><br />
<br />
==== Northern Mosaic ====<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel.<br />
<br />
Notable parameters included in the {{clean}} call are:<br />
*'''mode='velocity' ''','''outframe='LSRK' ''','''restfreq='345.79599GHz' '''. We use 'velocity' mode to set velocity information in the Local Standard of Rest frame (kinematic definition), and use the rest frequency of the CO(3-2) line.<br />
*'''nchan=60''','''start='1300km/s' ''','''width='10km/s' ''': To produce a data cube with 60 channels ("nchan"=60), starting at 1300km/s and with velocity widths of 10 km/s. That will include all the CO(3-2) emission in both mosaics.<br />
*'''imsize=500''','''cell='0.13arcsec' ''': An image size of 65 arcsec, with pixels of 0.13 arcsec (about one-fifth the minor axis of the synthesized beam). We make the imsize larger than the mosaic to increase the dirty beam image size, as the emission is quite extended along the mosaic. <br />
*'''weighting='briggs' ''','''robust=0.5''': Weighting to apply to visibilities. We use Briggs' weighting and robustness parameter 0.5 (in between natural and uniform weighting).<br />
*'''niter=10000''': Maximum number of clean iterations. <br />
*'''threshold='5.0mJy' ''': Stop cleaning if the maximum residual is below this value. <br />
The threshold is set to roughly the rms of a single line-free channel for each dataset. <br />
<br />
<figure id="North_interact.png"><br />
[[Image:North_interact.png|200px|thumb|right|<caption>Interactive cleaning of northern mosaic. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.CO3_2Line*')<br />
clean(vis='Antennae_North.cal.ms.contsub',<br />
imagename='Antennae_North.CO3_2Line.Clean',<br />
spw='0',field='',phasecenter='12',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',<br />
imsize=500,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,usescratch=False,<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
<xr id="North_interact.png"/> shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each channel with significant signal. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. To make it go a bit faster, you can increase '''iteration''' interactively, to 200 or 300, but don't overdo it.<br />
<br />
These data are pretty severely ''dynamic range'' limited, in part due to the sparse uv coverage. In other words, the noise in bright channels is set by a maximum signal-to-noise. This effectively prevents us from stopping clean based on an rms based '''threshold''' because the effective rms changes as a function of the brightest signal in each channel. Thus, in this case we need to stop clean interactively. Below an approximate number of '''iterations''' is given to help you decide when to quit. NOTE: the '''threshold''' that is set in the CO(3-2) clean commands are about equal to the noise in a line-free channel and is only there to prevent clean running forever if you fail to stop it. You are not intended to clean to this '''threshold'''.<br />
<br />
Also, we are going to self-calibrate the data so it's best to be conservative here - it can be difficult in images like these to discern real features from artifacts. If in doubt, don't include it in the clean mask. Keep cleaning and see if the feature becomes weaker. You cannot lose real emission by not masking it, but you can create a brighter feature by masking an artifact. <br />
<br />
Stop cleaning after about 900 iterations (Red X), when the artifacts start to look as bright as the residual. <br />
<br />
Inspect the resulting data cube:<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_North.CO3_2Line.Clean.image')<br />
</source><br />
<br />
==== Southern Mosaic ====<br />
<figure id="South_interact.png"><br />
[[Image:South_interact.png|200px|thumb|right|<caption>Interactive cleaning of southern mosaic. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
Repeat process for Southern mosaic.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South.CO3_2Line*')<br />
clean(vis='Antennae_South.cal.ms.contsub',<br />
imagename='Antennae_South.CO3_2Line.Clean',<br />
spw='0',field='',phasecenter='15',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',<br />
imsize=750,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,usescratch=False,<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
Clean about 1200 iterations before stopping.<br />
<br />
Inspect the resulting data cube:<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_South.CO3_2Line.Clean.image')<br />
</source><br />
<br />
For each mosaic use the '''viewer''' polygon tool as described above for the continuum, to find the image statistics in both a line-free channel and the channel with the strongest emission. <br />
<br />
The line-free channel rms for the northern and southern mosaics are about 4.0 mJy/beam and 3.5 mJy/beam, respectively.<br />
However in a bright channel this degrades to about 18 mJy/beam and 9 mJy/beam, respectively. This is the aforementioned dynamic range limit. <br />
<br />
Using the [https://almascience.nrao.edu/call-for-proposals/sensitivity-calculator ALMA sensitivity calculator], a bandwidth of 10 km/s, dual polarization, 12 antennas, and the time on a single pointing of about 300s yields an rms of about 9.0 mJy/beam. As described above the Nyquist sampled hexagonal mosaic improves this by a factor of about 2.5 for an expected rms noise of about 3.6 mJy. So in line-free channels we are doing close to theoretical.<br />
<br />
== Self Calibration == <br />
<br />
Next we attempt to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model image that you give it. When {{clean}} is run, it automatically saves a uv-model of the resulting image in the header of the measurement set. This model can be used to self-calibrate the data using {{gaincal}}. That is why it is important to make the model as good as you can by making clean masks. <br />
<br />
Mosaics can be tricky to self-calibrate. The reason is that typically only a few of the pointings may have strong emission. The stronger the signal, the stronger the signal-to-noise will be for a given self-calibration solution interval ('''solint'''). This means that typically only a few fields are strong enough for self-calibration, though it can still bring about overall improvement to apply these solutions to all fields. The fine tuning of each field in the mosaic over small solutions intervals is often impossible. Indeed fine-tuning only a few fields in the mosaic on small time scales can result in a mosaic with dramatically different noise levels as a function of position. Below, we will simply attempt to self-calibrate on the strongest field in the mosaic, obtaining one average solution per original input dataset. <br />
<br />
Here, the continuum is far too weak so we will use the CO(3-2) line emission. To increase signal-to-noise it is often helpful to limit solutions to the range of channels containing the strongest line emission. <br />
<br />
We will also use '''gaintype='T'''' to tell CASA to average the polarizations before deriving solutions which gains us a sqrt(2) in sensitivity.<br />
<br />
==== Northern Mosaic ====<br />
<br />
<figure id="north_selfchan_data.png"><br />
[[Image:north_selfchan.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the data column of field 12 of the Northern mosaic.</caption>]]<br />
</figure><br />
<br />
The strongest emission in the Northern mosaic comes from the center pointing, already identified above as '''field='12' '''. Below we make a uv-plot of the spectral line emission from this field to chose only the strongest channels to include in the self-calibration. ''It is essential that the self-calibration channel range be chosen based on the UV data and not on the image cube.'' This is because the channels in the image cube were modified by the velocity/channel specifications in the first invocation of clean. This plot shows the channel range of the uv data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_North.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',field='12',<br />
avgtime='1e8',avgscan=True,ydatacolumn='data',plotfile='North_selfchan_data.png', showgui = True)<br />
</source><br />
<br />
We also want to check the channel amplitudes in the model column of the measurement set. The depth of the initial clean will determine what model channels have emission. (A very shallow clean could potentially produce a model with emission over a small range of channels.) Self calibration will attempt to make the data look like the model. Therefore, it is important that we select a channel range where the model is realistic. <br />
<br />
<figure id="North_selfchan_model.png"><br />
[[Image:North_selfchan_model.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the model column of field 12 of the northern mosaic.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_North.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',field='12',<br />
avgtime='1e8',avgscan=True,ydatacolumn='model',plotfile='North_selfchan_model.png', showgui = True)<br />
</source><br />
<br />
Next remind ourselves of the timing of the various observations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_North.cal.ms.contsub',spw='',xaxis='time',yaxis='amp',field='12',<br />
avgchannel='167',coloraxis='scan',ydatacolumn='data', showgui = True)<br />
</source><br />
<br />
Zooming in on each dataset we see that they are about 1 hour long (you can also check the {{listobs}} output), and that each dataset has 2 or 3 observations of field 12. Each time, it's observed for about 25 seconds. We set '''solint='3600s'''' to get one solution per dataset.<br />
<br />
<figure id="north_pcal1_phase.png"><br />
[[Image:north_pcal1_phase.png|200px|thumb|right|<caption>Phase-only self-calibration solutions for the Northern mosaic.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='Antennae_North.cal.ms.contsub',caltable='north_self_1.pcal',<br />
solint='3600s',combine='scan',gaintype='T',field='12',<br />
refant='DV09',spw='0:82~89',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Plot the calibration solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='north_self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='',<br />
iteration='antenna',subplot=531,plotrange=[0,0,-80,80],<br />
figfile='north_pcal1_phase.png', showgui = True)<br />
</source><br />
<br />
Apply the solutions to all fields and channels with {{applycal}}, which will overwrite the corrected data column:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='Antennae_North.cal.ms.contsub',field='',<br />
gaintable=['north_self_1.pcal'],calwt=False)<br />
</source><br />
<br />
Re-image the data with the selfcal applied. Remember that {{clean}} always uses the corrected data column if it exists:<br />
<br />
<figure id="North_interact2.png"><br />
[[Image:North_interact2.png|200px|thumb|right|<caption>Interactive cleaning of Northern mosaic after self-cal. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.CO3_2Line.Clean.pcal1*')<br />
clean(vis='Antennae_North.cal.ms.contsub',<br />
imagename='Antennae_North.CO3_2Line.Clean.pcal1',<br />
spw='0',field='',phasecenter='12',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=500,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,mask='Antennae_North.CO3_2Line.Clean.mask',<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
After 600 iterations or so, inspect each channel to see if there is more emission that needs to be included in the mask. Remember to select the "all channels" toggle. Stop after 1200 or so iterations.<br />
<br />
Compare the un-selfcal'ed and selfcal'ed data to determine if there has been improvement.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (raster=[{'file': 'Antennae_North.CO3_2Line.Clean.image',<br />
'range': [-0.07,0.4]},<br />
{'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.07,0.4]}],<br />
zoom={'channel': 43})<br />
</source><br />
<br />
Then in the viewer, activate the Animator Images sub-panel by clicking the check box next to "Images". Then use the tape deck controls to cycle between the two images. To change the channel use the Channels sub-panel in the Animator. <br />
To make the figure shown in <xr id="north_ch43compare.png"/>, you can select the "p wrench" icon and change the number of panels in x to 2. You will need to drag your viewer window rather wide to get both panels to fit well. If you want to compare other channels, you need to toggle blink off, then use the tapedeck to move to the new channel of interest, and then turn blink back on to see both cubes again.<br />
<br />
Note: When the Images sub-panel is active (the check box next to Images is checked), statistics will be reported for the image currently displayed. When the Images sub-panel is not active, all open raster images will have their statistics reported.<br />
<br />
What you should notice is that the peak flux density has increased substantially while the rms noise is about the same. This is reasonable for this self-calibration case because we have mostly adjusted relative position offsets between the datasets and not taken out any short-term phase variations which would reduce the rms. <br />
<br />
Note that attempts to push the selfcal to shorter solint (for example to each scan of field=12) did not yield additional improvement. <br />
<br />
<figure id="north_ch43compare.png"><br />
[[Image:north_ch43compare.png|600px|thumb|center|<caption>Comparison of channel 43 before selfcal (left) and after selfcal (right).</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used '''standard='Butler-JPL-Horizons 2012' ''' when running {{setjy}} during the calibration process, you will see an increase of approximately 4% in the peak flux density (in channel 43).<br />
</div><br />
<br />
==== Southern Mosaic ====<br />
<br />
<figure id="south_selfchan.png"><br />
[[Image:south_selfchan.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the data column for Field 7 of the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
<figure id="South_selfchan_model.png"><br />
[[Image:South_selfchan_model.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the model column for Field 7 of the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
Now repeat the self-calibration process for the Southern mosaic. It is a bit tougher in this case to pick the best field. The most compact bright emission is toward field id 11 in the [[AntennaeBand7#Science_Target_Overview | Overview]]. Adjusting for the renumbering of field ids after the final calibration split, this becomes field='7'. <br />
<br />
From the following plots we can assess the brightest channels to pick and see that the timing in the 6 Southern datasets is similar to the North, with each lasting about 1 hour. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_South.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',<br />
field='7',avgtime='1e8',avgscan=True,ydatacolumn='data',<br />
plotfile='South_selfchan_data.png', showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
plotms(vis='Antennae_South.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',<br />
field='7',avgtime='1e8',avgscan=True,ydatacolumn='model',<br />
plotfile='South_selfchan_model.png', showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_South.cal.ms.contsub',spw='',xaxis='time',yaxis='amp',field='7',<br />
avgchannel='167',avgscan=True,coloraxis='scan',ydatacolumn='data', showgui = True)<br />
</source><br />
<br />
<figure id="south_pcal1_phase.png"><br />
[[Image:south_pcal1_phase.png|200px|thumb|right|<caption>Phase-only self-calibration solutions for the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='Antennae_South.cal.ms.contsub',caltable='south_self_1.pcal',<br />
solint='3600s',combine='scan',gaintype='T',field='7',<br />
refant='DV09',spw='0:70~85',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='south_self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='',<br />
iteration='antenna',subplot=531,plotrange=[0,0,-80,80],<br />
figfile='south_pcal1_phase.png', showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='Antennae_South.cal.ms.contsub',field='',<br />
gaintable=['south_self_1.pcal'],calwt=False)<br />
</source><br />
<br />
<figure id="South_interact2.png"><br />
[[Image:South_interact2.png|200px|thumb|right|<caption>Interactive cleaning of Southern mosaic after self-cal. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South.CO3_2Line.Clean.pcal1*')<br />
clean(vis='Antennae_South.cal.ms.contsub',<br />
imagename='Antennae_South.CO3_2Line.Clean.pcal1',<br />
spw='0',field='',phasecenter='15',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=750,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,mask='Antennae_South.CO3_2Line.Clean.mask',<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
After 600 iterations or so, inspect each channel to see if there is more emission that needs to be included in the mask. Remember to select the "all channels" toggle. Stop after 2200 or so iterations.<br />
<br />
As for the Northern mosaic, you can compare the before and after self-cal images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (raster=[{'file': 'Antennae_South.CO3_2Line.Clean.image',<br />
'range': [-0.05,0.2]},<br />
{'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.05,0.2]}],<br />
zoom={'channel': 31})<br />
</source><br />
<br />
<figure id="South_ch31compare.png"><br />
[[Image:South_ch31compare.png|600px|thumb|center|<caption>Comparison of channel 31 before selfcal (left) and after selfcal (right).</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used '''standard='Butler-JPL-Horizons 2012' ''' when running {{setjy}} during the calibration process, you will see an increase of approximately 4% in the peak flux density (in channel 31).<br />
</div><br />
<br />
== Image Analysis ==<br />
<br />
==== Moment Maps ====<br />
<br />
<figure id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png"><br />
[[Image:Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png|200px|thumb|right|<caption>The CO(3-2) integrated intensity map (moment 0) of the Northern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"><br />
[[Image:Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity field (moment 1) of the Northern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"><br />
[[Image:Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity dispersion (moment 2) of the Northern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png"><br />
[[Image:Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png|200px|thumb|right|<caption>The CO(3-2) integrated intensity map (moment 0) of the Southern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"><br />
[[Image:Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity field (moment 1) of the Southern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"><br />
[[Image:Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity dispersion (moment 2) of the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
Next we will make moment maps for the CO(3-2) emission: Moment 0 is the integrated intensity; Moment 1 is the intensity weighted velocity field; and Moment 2 is the intensity weighted velocity dispersion. <br />
<br />
Above we determined the rms noise levels for both the North and South mosaics in both a line-free and a line-bright channel. We want to limit the channel range of the moment calculations to those channels with significant emission. One good way to do this is to open the cube in the viewer overlaid with 3-sigma contours, with sigma corresponding to the line-free rms. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.04,0.4]},<br />
contour={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
'levels': [0.004],'unit': 5})<br />
</source><br />
<br />
We find a channel range for significant emission of 33~63.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.04,0.4]},<br />
contour={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
'levels': [0.0035],'unit': 5})<br />
</source><br />
<br />
We find a channel range for significant emission of 12~64.<br />
<br />
For moment 0 (integrated intensity) maps you do not typically want to set a flux threshold because this will tend to noise bias your integrated intensity.<br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_North.CO3_2Line.Clean.pcal1.image', <br />
moments=[0],chans='33~63',<br />
outfile='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
moments=[0], chans='12~64', <br />
outfile='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0')<br />
</source><br />
<br />
For higher order moments it is very important to set a conservative flux threshold. Typically something like 3sigma, using sigma from a bright line channel works well. We do this with the '''mask''' parameter in the commands below. When making multiple moments, {{immoments}} appends the appropriate file name suffix to the value of '''outfile'''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_North.CO3_2Line.Clean.pcal1.image', <br />
moments=[1,2], chans='33~63', <br />
mask='Antennae_North.CO3_2Line.Clean.pcal1.image>0.018*3',<br />
outfile='Antennae_North.CO3_2Line.Clean.pcal1.image.mom')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_South.CO3_2Line.Clean.pcal1.image', <br />
moments=[1,2], chans='12~64',<br />
mask=' Antennae_South.CO3_2Line.Clean.pcal1.image>0.009*3',<br />
outfile='Antennae_South.CO3_2Line.Clean.pcal1.image.mom')<br />
</source><br />
<br />
Next we can create the six moment maps<br />
(<xr id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png"/>,<br />
<xr id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"/>,<br />
<xr id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"/>,<br />
<xr id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png"/>,<br />
<xr id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"/>,<br />
<xr id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"/>)<br />
from these images using '''imview'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
imview (raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image.mom0',<br />
'colorwedge':T,'scaling': -0.5},<br />
zoom=1,out='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
<br />
os.system('rm -f Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
imview (raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
<br />
os.system('rm -f Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png')<br />
imview (raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png') <br />
<br />
os.system('rm -f Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
imview (raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image.mom0',<br />
'colorwedge':T,'scaling': -0.5},<br />
zoom=1,out='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
<br />
os.system('rm -f Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
imview (raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
<br />
os.system('rm -f Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png')<br />
imview (raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png') <br />
</source><br />
<br />
==== Exporting Images to Fits ====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
exportfits(imagename='Antennae_North.Cont.Clean.image',<br />
fitsimage='Antennae_North.Cont.Clean.image.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
exportfits(imagename='Antennae_South.Cont.Clean.image',<br />
fitsimage='Antennae_South.Cont.Clean.image.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=True''' and/or '''dropstokes=True'''.<br />
<br />
==Comparison with previous SMA CO(3-2) data==<br />
<br />
We compare with SMA CO(3-2) data (Ueda, Iono, Petitpas et al. 2012, ApJ, 745, 65). <xr id="alma_sma_compare.png"/> shows a comparison plot between the moment 0 maps of ALMA and SMA data using the {{viewer}}. The fluxes, peak locations, and large scale structure are consistent. Both southern and northern components have been combined.<br />
<br />
<figure id="alma_sma_compare.png"><br />
[[Image: alma_sma_compare.png|500px|thumb|center|<caption>The CO(3-2) total intensity map (moment 0) comparison with SMA data. Colour image is ALMA data, combining southern and northern mosaics. Contours show SMA data (Ueda, Iono, Petitpas et al. 2012, ApJ, 745, 65).</caption>]]<br />
</figure><br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.5&diff=21247AntennaeBand7 Calibration 4.52017-04-04T15:00:17Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This guide requires CASA 4.5.0 and assumes that you have downloaded Antennae_Band7_UnCalibratedMSAndTablesForReduction.tgz from [[AntennaeBand7#Obtaining_the_Data]]'''<br />
<br />
*'''Details of the ALMA observations are provided at [[AntennaeBand7]]<br />
<br />
*'''This portion of the guide covers calibration of the raw visibility data. To skip to the imaging portion of the guide, see: [[AntennaeBand7 Imaging 4.5]]'''.<br />
<br />
==Overview==<br />
<br />
This part of the Antennae Band 7 CASA guide will step you through the calibration of the visibility data. We will begin by flagging (marking as bad) data known to be useless before any inspection, for example data where one telescope blocks the line of sight of another. Then we will apply telescope-generated calibration tables to partially correct for atmospheric effects. After inspecting the data, we will flag some additional data that exhibit pathologies. Then we will use observations of the calibrators Titan and 3c279 to derive the phase and amplitude response of individual antennas as a function of time and frequency ("phase", "amplitude", and "bandpass" calibrations). We will apply these to the data and then extract the calibrated source data into a file appropriate for imaging.<br />
<br />
The general procedure in this guide follows the other ALMA CASA guides: [[NGC3256Band3]] and [[TWHydraBand7]].<br />
<br />
==Unpack the Data==<br />
<br />
Once you have downloaded the Antennae_Band7_UnCalibratedMSandTablesForReduction.tgz, unpack the file in a terminal outside CASA using<br />
<br />
<source lang="bash"><br />
<br />
tar -xvzf Antennae_Band7_UnCalibratedMSandTablesForReduction.tgz<br />
<br />
</source><br />
<br />
then change directory to the new directory <br />
<br />
<source lang="bash"><br />
<br />
cd Antennae_Band7_UnCalibratedMSandTablesForReduction<br />
<br />
</source><br />
<br />
You may wish to type<br />
<br />
<source lang="bash"><br />
<br />
ls<br />
<br />
</source><br />
<br />
to look at the files present. You should see a set of files with extension ".ms". These are CASA measurement set (MS) files. The data have already been converted to MS format from the native ALMA format using the CASA task {{importasdm}}. In addition to the data, we provide you with calibration tables containing system temperature (Tsys), water vapor radiometer (WVR), and antenna position information. For Early Science, these tables will either be pre-applied or supplied with the data.<br />
<br />
To begin, start CASA by typing<br />
<br />
<source lang="bash"><br />
<br />
casapy<br />
<br />
</source><br />
<br />
Be sure that you are using the version indicated at the top of this page.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
==Initial Inspection==<br />
<br />
First we will take stock of what we have. If you have not already done so, begin by reviewing the description of the observations here: [[AntennaeBand7]]. The 10 data sets each target either the Northern or the Southern Mosaic, as follows:<br />
<br />
Northern Mosaic:<br />
*uid___A002_X1ff7b0_Xb.ms<br />
*uid___A002_X207fe4_X3a.ms<br />
*uid___A002_X207fe4_X3b9.ms<br />
*uid___A002_X2181fb_X49.ms<br />
<br />
Southern Mosaic:<br />
*uid___A002_X1ff7b0_X1c8.ms<br />
*uid___A002_X207fe4_X1f7.ms<br />
*uid___A002_X207fe4_X4d7.ms<br />
*uid___A002_X215db8_X18.ms<br />
*uid___A002_X215db8_X1d5.ms<br />
*uid___A002_X215db8_X392.ms<br />
<br />
The first step is to get basic information about the data: targets observed, time range, spectral setup, and so on. We do this using the task {{listobs}}, which will output a detailed summary of each dataset. Enter the following commands into CASA:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Define a python list holding the names of all of our data sets<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
# Initialize user-input string. (for Python testing)<br />
dummy_string = ''<br />
<br />
# Loop over each element in the list and create summary file using listobs<br />
for asdm in basename_all:<br />
os.system('rm '+asdm+'.listobs.txt')<br />
listobs(vis=asdm+'.ms', listfile=asdm+'.listobs.txt', verbose=True)<br />
</source><br />
<br />
Note that after cutting and pasting a 'for' loop like this you often have to press return twice to execute. You may also want to take care to paste a line at a time if you are having trouble copy and pasting. Even better, you can use "cpaste" to paste blocks of code. To do so type "cpaste" at the CASA prompt, paste your commands, and then type "--" and hit return on the final (otherwise empty) line. This should look something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
CASA <8>: cpaste<br />
Pasting code; enter '--' alone on the line to stop.<br />
:basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
: "uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
: "uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
: "uid___A002_X215db8_X392"]<br />
:<br />
:for asdm in basename_all:<br />
: print asdm<br />
:--<br />
uid___A002_X1ff7b0_Xb<br />
uid___A002_X207fe4_X3a<br />
uid___A002_X207fe4_X3b9<br />
uid___A002_X2181fb_X49<br />
uid___A002_X1ff7b0_X1c8<br />
uid___A002_X207fe4_X1f7<br />
uid___A002_X207fe4_X4d7<br />
uid___A002_X215db8_X18<br />
uid___A002_X215db8_X1d5<br />
uid___A002_X215db8_X392<br />
<br />
CASA <9>: <br />
<br />
</pre><br />
<br />
cpaste should be ''much'' more robust than copying-and-pasting directly into the shell but if you have trouble, just carefully paste one line at a time directly into CASA and hit return until the desired command executes.<br />
<br />
These commands define a python list called "basename_all", which contains the name of all 10 MS files. The "for" loop executes for each element in basename_all, calling listobs and directing the output to a file called, e.g., "uid___A002_X1ff7b0_Xb.listobs.txt" for the first measurement set. You can browse through the listobs output as you would normally look at a text file (use emacs, vi, or another editor). You can also send the output to the terminal from inside of CASA. To do so type:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('cat uid___A002_X1ff7b0_Xb.listobs.txt')<br />
</source><br />
<br />
or<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('more uid___A002_X1ff7b0_Xb.listobs.txt')<br />
</source><br />
<br />
CASA knows a few basic shell commands like 'cat', 'ls', and 'rm' but for more complex commands you will need to run them inside 'os.system("command")'. For more information see http://casa.nrao.edu/ .<br />
<br />
Here is an example of the (abridged) output from {{listobs}} for the first dataset in the list, uid___A002_X1ff7b0_Xb.ms, which targets the Northern Mosaic. You would see this if you had specified '''verbose''' to be False in the listobs call:<br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: /lustre/naasc/almauser/AntennaeBand7/uid___A002_X1ff7b0_Xb.ms MS Version 2<br />
================================================================================<br />
Observer: Unknown Project: T.B.D. <br />
Observation: ALMA(11 antennas)<br />
Data records: 181357 Total integration time = 4931.71 seconds<br />
Observed from 28-May-2011/01:25:27.6 to 28-May-2011/02:47:39.3 (UTC)<br />
<br />
Fields: 26<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 39116 <br />
1 none Titan 12:42:43.94813 -01.43.38.3190 J2000 1 10626 <br />
2 none NGC4038 - Antennae *12:01:53.17008 -18.52.37.9200 J2000 2 4818 <br />
3 none NGC4038 - Antennae *12:01:51.90301 -18.51.49.9437 J2000 2 6435 <br />
4 none NGC4038 - Antennae *12:01:52.43086 -18.51.49.9437 J2000 2 6424 <br />
5 none NGC4038 - Antennae *12:01:52.95871 -18.51.49.9437 J2000 2 5478 <br />
6 none NGC4038 - Antennae *12:01:53.48656 -18.51.49.9436 J2000 2 6435 <br />
7 none NGC4038 - Antennae *12:01:54.01441 -18.51.49.9436 J2000 2 6446 <br />
8 none NGC4038 - Antennae *12:01:52.16693 -18.51.56.4319 J2000 2 6435 <br />
9 none NGC4038 - Antennae *12:01:52.69478 -18.51.56.4318 J2000 2 6424 <br />
10 none NGC4038 - Antennae *12:01:53.22263 -18.51.56.4318 J2000 2 6446 <br />
11 none NGC4038 - Antennae *12:01:53.75049 -18.51.56.4318 J2000 2 6446 <br />
12 none NGC4038 - Antennae *12:01:51.90301 -18.52.02.9201 J2000 2 6435 <br />
13 none NGC4038 - Antennae *12:01:52.43086 -18.52.02.9200 J2000 2 6424 <br />
14 none NGC4038 - Antennae *12:01:52.95871 -18.52.02.9200 J2000 2 4818 <br />
15 none NGC4038 - Antennae *12:01:53.48656 -18.52.02.9200 J2000 2 4829 <br />
16 none NGC4038 - Antennae *12:01:54.01441 -18.52.02.9199 J2000 2 4829 <br />
17 none NGC4038 - Antennae *12:01:52.16694 -18.52.09.4082 J2000 2 4829 <br />
18 none NGC4038 - Antennae *12:01:52.69479 -18.52.09.4082 J2000 2 4829 <br />
19 none NGC4038 - Antennae *12:01:53.22264 -18.52.09.4082 J2000 2 3872 <br />
20 none NGC4038 - Antennae *12:01:53.75049 -18.52.09.4081 J2000 2 4829 <br />
21 none NGC4038 - Antennae *12:01:51.90301 -18.52.15.8964 J2000 2 4829 <br />
22 none NGC4038 - Antennae *12:01:52.43087 -18.52.15.8964 J2000 2 4829 <br />
23 none NGC4038 - Antennae *12:01:52.95872 -18.52.15.8963 J2000 2 4818 <br />
24 none NGC4038 - Antennae *12:01:53.48657 -18.52.15.8963 J2000 2 4818 <br />
25 none NGC4038 - Antennae *12:01:54.01442 -18.52.15.8963 J2000 2 4840 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 3840 TOPO 344845.586 488.28125 1875000 XX YY <br />
2 1 TOPO 343908.086 1875000 1875000 XX YY <br />
3 3840 TOPO 354971.074 488.28125 1875000 XX YY <br />
4 1 TOPO 343908.086 1875000 1875000 XX YY <br />
5 128 TOPO 344900.518 15625 2000000 XX YY <br />
6 1 TOPO 343892.705 1796875 1796875 XX YY <br />
7 128 TOPO 354916.143 15625 2000000 XX YY <br />
8 1 TOPO 343892.705 1796875 1796875 XX YY <br />
Antennas: 11 'name'='station' <br />
ID= 0-3: 'DV02'='A015', 'DV04'='J505', 'DV06'='T704', 'DV07'='A004', <br />
ID= 4-7: 'DV08'='A072', 'DV09'='A008', 'DV10'='A009', 'DV11'='A016', <br />
ID= 8-10: 'PM01'='T702', 'PM02'='A017', 'PM03'='J504'<br />
================================================================================<br />
<br />
</pre><br />
<br />
And here is an extract from the full '''verbose''' {{listobs}} for uid___A002_X1ff7b0_X1c8.ms, which targets the Southern Mosaic (note that we have snipped out the record of individual scans):<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
================================================================================<br />
MeasurementSet Name: /lustre/naasc/almauser/AntennaeBand7/uid___A002_X1ff7b0_X1c8.ms MS Version 2<br />
================================================================================<br />
Observer: Unknown Project: T.B.D. <br />
Observation: ALMA<br />
Data records: 175615 Total integration time = 4927.1 seconds<br />
Observed from 28-May-2011/02:50:18.2 to 28-May-2011/04:12:25.3 (UTC)<br />
<br />
<snip><br />
<br />
Fields: 33<br />
ID Code Name RA Decl Epoch SrcId nVis <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 12232 <br />
1 none Titan 12:42:44.82765 -01.43.41.4224 J2000 1 10615 <br />
2 none 3c279 12:56:11.16600 -05.47.21.5250 J2000 2 27764 <br />
3 none Antennae 12:01:53.17008 -18.52.37.9200 J2000 3 4829 <br />
4 none Antennae 12:01:52.18699 -18.53.30.3952 J2000 3 3883 <br />
5 none Antennae 12:01:52.64413 -18.53.26.6494 J2000 3 3883 <br />
6 none Antennae 12:01:53.10127 -18.53.22.9035 J2000 3 3872 <br />
7 none Antennae 12:01:53.55841 -18.53.19.1577 J2000 3 4818 <br />
8 none Antennae 12:01:54.01554 -18.53.15.4119 J2000 3 4829 <br />
9 none Antennae 12:01:54.47268 -18.53.11.6661 J2000 3 4829 <br />
10 none Antennae 12:01:54.92982 -18.53.07.9203 J2000 3 3872 <br />
11 none Antennae 12:01:55.38696 -18.53.04.1744 J2000 3 3883 <br />
12 none Antennae 12:01:55.84409 -18.53.00.4286 J2000 3 4840 <br />
13 none Antennae 12:01:56.30123 -18.52.56.6828 J2000 3 4818 <br />
14 none Antennae 12:01:52.18700 -18.53.22.9033 J2000 3 4829 <br />
15 none Antennae 12:01:52.64414 -18.53.19.1575 J2000 3 4818 <br />
16 none Antennae 12:01:53.10128 -18.53.15.4116 J2000 3 4818 <br />
17 none Antennae 12:01:53.55842 -18.53.11.6658 J2000 3 4840 <br />
18 none Antennae 12:01:54.01555 -18.53.07.9200 J2000 3 3872 <br />
19 none Antennae 12:01:54.47269 -18.53.04.1742 J2000 3 4829 <br />
20 none Antennae 12:01:54.92983 -18.53.00.4284 J2000 3 4829 <br />
21 none Antennae 12:01:55.38697 -18.52.56.6825 J2000 3 4829 <br />
22 none Antennae 12:01:55.84410 -18.52.52.9367 J2000 3 4829 <br />
23 none Antennae 12:01:51.72988 -18.53.19.1572 J2000 3 4818 <br />
24 none Antennae 12:01:52.18702 -18.53.15.4114 J2000 3 4829 <br />
25 none Antennae 12:01:52.64415 -18.53.11.6656 J2000 3 4829 <br />
26 none Antennae 12:01:53.10129 -18.53.07.9197 J2000 3 2266 <br />
27 none Antennae 12:01:53.55843 -18.53.04.1739 J2000 3 2266 <br />
28 none Antennae 12:01:54.01557 -18.53.00.4281 J2000 3 3212 <br />
29 none Antennae 12:01:54.47270 -18.52.56.6823 J2000 3 3234 <br />
30 none Antennae 12:01:54.92984 -18.52.52.9365 J2000 3 3212 <br />
31 none Antennae 12:01:55.38698 -18.52.49.1906 J2000 3 2266 <br />
32 none Antennae 12:01:55.84411 -18.52.45.4448 J2000 3 3223 <br />
(nVis = Total number of time/baseline visibilities per field) <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 3840 TOPO 344845.586 488.28125 1875000 XX YY <br />
2 1 TOPO 343908.086 1875000 1875000 XX YY <br />
3 3840 TOPO 356845.586 488.28125 1875000 XX YY <br />
4 1 TOPO 343908.086 1875000 1875000 XX YY <br />
5 128 TOPO 344900.518 15625 2000000 XX YY <br />
6 1 TOPO 343892.705 1796875 1796875 XX YY <br />
7 128 TOPO 356900.518 15625 2000000 XX YY <br />
8 1 TOPO 343892.705 1796875 1796875 XX YY <br />
Antennas: 11:<br />
ID Name Station Diam. Long. Lat. <br />
0 DV02 A015 12.0 m -067.45.15.3 -22.53.26.0 <br />
1 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8 <br />
2 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1 <br />
3 DV07 A004 12.0 m -067.45.15.9 -22.53.28.0 <br />
4 DV08 A072 12.0 m -067.45.12.6 -22.53.24.0 <br />
5 DV09 A008 12.0 m -067.45.15.4 -22.53.26.8 <br />
6 DV10 A009 12.0 m -067.45.16.1 -22.53.26.1 <br />
7 DV11 A016 12.0 m -067.45.16.4 -22.53.25.1 <br />
8 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1 <br />
9 PM02 A017 12.0 m -067.45.15.9 -22.53.26.8 <br />
10 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0 <br />
</pre><br />
<br />
This output shows that three sources were observed in each data set: 3c279, Titan, and the Antennae.<br />
<br />
* The '''Antennae''' are our science target. Note that the source name changes between the Northern Mosaic, where it is "NGC4038 - Antennae", and the Southern Mosaic, where it is just "Antennae". Also note that the source corresponds to a number of individual fields (see the Field ID column). These are the individual mosaic pointings. There are 23 for the Northern Mosaic and 29 for the Southern Mosaic.<br />
* '''Titan''' is observed once and will be used to set the absolute flux scale of the data.<br />
* '''3c279''' plays two roles: it will serve as our bandpass calibrator, to characterize the frequency response of the antennas, and because it is fairly close on the sky to the Antennae (18.6 degrees away) it will serve as our secondary calibrator (also referred to as the "phase calibrator" or "gain calibrator"), to track changes in the phase and amplitude response of the telescopes over time. Observations of 3c279 are interleaved with observations of the Antennae.<br />
<br />
The output also shows that the data contain many spectral windows. Using the labeling scheme in the listobs above these are:<br />
<br />
* '''spw 0''' targets ~185 GHz and holds water vapor radiometer data<br />
* '''spw 1''' and '''spw 3''' hold our science data. These are "Frequency Domain Mode" (FDM) data with small (0.49 MHz) channel width and wide (1.875 GHz) total bandwidth. As a result these have a lot of channels (3840). spw 1 holds the lower sideband (LSB) data and includes the CO(3-2) line. We will focus on these data. For the CO(3-2) line the channel width corresponds to 0.426 km/s and the bandwidth of spw 1 to 1634 km/s.<br />
* '''spw 2''' and '''spw 4''' hold frequency-averaged versions of spw 1 and 3 ("Channel 0" for those familiar with AIPS). These are used for some quick automated inspection. We will not use them here but we will carry out an equivalent inspection using spw 1.<br />
* '''spw 5''' and '''spw 7''' hold lower a resolution processing ("Time Domain Mode", TDM) of the data from the same part of the spectrum (baseband) as spws 1 and 3. These data have only 128 channels across 2 GHz bandwidth and so have a much coarser channel spacing than the FDM data. These were used to generate the calibration tables that we include in the tarball but will not otherwise appear in this guide.<br />
<br />
The final column of the listobs output in the logger (not shown above) gives the scan intent. Later we will use this information to flag the pointing scans and the hot and ambient load calibration scans.<br />
<br />
We'll now have a look at the configuration of the antennas used to take the data using the task {{plotants}} (<xr id="Uid_A002_X1ff7b0_Xb.ANT.png"/>).<br />
<br />
<figure id="Uid_A002_X1ff7b0_Xb.ANT.png"><br />
[[File:Uid_A002_X1ff7b0_Xb.ANT.png|200px|thumb|right|<caption> Position of antennas in dataset uid_A002_X1ff7b0_Xb obtained using task {{plotants}}</caption>]]<br />
</figure><br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
<br />
for asdm in basename_all:<br />
print "Antenna configuration for : "+asdm<br />
plotants(vis=asdm+'.ms', figfile=asdm+'.plotants.png')<br />
clearstat()<br />
dummy_string = raw_input("Hit <Enter> to see the antenna configuration for the next data set.")<br />
</source> <br />
<br />
This will loop through all 10 data sets, show you the antenna position for each, and save that as a file named, e.g., "uid___A002_X1ff7b0_Xb.plotants.png" for the first data set. The "raw_input" command asks CASA to wait for your input before proceeding. If you would prefer to just browse the .png files after the fact you can remove this. Notice that the antenna setup changes, but only slightly, over the course of the 10 data sets.<br />
<br />
==How to Deal With 10 Measurement Sets==<br />
<br />
It should already be clear from the initial inspection that dealing with 10 data sets at the same time can be a bit problematic. This is especially tricky in our case because the Antennae data contain two distinct sets of observations: the Northern and Southern Mosaics. The source name changes between these two scripts and there are different numbers of fields in the mosaic.<br />
<br />
''As a general rule one would reduce each individual observation separately or at the very least only group data observed in a uniform way and very close in time.'' <br />
<br />
Unfortunately, a CASA Guide stepping through the reduction for each of 10 data sets would quickly become unwieldy. Therefore we will use a few tricks to reduce the Antennae data in a kind of batch mode. You have already seen the first trick: we can define a python list holding the names of each data set and then loop over this list to execute the same command on each data set. For example:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print asdm<br />
</source><br />
<br />
You only need to define your list of MS files once per CASA session. Then "basename_all" will be a variable in the casapy shell. You can check if it exists by typing "print basename_all". In the interests of allowing you to easily exit and restart CASA and pick this guide up at any point we will redefine "basename_all" in each section of the guide. Feel free to skip this step if you've already defined it in your session.<br />
<br />
This page will step you through the reduction of the whole Antennae Band 7 SV data set using these 'for' loops. We will not be able to show every diagnostic plot but we give an example of each and the syntax to generate the rest. Also please be aware that even on a very fast machine this whole process can take a while, we are simply dealing with a lot of data.<br />
<br />
One potential "gotcha" is that the source name changes between the two data sets. Therefore at several points we will break apart our loop to iterate separately over the Northern and Southern Mosaics, where the source can be referred unambiguously. Another subtle point is that 3c279 appears with two distinct field IDs in the Southern Mosaic, but only one in the Northern Mosaic. We will largely avoid this by referring to the source by its name but if you tried to use field ID numbers and mingled the two data sets this could cause confusion.<br />
<br />
==''A Priori'' Flagging==<br />
<br />
Even before we look in detail, we know that there are some data that we wish to exclude. We will start by flagging "shadowed" data where one antenna blocks the line of sight of another. We will also flag scans that were used to carry out pointing and atmospheric calibration, identified by their scan intent. Finally, we'll flag the autocorrelation data (the correlation of the signal from an antenna with itself) as we are only interested in cross-correlation data to make an interferometric image.<br />
<br />
Start by defining our list of MS files:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
</source><br />
<br />
You may want to reset the flagging if you have tried this step before and are starting over though this is not necessary on your first time through. Do so using {{flagdata}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Resetting flags for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='unflag', flagbackup=False)<br />
</source><br />
<br />
Then flag shadowed data using the command {{flagdata}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Flagging shadowed data for "+asdm<br />
flagdata(vis=asdm+'.ms',mode = 'shadow', flagbackup = False)<br />
</source><br />
<br />
In the {{flagdata}} task we choose:<br />
<br />
* '''vis''' = asdm+'.ms' : each measurement set<br />
* '''mode''' = 'shadow': flag shadowed data<br />
* '''flagbackup''' = F: Do not automatically back up the flag files. We will save all of the ''a priori'' flags together using {{flagmanager}} at the end of this subsection and save some space and time.<br />
<br />
The relevant calibration information has already been extracted from the pointing and atmospheric scans and we will not need them below. Now flag the pointing scans using {{flagdata}} in 'manualflag' mode and selecting on 'intent':<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Flagging calibration scans for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', intent='*POINTING*', flagbackup = False)<br />
</source><br />
<br />
Note that because the atmospheric calibration scans contain only TDM spectral windows, they will be removed automatically when we separate out the FDM data below.<br />
<br />
Now flag the autocorrelation data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Flagging autocorrelation data for "+asdm<br />
flagdata(vis=asdm+'.ms',autocorr=True,flagbackup=False)<br />
</source><br />
<br />
Finally store the current flags information using {{flagmanager}}: <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Backing up 'a priori' flags for "+asdm<br />
flagmanager(vis = asdm+'.ms', mode = 'save', versionname = 'Apriori')<br />
</source><br />
<br />
Where '''versionname''' is just the name we assign to the current flagging state in the data. We can now roll back the flags to match the current version, called 'Apriori', whenever we want. There is no reason to do this now, but the syntax would be:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Restoring up 'a priori' flags for "+asdm<br />
flagmanager(vis = asdm+'.ms', mode = 'restore', versionname = 'Apriori')<br />
</source><br />
<br />
<br />
It would have been possible to set {{flagdata}} to '''flagbackup'''=True so that it stores the flags at each of the flagging step automatically, but this way it is a bit more efficient with regard to time and disk space. More important, lumping all the ''a priori'' flagging together gives us a natural point to roll back to if we get in trouble.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The flagmanager task will also allow you to view the saved flagging versions,<br />
including those created by running flagdata with flagbackup=True.<br />
<br />
For example try <br />
<br />
flagmanager(vis='uid___A002_X2181fb_X49.ms', mode='list')<br />
<br />
The output in the logger should list the Apriori flagging that we have applied.<br />
It will also indicate versions associated with any flagdata command where you<br />
did not set flagbackup=False. Other tasks, for example applycal, will also create<br />
flag version tables.<br />
</pre><br />
<br />
==Create and Apply Tsys, WVR, and Antenna Position Calibration Tables==<br />
<br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
</source><br />
<br />
===Tsys===<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 persists through imaging.<br />
<br />
Use gencal to create the Tsys calibration tables from the spectral windows with CALIBRATE_ATMOSPHERE intents in listobs (i.e. the TDM spectral windows with 128 channels), these are spectral windows 5 and 7.<br />
<br />
<source lang="python"><br />
#In CASA<br />
#Removing existing Tsys information<br />
os.system('rm -rf *tdm.tsys')<br />
for asdm in basename_all:<br />
print "Creating TDM Tsys Table for "+asdm<br />
gencal(vis=asdm+'.ms',caltable=asdm+'.tdm.tsys',spw='5,7',caltype='tsys')<br />
</source><br />
<br />
Later in the applycal stage this TDM Tsys table will be interpolated to the FDM (3840 channels per spw) science spectral windows 1 and 3.<br />
<br />
Next we inspect the Tsys tables for the spectral window spw=5 with the task {{plotcal}}. We want to check that Tsys data have reasonable values and identify any unexpected features as a function of either time or frequency. To get an idea of sensible Tsys under average atmospheric observations consult the ALMA sensitivity calculator, accessible from http://www.almascience.org (via the "Documents & Tools" link).<br />
<br />
We start by plotting the Tsys for all the antennas and polarizations (XX and YY) as a function of time for each. Here and throughout we focus on spw 1, which contains CO(3-2):<br />
<figure id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page1.png"><br />
[[File:uid___A002_X1ff7b0_X1c8.tsys_vs_time.page1.png|200px|thumb|right|<caption> Tsys vs. time plot for uid_A002_X1ff7b0_Xb (northern mosaic). First 8 antennas. Note the high y-axis values for DV04. The two different colors indicate the two polarizations (XX and YY).</caption>]]<br />
</figure><br />
<figure id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page2.png"><br />
[[File:uid___A002_X1ff7b0_X1c8.tsys_vs_time.page2.png|200px|thumb|right|<caption> Tsys vs. time plot for uid_A002_X1ff7b0_Xb (northern mosaic). Remaining antennas.</caption>]]<br />
</figure><br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tdm.tsys', <br />
xaxis="time",yaxis="tsys",<br />
spw='5:50~50',plotsymbol=".", subplot=421,<br />
antenna='0~7',<br />
iteration='antenna', figfile=asdm+'.tsys_vs_time.page1.png',<br />
fontsize=7.0, showgui = True) <br />
#dummy_string = raw_input("First eight antennas for "+asdm+" . Hit <Enter> to continue.")<br />
plotcal(caltable=asdm+'.tdm.tsys', <br />
xaxis="time",yaxis="tsys",<br />
antenna='8~15',<br />
spw='5:50~50',plotsymbol=".", subplot=421,<br />
iteration='antenna', figfile=asdm+'.tsys_vs_time.page2.png',<br />
fontsize=7.0, showgui = True) <br />
#dummy_string = raw_input("Remaining antennas for "+asdm+" . Hit <Enter> to continue.")<br />
</source><br />
<br />
This sequence loops over all of our files and plots Tsys as a function of time for channel 50 in spectral window 5. In the call to {{plotcal}}:<br />
<br />
* '''subplot'''=421 parameter sets up a 4 x 2 panel grid. <br />
* '''iteration''' tells {{plotcal}} to make a separate plot for each antenna.<br />
* '''spw''' '5:50~50' selects spw '5' channel 50-50. This allows us to cleanly separate time variations from frequency variations.<br />
<br />
Because 8 panels (2 panels for each antenna - LSB and USB) is not enough to show all antennas on one page, there are two plotcal calls: one for the first 8 antennas ('''antenna'''=0~7), and then for the remaining antennas ('''antenna'''=8~15). The '''fontsize''' needs to be set to a small value or the text overlaps.<br />
<br />
The 'raw_input' commands will wait for you to hit Enter before issuing the next plot command. In the example above these are commented out (the leading "#" means that CASA will ignore them). If you would like to interactively cycle through the plots, uncomment them by removing the "#". Otherwise, the '''figfile''' parameter directs the output to .png files for later inspection. The easiest way to look at the 20 plots produced here is to simply inspect the .png files using your favorite viewer.<br />
<br />
The Tsys values in <xr id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page1.png"/> and <xr id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page2.png"/> look reliable, with typical values ~150 K except for some large values of Tsys at ~400 and 500 K for DV04. We will flag the data for that antenna later. <br />
<br />
We will also want to look at Tsys as a function of frequency. <br />
<br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
os.system('rm -rf cal_plots/Tsys_plots/'+asdm+'.tdm.tsys*')<br />
tsysfields=['3c279','Titan','*Antennae*']<br />
caltable=asdm+'.tdm.tsys'<br />
for field in tsysfields:<br />
plotbandpass(caltable=caltable,yaxis='amp',field=field,xaxis='freq',<br />
showatm=True,overlay='time',<br />
figfile='cal_plots/Tsys_plots/'+caltable+'.'+field,<br />
buildpdf=False,interactive=False,chanrange='8~120',subplot=42)<br />
</source><br />
<br />
<figure id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid_A002_X1ff7b0_Xb (northern mosaic). First 4 antennas. Note the high y-axis values for DV04 and the mesospheric line near 343.2 GHz.</caption>]]<br />
</figure><br />
<figure id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV08.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV08.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid_A002_X1ff7b0_Xb (northern mosaic). Next 4 antennas.</caption>]]<br />
</figure><br />
<figure id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid_A002_X1ff7b0_Xb (northern mosaic). Remaining antennas.</caption>]]<br />
</figure><br />
<br />
<figure id="Uid___A002_X215db8_X392.tdm.tsys.3c279.DV11.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X215db8_X392.tdm.tsys.3c279.DV11.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid___A002_X215db8_X392. Note the pathological behavior for DV12.</caption>]]<br />
</figure><br />
<br />
Now have a look at the Tsys vs. frequency plots or see <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png"/>, <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV08.spw5.CASA3_4.png"/>, and <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png"/> for examples on the first data set. You can see the effect of a close pair of atmospheric ozone absorption lines at about 343.2 GHz that makes Tsys larger near that frequency in all antennas. Applying the Tsys calibration tables will minimize the contribution of these atmospheric lines. Again DV04 stands out with its very high Tsys. Although not present in the first data sets, Antenna DV12 exhibits periodic spikes in Tsys vs. frequency for one polarization (see <xr id="Uid___A002_X215db8_X392.tdm.tsys.3c279.DV11.spw5.CASA3_4.png"/> for an example from a later data set). It may or may not be possible to calibrate that behavior out. We will make a note to look carefully at DV12 further on in the calibration process.<br />
<br />
===WVR===<br />
The WVR calibration uses observations of the wings of the 183 GHz atmospheric water line to correct for phase variations as a function of time. As noted in the tsys section, this run of gencal will append to existing WVR produced tables. To avoid this, preexisting wvrgcal data is removed. <br />
<source lang="python"><br />
#In CASA<br />
#Removing existing WVR information<br />
os.system('rm -rf *.wvrgcal')<br />
for asdm in basename_all:<br />
wvrgcal(vis=asdm+'.ms',caltable=asdm+'.wvrgcal',toffset=-1)<br />
</source><br />
<br />
===Antenna Positions===<br />
The antenna position table reflects refinements in the measured positions of the antennas from those stored in the data. gencal will now be used put antenna position data into each observation. Again, gencal will merely append to existing antenna position data, ruining any subsequent results. We start by removing any existing antenna position refinements, followed by defining the antenna names, then their refinements (both as arrays), finally running gencal to create the information CASA can refer to for antenna positions.<br />
<source lang="python"><br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X1ff7b0_Xb.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:21]+'.antpos')<br />
antenna='DV02,DV04,DV06,DV07,DV08,DV09,DV10,DV11,PM01,PM02,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00034, 0.00092, 0.00027, #PM02-A017 Before July 1<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X3a.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:22]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X3b9.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X2181fb_X49.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:22]+'.antpos')<br />
antenna='DV01,DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
-0.00004, 0.00026, 0.00019, #DV01-A137<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X1ff7b0_X1c8.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV06,DV07,DV08,DV09,DV10,DV11,PM01,PM02,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00034, 0.00092, 0.00027, #PM02-A017 Before July 1<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X1f7.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X4d7.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X215db8_X18.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:22]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X215db8_X1d5.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X215db8_X392.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
</source><br />
<br />
===Applycal===<br />
<br />
We are now ready to apply the Tsys and the WVR calibration tables to the data with {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. Again, we loop through all the datasets. It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected, so in addition to looping over data sets we define the list of unique source names and loop over these. Then by setting '''gainfield''' and '''field''' to the same value we ensure that Tsys and WVR calibrations are only applied to the source for which they are measured. Because the source has a different name in the Northern Mosaic and the Southern Mosaic, we will carry out two loops. We will only correct '''spw''' 1 and 3, our science windows, because we will drop the other data in a moment.<br />
<br />
The applycal task now has much more flexibility for interpolating and applying calibrations derived in one spectral window to another, even if they do not share the same spectral shape (number of channels and channel width). This new functionality is used below to interpolate the TDM (128 channel) Tsys measurements to the FDM (3840 channel) spectral windows. This is controlled through the spectral window mapping parameter *spwmap*. Because this can be a bit confusing, we've written a "helper" function that will tell you what you should put for the Tsys calibration table part of spwmap. We only need to run it on one of the datasets because they are all the same in this regard<br />
<br />
<source lang="python"><br />
# In CASA<br />
from recipes.almahelpers import tsysspwmap<br />
tsysspwmap(vis='uid___A002_X207fe4_X3a.ms',tsystable='uid___A002_X207fe4_X3a.tdm.tsys')<br />
</source><br />
<br />
This will print to your screen: [0, 5, 5, 7, 5, 5, 5, 7]. Recall that the TDM spectral windows are spw=5 and 7 and the FDM spectral windows are 1 and 3. This spwmap tells applycal to use the Tsys information in spectral window 5 for spectral window 1; and to use the information in spectral window 7 for spectral window 3. Beyond that, it is only important that there are placeholders for the other spectral windows, its also useful to note that you need not give placeholders for spectral window ids larger than the largest spectral window you need to use, in this case 7.<br />
<br />
You will also need to put in placeholders for other tables that you give the gaintables. So if the Tsys table is 2nd in the list, spwmap=[[],[0,5,5,7,5,5,5,7],[]]<br />
<br />
Now run the applycal commands.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# A new list of file names that contain only data from the Northern Mosaic<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
field_names_north = ['Titan','3c279','NGC*']<br />
<br />
for asdm in basename_north:<br />
print "Apply Tsys, WVR, and Antenna Position calibrations to "+asdm<br />
for field in field_names_north:<br />
applycal(vis=asdm+".ms", spw='1,3', <br />
field=field, gainfield=['',field,field],<br />
interp=['','linear,spline','nearest'], <br />
gaintable=[asdm+'.antpos',asdm+'.tdm.tsys',asdm+'.wvrgcal'],<br />
spwmap=[[],[0, 5, 5, 7, 5, 5, 5, 7],[]],<br />
flagbackup=False, calwt=True)<br />
<br />
# A new list of file names that contain only data from the Southern Mosaic<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
field_names_south = ['Titan','3c279','Ant*']<br />
<br />
for asdm in basename_south:<br />
print "Apply Tsys, WVR, and Antenna Position calibrations to "+asdm<br />
for field in field_names_south:<br />
applycal(vis=asdm+".ms", spw='1,3', <br />
field=field, gainfield=["",field,field],<br />
interp=['','linear,spline','nearest'],<br />
gaintable=[asdm+".antpos",asdm+'.tdm.tsys',asdm+'.wvrgcal'],<br />
spwmap=[[],[0, 5, 5, 7, 5, 5, 5, 7],[]], <br />
flagbackup=False, calwt=True)<br />
</source><br />
<br />
where:<br />
<br />
*'''field''': the field ''to'' which we will apply the calibration, <br />
*'''gainfield''': the field ''from'' which we wish to take the calibration table<br />
*'''interp''' = 'nearest' : apply the nearest solution from the calibration table rather than interpolating.<br />
<br />
As you browse through the whole data set, you will probably note some problems along the same lines as the DV04 issue we saw above. We'll apply these as additional data flagging in just a moment.<br />
<br />
==Inspect Data==<br />
We are not quite done with the original ".ms" data sets yet. Before going further it will be useful to use {{plotms}} to show the effects of applying the calibration. In the process we'll take a quick look at each antenna and search for pathologies in the data.<br />
<br />
For this basic inspection, we want to compare the phase and amplitude as a function of frequency and time in the DATA and CORRECTED columns of each measurement set. The CORRECTED column has had the Tsys and WVR calibrations applied and so we expect lower phase scatter and flatter amplitude response as a function of time and frequency. We are looking for antenna-based issues, so cycling through a set of baselines that includes each antenna once will be a good start. We'll focus these plots on the phase+bandpass calibrator, 3c279, and on baselines that include antenna DV11, which we will make our reference antenna in just a bit.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
<br />
Each CASA Measurement Set has up to three "columns" of data: DATA, CORRECTED, and MODEL (though it is possible<br />
for a MS to hold only a DATA column if it has not been processed at all). <br />
<br />
A column entry exists for each data point (baseline, frequency, time). <br />
<br />
The DATA column holds the current raw data, though using split as we just did we can change the definition of<br />
"raw" data. <br />
<br />
The CORRECTED column holds the result of applying one or more calibration tables (e.g., via applycal) to the<br />
DATA column and so represents a corrected version of the DATA column. <br />
<br />
The MODEL column is now deprecated (though it is still possible to use it by explicitly setting usescratch=True).<br />
Instead, the model is stored in the header of the ms. This is a great step forward in terms of saving space and time <br />
to create scratch columns <br />
<br />
To get an intuitive feel for the columns you may wish to explore using plotms (which can plot different data <br />
columns, as seen below) or the browsetable task.<br />
<br />
</pre><br />
<br />
<figure id="plotms_amp_vs_freq_example-data.png"><br />
[[File:plotms_amp_vs_freq_example-data.png|200px|thumb|right|<caption> Example of Amplitude vs. Frequency before correction for the first Northern Mosaic data set.</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_freq_example-corr.png"><br />
[[File:plotms_amp_vs_freq_example-corr.png|200px|thumb|right|<caption> Same baseline as <xr id="plotms_amp_vs_freq_example-data.png"/> but now after correction using WVR and Tsys calibrations.</caption>]]<br />
</figure><br />
<br />
First, we plot amplitude as a function of frequency for 3c279. We start by plotting the DATA column, set color to indicate the two correlations (i.e., the XX and YY polarizations), and ask plotms to iterate over baseline. By setting '''antenna''' to 'DV11&*' we select only baselines that include DV11. We ask plotms to average all data over a very long timescale, '''avgtime''' = 1e8 seconds ~ 3 years or much longer than the time spanned by the whole data set. By setting '''avgscan''' = True we allow {{plotms}} to average across scan boundaries. The result is a plot of average amplitude per channel vs. frequency.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
asdm=basename_all[0]<br />
<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='frequency', yaxis='amp',<br />
selectdata=True, spw='1', <br />
avgtime='1e8',avgscan=True,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data', <br />
showgui = True)<br />
</source><br />
<br />
Notice the green arrows along the bottom of the {{plotms}} window. We asked {{plotms}} to iterate over baseline. As you click the arrows, the plot will rotate from baseline to baseline, always with DV11 so that each antenna shows up once. To see the effect of the calibration, go to the "Axes" tab along the left of the {{plotms}} window and pull down the Data Column menu under the Y Axis. Set this from DATA to CORRECTED and you should see the effects of the calibration. You may need to ensure that the "Force Reload" box is checked before clicking "Plot" (both buttons lie at the bottom of the panel). For the most part things get better (flatter), but as we noted before DV04 is problematic.<br />
<br />
<figure id="plotms_amp_vs_time_north.png"><br />
[[File:plotms_amp_vs_time_north.png|200px|thumb|right|<caption> Example of amplitude vs. time for a northern mosaic data set.</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_time_south.png"><br />
[[File:plotms_amp_vs_time_south.png|200px|thumb|right|<caption> Example of amplitude vs. time for a southern mosaic data set.</caption>]]<br />
</figure><br />
<br />
You can now make analogous calls to examine the phase vs. frequency, amplitude vs. time, and phase vs. time.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='frequency', yaxis='phase',<br />
selectdata=True, spw='1', <br />
avgtime='1e8',avgscan=True,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data', <br />
showgui = True)<br />
<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='time', yaxis='amp',<br />
selectdata=True, spw='1:1200~1300', <br />
avgchannel='1000',avgscan=False,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data', <br />
showgui = True)<br />
<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='time', yaxis='phase',<br />
selectdata=True, spw='1:1200~1300', <br />
avgchannel='1000',avgscan=False,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data', <br />
showgui = True)<br />
</source><br />
<br />
Where:<br />
<br />
* '''spw''' is set to cover only channels 1200~1300 for the time plots in order to isolate time dependent variations from frequency-dependent behavior. Those 101 channels represent only a small part of the total spw 1 bandpass.<br />
* '''avgchannel''' set to a large number causes the plots of phase and amplitude vs. time to average data at all frequencies into a single point for each measurement.<br />
* '''coloraxis''' corr sets the colors to correspond to the two polarizations of the data.<br />
<br />
In each case, you will want to examine each baseline, alternating between the DATA and CORRECTED columns.<br />
<br />
This is a lot of data inspection and that's only for one of 10 data sets! You can iterate across the data by hand, updating "asdm" to refer to each data set in order and cycling between baselines and DATA/CORRECTED. It is also possible to script CASA to show you the key plots in succession (see the next block down). However you approach the infrastructure, you are looking for:<br />
<br />
* Improved scatter and lower variability in phase and amplitude vs. frequency and time. This indicates that the WVR and Tsys calibrations helped. <br />
* Sudden jumps in phase or amplitude as a function of either time or frequency. These may indicate problems with the antenna during that observation.<br />
* Large gradients, especially full wraps, in phase as a function of frequency. This may indicate a problem in the delays, the signal path length to the telescopes.<br />
* Unusual magnitude, scatter, or patterns in any plot - though this may be better explored using plots that show all data together, which we'll make in a moment.<br />
* Missing data. For example, if the phase calibrator drops out for a period of time we will not be able to calibrate and will need to flag the data.<br />
<br />
As you look through, note individual potentially problematic antennas. If ''all'' antennas in a data set appear problematic it may be that your "reference" antenna, DV11 in the example above, is the source of the problem. In this case swap this reference antenna for another and see whether the problem is isolated to your original reference antenna.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
<br />
A brief aside on structure:<br />
<br />
This section (Data Inspection) and the next (Apply Flags) are closely linked. We will present them as two<br />
separate steps. The idea here is that you look through your data, note problems, and then write commands to<br />
flag problematic data. This mimics one approach to writing data reduction scripts for CASA, where you will<br />
group all flagging together into one convenient place. Other CASA guides take a different approach, interleaving <br />
flagging and plotting. There is no "right" answer here. Find an approach to data inspection that works for you.<br />
<br />
</pre><br />
<br />
If you do wish to semi-automate the plot generation, the following sequence will cycle between data and corrected plots for each data set in turn. Type "stop" at any input call to break out.<br />
<br />
'''Note:''' In loops like this involving {{plotms}}, hitting enter before the last dataset completes loading may cause {{plotms}} to stop refreshing the plot window at each step, or cause the window to disappear altogether. This will be fixed in an upcoming CASA release. Right now, you may need to exit CASA and restart to bring up the {{plotms}} window again, but you should be able to continue in the script where you left off.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
user_input = ""<br />
for asdm in basename_all:<br />
# check if a stop has been requested<br />
if user_input == "stop":<br />
break<br />
# Extract antenna list for this data set.<br />
tb.open(asdm+'.ms/ANTENNA', nomodify=True)<br />
ants = tb.getcol('NAME')<br />
tb.close<br />
# Define the reference antenna to make baselines with<br />
ref_ant = 'DV11'<br />
# Loop over antennas<br />
for ant in ants:<br />
# Check if the user wants to stop<br />
if user_input == "stop":<br />
break<br />
# Skip correlation of reference antenna with itself (autocorrelations are flagged anyhow) <br />
if ant == ref_ant:<br />
continue<br />
# Define the baseline with the reference antenna for current antenna<br />
ant_str = ref_ant+'&'+ant<br />
print "Showing baseline "+ant_str+" for data set "+asdm<br />
print "Use this to inspect effect of applying wvrcal and Tsys calibrations."<br />
# Loop over phase and amplitude as axes<br />
for y_axis in ["amp", "phase"]:<br />
# Make 'before' plot for frequency x-axis<br />
print "... "+y_axis+" vs. frequency for DATA:" <br />
plotms(vis=asdm+'.ms', spw='1', field='3c279',<br />
antenna=ant_str, xaxis="frequency", yaxis=y_axis,<br />
avgtime="1e8", avgscan=True, coloraxis="corr",<br />
ydatacolumn="data", showgui = True)<br />
user_input = raw_input("Hit <ENTER> to see CORRECTED data [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
# Make 'after' plot for frequency x-axis<br />
print "... "+y_axis+" vs. frequency for CORRECTED:"<br />
plotms(vis=asdm+'.ms', spw='1', field='3c279',<br />
antenna=ant_str, xaxis="frequency", yaxis=y_axis,<br />
avgtime="1e8", avgscan=True, coloraxis="corr",<br />
ydatacolumn="corrected", showgui = True)<br />
user_input = raw_input("Hit <ENTER> to proceed to next plot [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
# Make 'before' plot for time x-axis<br />
print "... "+y_axis+" vs. time for DATA:" <br />
plotms(vis=asdm+'.ms', spw='1:1200~1300', field='3c279',<br />
antenna=ant_str, xaxis="time", yaxis=y_axis,<br />
avgchannel="1000", coloraxis="corr",<br />
ydatacolumn="data", showgui = True)<br />
user_input = raw_input("Hit <ENTER> to see CORRECTED data [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
# Make 'after' plot for time y-axis<br />
print "... "+y_axis+" vs. time for CORRECTED:"<br />
plotms(vis=asdm+'.ms', spw='1:1200~1300', field='3c279',<br />
antenna=ant_str, xaxis="time", yaxis=y_axis,<br />
avgchannel="1000", coloraxis="corr",<br />
ydatacolumn="corrected", showgui = True)<br />
user_input = raw_input("Hit <ENTER> to proceed to next plot [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
</source><br />
<figure id="plotms_amp_vs_uvdist_north.png"><br />
[[File:plotms_amp_vs_uvdist_north.png|200px|thumb|right|<caption> Example of amplitude vs. uv-distance for 3c279 in the first northern mosaic data set.</caption>]]<br />
</figure><br />
<br />
<figure id="plotms_amp_vs_freq_3c279.png"><br />
[[File:plotms_amp_vs_freq_3c279.png|200px|thumb|right|<caption> Example of amplitude vs. frequency for 3c279 in the second northern mosaic data set.</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_freq_Titan.png"><br />
[[File:plotms_amp_vs_freq_Titan.png|200px|thumb|right|<caption> Example of amplitude vs. frequency for Titan in the second northern mosaic data set. Note the strong line (this is CO 3-2)!</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_freq_Antennae.png"><br />
[[File:plotms_amp_vs_freq_Antennae.png|200px|thumb|right|<caption> Example of amplitude vs. frequency for the Antennae in the second northern mosaic data set. The CO(3-2) line is visible.</caption>]]<br />
</figure><br />
<br />
A detailed explanation of the procedure is a bit outside the scope of this guide (for more on python see http://www.python.org/ and for more on the CASA toolkit see http://casa.nrao.edu/), but the basic process is to loop over each data set, baseline with the reference antenna (here DV11), and y-axis of interest (phase or amplitude) then plot the effect of the calibration vs. frequency and time for each combination. Running this to step through the data will give you about 200 "before and after" plots from which you could note a subset of problematic cases to be followed up by hand. Many other strategies to inspect the data are also viable.<br />
<br />
With the Tsys and WVR calibrations applied successfully and the ''a priori'' flagging taken care of we will now {{split}} out the corrected data. We will keep only the corrected data, specified via '''datacolumn''', and only spectral window 1, which contains the FDM (high spectral resolution) observations of the CO(3-2) line. Setting '''keepflags'''=False tells {{split}} not to carry over any fully flagged rows from the original data set to the new MS. We give the new MS files the extension ".wvrtsys.ms" to indicate that they have been corrected for WVR and Tsys effects. Because split will not overwrite existing files, we remove any previous versions of the new MS before beginning.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvrtsys.ms')<br />
print "Splitting out corrected data for "+asdm<br />
split(vis=asdm+'.ms', outputvis=asdm+'.wvrtsys.ms', <br />
datacolumn='corrected', spw='1', keepflags=False)<br />
</source><br />
<br />
Be patient, {{split}} may take awhile. The WVR and Tsys-corrected data now sit in the DATA column of the new measurement sets, which have only one spectral window (now labeled spectral window 0 though it was spectral window 1 in the original data). You may wish to run {{listobs}} to illustrate the changes:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
os.system('rm '+asdm+'.wvrtsys.listobs.txt')<br />
listobs(vis=asdm+'.wvrtsys.ms', listfile=asdm+'.wvrtsys.listobs.txt', verbose=True)<br />
</source><br />
<br />
Note the new spectral window information:<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
2011-08-05 01:07:08 INFO listobs Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
2011-08-05 01:07:08 INFO listobs SpwID #Chans Frame Ch1(MHz) ChanWid(kHz)TotBW(kHz) Ref(MHz) Corrs <br />
2011-08-05 01:07:08 INFO listobs 0 3840 TOPO 344845.586 488.28125 1875000 344908.33 XX YY <br />
<br />
</pre><br />
<br />
<br />
Next we will do a bit more inspection using {{plotms}} to look at whole data sets. This will help us identify missing data or look for egregious outliers.<br />
<br />
First we plot amplitude versus time (see <xr id="plotms_amp_vs_time_north.png"/> and <xr id="plotms_amp_vs_time_south.png"/>), averaging over all channels (by setting '''avgchannel''' to the very large value 10,000). We colorize by field so that scans on Titan are red, the bandpass and phase calibrator 3c279 is black (and orange in the Southern Mosaic where it has two field IDs), and the Antennae mosaic appears as a range of colors (one per pointing).<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
xaxis='time', yaxis='amp', <br />
avgchannel='3840',coloraxis='field', showgui = True)<br />
dummy_string = raw_input("Examining amplitude vs. time for "+asdm+" . Hit <Enter> to proceed.")<br />
</source><br />
<br />
Here look for:<br />
<br />
* Missing data. The source needs to be flanked by phase calibrator scans, if those are missing for any reason we need to flag the appropriate time range.<br />
* Dramatic outliers. Does the source suddenly get very bright or the otherwise bright calibrator appear anomalously faint for a brief time? This likely indicates problematic data that should be identified and flagged. You can use the "select" (box with green plus along the bottom row in plotms) and "locate" (magnifying glass) buttons in {{plotms}} to isolate and identify problem data (it will print to the log).<br />
* Smooth variation with time. A sudden jump may indicate a problem and often the safest approach is to flag data near a discontinuity.<br />
<br />
Look through the amplitudes vs. time for each data set (remember that we've already examined the phases vs. time and amplitude vs. time for individual baselines above).<br />
<br />
There are two other very useful "averaging" plots worth making. First, we plot amplitude as a function of u-v distance (projected antenna separation). Discontinuities and spikes in this plot are often from non-astrophysical sources. In the phase analog to the plot, the effects of atmospheric decorrelation can be assessed from increased scatter at longer u-v distances. While using the moon Titan as our flux calibrator, we may want to watch for flaring amplitudes at short u-v distances. These may indicate that Saturn is contaminating our beam. For a perfect, bright point source, we expect flat amplitudes as a function of u-v distance at the source amplitudes. <xr id="plotms_amp_vs_uvdist_north.png"/> shows an example of this plot, generated via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field='3c279',<br />
xaxis='uvdist', yaxis='amp', <br />
avgchannel='3840',coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Examining amplitude vs. UV Distance for 3c279 for "+asdm+" . Hit <Enter> to proceed.")<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field='Titan',<br />
xaxis='uvdist', yaxis='amp', <br />
avgchannel='3840',coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Examining amplitude vs. UV Distance for Titan for "+asdm+" . Hit <Enter> to proceed [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
<br />
<br />
It can also be useful to examine the average amplitude as a function of frequency for each target. This allows one to check for lingering atmospheric effects, unexpected line emission or absorption in the calibrators, or decreased sensitivity due to "roll-off" of the telescope sensitivity at the band edges. These plots are created by the sequence of commands below, where we have broken up the script to loop separately over the Northern and Southern Mosaics to reflect the different source names.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
field_names = ["3c279","Titan","NGC*"]<br />
<br />
for asdm in basename_north:<br />
for field in field_names:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field=field,<br />
xaxis='frequency', yaxis='amp', <br />
avgtime='1e8',avgscan=True, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Examining amplitude vs. frequency for "+field+" in "+asdm+" . Hit <Enter> to proceed.")<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
field_names = ["3c279","Titan","Ant*"]<br />
<br />
for asdm in basename_south:<br />
for field in field_names:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field=field,<br />
xaxis='frequency', yaxis='amp', <br />
avgtime='1e8',avgscan=True, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Examining amplitude vs. frequency for "+field+" in "+asdm+" . Hit <Enter> to proceed.")<br />
</source><br />
<br />
<br />
For this command notice that we can see the CO(3-2) line in the Antennae even before calibration (see <xr id="plotms_amp_vs_freq_Antennae.png"/>) and that Titan also shows evidence of a strong line (also <xr id="plotms_amp_vs_freq_Titan.png"/>)! This will need to be flagged before we can use Titan to calibrate the flux scale of our data.<br />
<br />
This suite of plots (along with the earlier inspection of the Tsys tables) gives us the tools we need to identify problematic data through the data sets. We use this to generate a set of inspection-driven {{flagdata}} commands for each data set. We apply these before the bandpass and gain calibration.<br />
<br />
==Apply Flagging==<br />
Based on this inspection and the other plots we have made, we now flag problematic portions of the data. We break up the flags by reason for flagging in order to illustrate the process. As you reduce your own data it may be more efficient to group flags by data set and make use of the flagcmd command. Except for the "post-calibration" flagging, the inspection plots that we just looked through have already revealed all of the problems that we flag. We structure the guide so that the flagging is grouped in one place.<br />
<br />
As before, we may wish to reset our flags before beginning (particularly if one iterates this process) via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
for asdm in basename_all:<br />
flagdata(vis = asdm+'.wvrtsys.ms',mode='unflag', flagbackup = False)<br />
</source><br />
<br />
Remember that we dropped the flagged data when splitting out after the WVR and Tsys calibration, so this should not undo your "A Priori" flagging of shadowed data, autocorrelations, etc.. In any case this unflagging step is not necessary during the first iteration.<br />
<br />
* '''Edge Channels'''<br />
<br />
ALMA's sensitivity decreases near the edge of the baseband and it is often useful to check for a 'roll-off' in sensitivity near the edge of the band. This will appear as a downturn in amplitude as a function of channel near the edge of the window in the uncalibrated data, as a flaring due to increased noise at the spw edges in the calibrated data. It will also be visible in the amplitude part of the bandpass calibration table. Because our FDM spw does not cover the full baseband, we do not see a strong roll off in our data (see <xr id="amp_vs_channel_example.png"/>), where there is only a mild hint of a roll-off at the high end) but we do flag a (very) few channels at the high and low-frequency edge of the data set to be safe.<br />
<br />
<figure id="amp_vs_channel_example.png"><br />
[[File:amp_vs_channel_example.png|200px|thumb|right|<caption> Amplitude vs. channel for one uncalibrated antenna pair. This kind of plot can be inspected to get an idea of the presence or magnitude of any roll-off in sensitivity near the edges of the spectral window.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
for asdm in basename_all:<br />
flagdata(vis = asdm+'.wvrtsys.ms', mode='manual', spw = '0:0~7,0:3831~3839', flagbackup = False)<br />
<br />
for asdm in basename_all:<br />
flagdata(vis = asdm+'.wvrtsys.ms', mode='manual', spw = '0:3260~3320', flagbackup = False)<br />
</source><br />
<br />
* '''Problematic Tsys measurements'''<br />
<br />
Above we noted issues with the Tsys measurements for both DV04 and DV12. We flag the affected data. Each of these issues should be visible in the Tsys plots you made above (e.g., see <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png"/> and <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png"/>).<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X1ff7b0_Xb"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV04', flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X3b9"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X2181fb_X49"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X1ff7b0_X1c8"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV04',flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X1f7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X4d7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X215db8_X18"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X215db8_X1d5"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X215db8_X392"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
</source><br />
<br />
* '''Unreliable Short-Spacing Measurements on Titan'''<br />
<br />
<figure id="amp_vs_uv_titan_obs.png"><br />
[[File:amp_vs_uv_titan_obs.png|200px|thumb|right|<caption> Observed amplitude vs. uv-distance for observations of Titan in the first data set. Note the scatter for low projected antenna separations. We will flag these short-spacing data, which may reflect contamination by Saturn, and use only the more extended baselines for flux calibration.</caption>]]<br />
</figure><br />
<br />
Saturn may contaminate the short u-v spacings from Titan. In any case these often show significant scatter (<xr id="amp_vs_uv_titan_obs.png"/>), so we flag them. There are still enough baselines to determine a good amplitude calibration for each antenna.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X1ff7b0_Xb"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~50', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~40', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X3b9"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~50', flagbackup = False)<br />
<br />
asdm="uid___A002_X2181fb_X49"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~30', flagbackup = False)<br />
<br />
asdm="uid___A002_X1ff7b0_X1c8"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~50', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X1f7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~30', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X4d7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~30', flagbackup = False)<br />
</source><br />
<br />
* '''Delay Issues''' <br />
<br />
<figure id="phase_vs_freq_DV13.png"><br />
[[File:phase_vs_freq_DV13.png|200px|thumb|right|<caption> Phase vs. frequency for DV13 in a data set where this antenna shows evidence of imperfect delay calibration.</caption>]]<br />
</figure><br />
<br />
DV13 and a few other antennas show signatures of an imperfect delay calibration. This is most easily identified via strong "wrapping" of phase as a function of frequency (see <xr id="phase_vs_freq_DV13.png"/>). Such effects can be calibrated out with mild delay issues largely accounted for by the bandpass solution. The phase wrapping in DV13 seems weak enough that we will trust the calibrations to remove it. For a more extreme example see the CASA guide describing the calibration of [[NGC3256Band3]].<br />
<br />
* '''Missing Phase Calibrator Observations'''<br />
<br />
<figure id="amp_vs_time_missing_scans.png"><br />
[[File:amp_vs_time_missing_scans.png|200px|thumb|right|<caption> Amplitude vs. time colored by field for a data set where the final visit to the phase calibrator is missing. We will flag the last set of source data to ensure that each visit to the source is flanked in time by visits to the phase calibrator.</caption>]]<br />
</figure><br />
<br />
As a general rule, we want to be sure that observations of the phase calibrator (3c279) bracket each source observation. Two of the data sets do not include a final phase calibrator observation (see <xr id="amp_vs_time_missing_scans.png"/>) and for those two cases we flag the affected source observations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X207fe4_X3b9"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', timerange='00:53:47~01:08:00',flagbackup = False)<br />
<br />
asdm="uid___A002_X215db8_X18"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV10',timerange='19:46:20~20:34:40',flagbackup=False)<br />
</source><br />
<br />
* '''Unexpected Scatter or Discontinuity in the Data'''<br />
<br />
For several antennas we find sudden jumps in the phase of the phase calibrator as a function of time. These are visible in the plots of uncalibrated phase vs. time for single baselines above, and we show an example in <xr id="phase_vs_time_DV09.png"/>. It will not be possible to effectively interpolate the phase between measurements when we see these discontinuities. The safest approach is to flag the source data across these jumps. We do so here (though note that the last two flaggings are borderline cases).<br />
<br />
<figure id="phase_vs_time_DV09.png"><br />
[[File:phase_vs_time_DV09.png|200px|thumb|right|<caption> Phase vs. time for DV09 on a problematic day. It may prove problematic to calibrate the data near this discontinuity so we flag data near this time.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV09', timerange='21:24:09~21:35:35', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X1f7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV09',timerange='23:30:52~24:10:00',flagbackup=False)<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='PM01',timerange='23:16:50~24:10:00',flagbackup=False)<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='PM03',timerange='23:16:50~24:10:00',flagbackup=False)<br />
</source><br />
<br />
* '''Outliers Visible After Calibration'''<br />
<br />
<figure id="amp_vs_uvdist_outliers.png"><br />
[[File:amp_vs_uvdist_outliers.png|200px|thumb|right|<caption> Amplitude vs. u-v distance ''after'' calibration. Note the outlying data. We track these down using the select (box with green "+") and locate (magnifying glass) features inside plotms and identify several problematic baselines across our data. ''Note that you cannot make this plot at this point in the guide, these pathologies become evident after calibration, requiring an iterative approach to reduction.''</caption>]]<br />
</figure><br />
<br />
Often issues with the data may become evident after calibration (i.e., after the next few steps that we apply). These data can appear as outliers in diagnostic plots for the calibrated data or even show up in the imaging stages. Once these are identified, best practice is to apply this new flagging then redo the calibration (if the issue is very minor, then re-calibrating may not be necessary).<br />
<br />
<source lang="python"><br />
# In CASA<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', timerange='21:18:00~21:22:15', flagbackup=False)<br />
<br />
asdm="uid___A002_X2181fb_X49"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV01&DV04', flagbackup=False)<br />
</source><br />
<br />
Now that we've applied our flagging, back up the flags as version "User" using {{flagmanager}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
flagmanager(vis=asdm+'.wvrtsys.ms',mode='save',versionname ='User')<br />
</source><br />
<br />
Applying this flagging will remove the most egregious pathologies from the data. We are now ready to calibrate the data.<br />
<br />
==Bandpass Calibration==<br />
<br />
We begin by calibrating the phase and amplitude response of each antenna as a function of frequency, called "bandpass calibration." We have already seen that the data contain smooth but systematic variations in both phase and amplitude as a function of frequency. We can see this again in a more compact form by plotting phase as a function of frequency for all baselines associated with each antenna (<xr id="plotms_phase_vs_freq_example.png"/>).<br />
<br />
<figure id="plotms_phase_vs_freq_example.png"><br />
[[File:plotms_phase_vs_freq_example.png|200px|thumb|right|<caption> Phase vs. frequency for the bandpass calibrator, 3c279 in the first data set. We plot all baselines with DV02, averaged over time, and show only the 'XX' correlation.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
plotms(vis= asdm+'.wvrtsys.ms', <br />
xaxis='freq', yaxis='phase', <br />
selectdata=True, field='3c279', correlation='XX',<br />
avgtime='1e8', avgscan=True, antenna='*&*',<br />
coloraxis='baseline', iteraxis='antenna', showgui = True)<br />
dummy_string = raw_input("Plotting phase vs. frequency for "+asdm+". Hit <Enter> for next data set or cycle through antennas [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
Each plot shows phase as a function of frequency for all baselines with one antenna for 3c279. We plot only the 'XX' correlation, colorizing by baseline. With '''iteraxis''' set to antenna the green arrows at the bottom of {{plotms}} will cycle through antennas. By using '''avgscan''' and a large '''avgtime''' we average all scans and integrations. <br />
<br />
The phase (and amplitude) also varies as a function of time, as we saw before. Here are the similar plots for phase vs. time (see <xr id="Uid_A002_X1ff7b0_Xb-phasecont.png"/>).<br />
<br />
<figure id="Uid_A002_X1ff7b0_Xb-phasecont.png"><br />
[[File:Uid_A002_X1ff7b0_Xb-phasecont.png|200px|thumb|right|<caption> Phase vs. time for the bandpass calibrator, 3c279. Averaged over channel. Only baselines with antenna DV02, and corr='XX'</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
plotms(vis= asdm+'.wvrtsys.ms', <br />
xaxis='time', yaxis='phase', <br />
selectdata=True, field='3c279', <br />
spw='0:1200~1300', antenna='*&*',correlation='XX',<br />
avgchannel='1000', avgscan=True, <br />
coloraxis='baseline', iteraxis='antenna', showgui = True)<br />
dummy_string = raw_input("Plotting phase vs. time for "+asdm+". Hit <Enter> for next data set or cycle through antennas [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
<xr id="Uid_A002_X1ff7b0_Xb-phasecont.png"/> shows that the phase varies with time. We need to take this temporal variation into account when we solve for the frequency variations. Therefore we carry out the bandpass calibration in two steps. First, we use {{gaincal}} to solve for the variation of phase as a function of time for 3c279 on very short timescales. We set {{gaincal}} to derive a separate phase solution for each antenna every integration by setting '''solint''' to 'int'. We solve, averaging together only a small fraction of the total bandpass (channels 1100-1300) to avoid the effects of the phase vs. frequency behavior. We will then apply this solution to remove time-dependent behavior when we solve for the frequency response of the antennas with {{bandpass}}.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
An integration is the smallest time quantum of observation in the data, usually a few seconds. <br />
You can check the integration length for each scan in listobs. <br />
</pre><br />
<br />
<source lang="python"><br />
#In CASA<br />
<br />
for asdm in basename_all:<br />
print "Running a short solution interval phase calibration for "+asdm<br />
os.system('rm -rf '+asdm+'.bpphase.gcal')<br />
gaincal(vis = asdm+'.wvrtsys.ms',<br />
selectdata=True,field = '3c279',spw = '0:1100~1300',<br />
caltable = asdm+'.bpphase.gcal',<br />
solint = 'int',refant = 'DV11',calmode='p')<br />
</source><br />
<br />
Now we use {{bandpass}} to solve for the frequency response of each antenna. To do this, we average all data in time by setting '''solint''' to 'inf' (that is, 'infinite'). We allow combination across scans and the different field IDs found for 3c279 by setting '''combine''' to "scan,field". We apply the phase vs. time calibration that we just derived on-the-fly using the parameter "gaintable".<br />
<br />
<source lang="python"><br />
for asdm in basename_all:<br />
print "Running a bandpass calibration for "+asdm<br />
os.system('rm -rf '+asdm+'.bandpass.bcal')<br />
bandpass(vis = asdm+'.wvrtsys.ms',<br />
field = '3c279',<br />
gaintable = asdm+'.bpphase.gcal',<br />
caltable = asdm+'.bandpass.bcal',<br />
bandtype='B',<br />
solint = 'inf',combine = 'scan,field', solnorm=True,refant = 'DV11',<br />
minblperant=3,minsnr=2,fillgaps=62)<br />
</source><br />
<br />
in these calls:<br />
<br />
*'''caltable''' specifies the output calibration table<br />
*'''gaintable''' specifies any calibration tables to be applied "on the fly" to the data before solving.<br />
*'''solint''' sets the time interval for which solutions are derived for each antenna.<br />
*'''refant''' set the reference antenna, here DV11, which is defined to have zero correction by construction.<br />
*'''calmode''' 'p' sets {{gaincal}} to calibrate the phase only, other options are 'a'mplitude or 'ap' - amplitude and phase.<br />
*'''minblperant''' sets the minimum baselines required per antenna for a successful solution.<br />
*'''minsnr''' sets the minimum signal-to-noise ratio required for a successful solution.<br />
*'''bandtype''' here 'B' tells {{bandpass}} to solve for the phase and frequency response of each antenna in each channel, averaging data in time across the solution interval.<br />
*'''fillgaps''' tells {{bandpass}} to interpolate across channel gaps 1 channel wide.<br />
*'''solnorm''' tells {{bandpass}} to normalize the bandpass amplitude and phase corrections to have magnitude unity. The absolute scale of the calibration will come from our later {{gaincal}} solutions.<br />
<br />
Do not worry about the message "Insufficient unflagged antennas" when running the {{bandpass}} task. This indicates that {{bandpass}} is failing on the flagged edge channels, which is expected.<br />
<br />
It is now a good idea to plot both sets of solutions to look for irregularities, especially:<br />
<br />
* discontinuities in the phase vs. time solution<br />
* rapid wrapping of phase in either phase vs. time or bandpass solution<br />
* large roll-off in the amplitude response near the band edge in the bandpass solution<br />
* large scatter in any solution.<br />
<br />
We loop through and using analysis utils, again generating .png files of each calibration. As the bandpass plots take a while you may want to go have a cup of coffee and inspect them using your favorite image viewer. Otherwise, switch the '''interactive''' parameter to True to see them in real time instead.<br />
<br />
<figure id="uid___A002_X1ff7b0_X1c8.bpphase.page1.png"><br />
[[File:uid___A002_X1ff7b0_X1c8.bpphase.page1.png|200px|thumb|right|<caption> Short interval phase vs. time solution carried out and applied during bandpass calibration, here for the first set of antennas for the first data set. This solution removes any systematic variations in phase vs. time.</caption>]]<br />
</figure><br />
<figure id="Uid___A002_X1ff7b0_X1c8.bandpass.DV02.spw0.t1.CASA3.4.png"><br />
[[File:Uid___A002_X1ff7b0_X1c8.bandpass.DV02.spw0.t1.CASA3.4.png|200px|thumb|right|<caption> Bandpass amplitude solution for the first set of antennas and the first data set.</caption>]]<br />
</figure><br />
<figure id="uid___A002_X1ff7b0_Xb.bcal_phase.page1.png"><br />
[[File:uid___A002_X1ff7b0_Xb.bcal_phase.page1.png|200px|thumb|right|<caption> Phase vs. frequency calibration from the bandpass calibration for the first set of antennas and the first data set.</caption>]]<br />
</figure><br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
os.system('rm -rf cal_plots/*bandpass*.png')<br />
for asdm in basename_all:<br />
plotbandpass(caltable=asdm+'.bandpass.bcal',<br />
field='',xaxis='freq',yaxis='both',<br />
figfile='cal_plots/'+asdm+'.bandpass.png',<br />
showatm=True,interactive=False,subplot=42)<br />
</source><br />
<br />
==Absolute Flux Calibration==<br />
<br />
The bandpass calibration will account for the phase and amplitude response of our antennas as a function of frequency. We now solve for the absolute flux scale of the data by referencing to Titan and in the next section we will calibrate the phase and amplitude behavior of the antennas as a function of time.<br />
<br />
Before using Titan to set the flux, there is an important systematic to account for. When we looked at the integrated spectra of our targets above, remember that Titan showed a whopping spectral line, in fact the same CO(3-2) line that we wish to observe in the Antennae. We will set the flux of Titan (and thus all of our data) by referencing to a model in casa that does not account for this line. Therefore we need to flag the part of the Titan observations contaminated by the line before we calibrate (you can see the affected channel range in <xr id="Antennae-TitanLine.png"/>). We run the following additional flagging step:<br />
<br />
<figure id="Antennae-TitanLine.png"><br />
[[File:Antennae-TitanLine.png|200px|thumb|right|<caption> Uncalibrated amplitude vs. channel plot for the flux calibrator, Titan (uid___A002_X1ff7b0_Xb dataset). Averaged over time, corr='XX', and colorized by baseline.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Flagging CO(3-2) in Titan for "+asdm<br />
flagdata(vis=asdm+'.wvrtsys.ms',flagbackup=False, <br />
field='Titan', spw='0:1100~1700')<br />
<br />
for asdm in basename_all:<br />
flagmanager(vis =asdm+'.wvrtsys.ms',mode = 'save',versionname = 'Calibration')<br />
</source><br />
<br />
Next, we will use the {{setjy}} task to read the predicted complex visibilities for Titan into the MODEL column of each data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
for asdm in basename_all:<br />
print "Reading model for Titan into "+asdm<br />
setjy(vis = asdm+'.wvrtsys.ms',field = 'Titan',<br />
usescratch=False,scalebychan=True,<br />
standard = 'Butler-JPL-Horizons 2010')<br />
</source><br />
<br />
{{setjy}} will output the flux of Titan to the CASA logger and it is worth recording this information. The flux of Titan at these frequencies is about 2.9 Jy. For example, for dataset uid___A002_X1ff7b0_Xb.wvrtsys.ms:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Titan (fld ind 1) spw 0 [I=2.8614, Q=0, U=0, V=0] Jy, (JPL-Butler Solar System Object)<br />
</pre><br />
<br />
Now we are going to take a look at the titan model for one dataset<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis ='uid___A002_X1ff7b0_X1c8.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='model', field='Titan',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
<br />
plotms(vis ='uid___A002_X1ff7b0_X1c8.wvrtsys.ms', xaxis='uvdist', yaxis='phase',<br />
ydatacolumn='model', field='Titan',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
</source><br />
<br />
<figure id="2010_titan_model.png">[[File:2010_titan_model.png|thumb|right|200px|<caption>Titan model prodcued by 'Butler-JPL-Horizons 2010'.</caption>]]</figure><br />
<figure id="2012_titan_model.png">[[File:2012_titan_model.png|thumb|right|200px|<caption>Titan model prodcued by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation made in this section uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="2010_titan_model.png"/> and <xr id="2012_titan_model.png"/> show the differences in the Titan models produced using these two standards. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Gain (Phase and Amplitude) Calibration==<br />
<br />
With the flux now properly scaled, we will calibrate the phase and amplitude behavior of the antennas as a function of time.<br />
<br />
We begin by running a short-solution interval {{gaincal}} to solve for phase variation on short timescales during observations of our two calibrators, with '''solint''' set to "int". By applying this on-the-fly, we can remove any decorrelation in the data due to phase scatter when we solve for the amplitude calibration. However, there is no benefit to using this short-timescale solution to calibrate the source because we only have information on the gain during calibrator visits (though see the Imaging portion of this guide). Instead we will solve for the gains to apply to the source using a longer '''solint''' in just a moment.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Carrying out short timescale phase solution for "+asdm<br />
os.system('rm -rf '+asdm+'.intphase.gcal')<br />
gaincal(vis=asdm+'.wvrtsys.ms',<br />
gaintable=asdm+'.bandpass.bcal', <br />
caltable=asdm+'.intphase.gcal',<br />
calmode='p',<br />
field='Titan,3c279',<br />
spw='0:40~3800',<br />
refant='DV11', solint='int',minsnr=2.0, minblperant=4)<br />
</source><br />
<br />
Now we derive the longer timescale phase calibration table using '''solint''' set to "inf", but not allowing scan combination. This calibration has higher signal to noise due to combining more data, and for the purposes of correcting the source, it is just as precise as the short timescale solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Carrying out longer timescale phase solution for "+asdm<br />
os.system('rm -rf '+asdm+'.scanphase.gcal')<br />
gaincal(vis=asdm+'.wvrtsys.ms',<br />
gaintable=asdm+'.bandpass.bcal', <br />
caltable=asdm+'.scanphase.gcal',<br />
calmode='p',<br />
field='Titan,3c279',<br />
spw='0:40~3800',<br />
refant='DV11', solint='inf',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
Now we apply the short-timescale phase solution and carry out a scan length ('''solint''' set to "inf") calibration of the data using '''calmode''' of 'ap'.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Solving for longer (scan) interval amplitude solution for "+asdm<br />
os.system('rm -rf '+asdm+'.amp.cal')<br />
gaincal(vis = asdm+'.wvrtsys.ms',<br />
gaintable =[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'],<br />
caltable = asdm+'.amp.cal',<br />
calmode='ap',<br />
field = 'Titan,3c279',<br />
spw='0:40~3800',<br />
refant = 'DV11',solint = 'inf', minblperant=4)<br />
</source><br />
<br />
This "amp.cal" solution gives us the amplitude variations as a function of time, but they are not yet pinned to a realistic scale except in the case of Titan, where we have solved using the model input by {{setjy}}. We will set the flux of our secondary calibrator 3c279 with reference to Titan using {{fluxscale}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Scaling amplitude calibration to match Titan for "+asdm<br />
os.system('rm -rf '+asdm+'.flux.cal')<br />
fluxscale(vis = asdm+'.wvrtsys.ms',<br />
caltable = asdm+'.amp.cal',<br />
fluxtable = asdm+'.flux.cal',<br />
reference = 'Titan',<br />
transfer = '3c279')<br />
</source><br />
<br />
This new correctly-scaled flux table ".flux.cal" replaces the previous ".amp.cal" table as the correct amplitude calibration table to apply to the data, i.e., the ".flux.cal" contains both the time variability of the amplitude solved for in ".amp.cal" and the correct flux scaling set with {{fluxscale}}.<br />
<br />
Fluxscale will output the derived flux for 3c279 to the CASA logger. This information is worth noting. We find that the flux of 3c279 is 10.41 Jy, by averaging the fluxes obtained from the ten available datasets. This value agrees within 10% with the most recent 0.850 millimeter measurements from the SMA calibrator list [http://sma1.sma.hawaii.edu/callist/callist.html] : (03 Feb 2014, SMA 10.93 ± 0.49).<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated, Butler-JPL-Horizons 2012, flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for 3c279 will be slightly higher. The flux of 3c279, when averaged over all 10 measurement sets, will be 10.80 Jy.<br />
</div><br />
<br />
Now we plot the final phase and amplitude calibration tables for each data set. A well-behaved calibration table will show smooth variations as a function of time. Sudden jumps or wild variations among the antenna amplitude gains should prompt further investigation and possibly additional flagging.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Plotting solutions for "+asdm<br />
plotcal(caltable = asdm+'.scanphase.gcal',<br />
xaxis = 'time', yaxis = 'phase',<br />
iteration = 'antenna', plotrange=[0,0,-180,180],<br />
showgui=False, subplot=421, figfile=asdm+'.scanphase.page1.png',<br />
antenna='0~7', fontsize=6.0)<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
plotcal(caltable = asdm+'.scanphase.gcal',<br />
xaxis = 'time', yaxis = 'phase',<br />
iteration = 'antenna', plotrange=[0,0,-180,180],<br />
showgui=False, subplot=421, figfile=asdm+'.scanphase.page2.png',<br />
antenna='8~15', fontsize=6.0)<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
plotcal(caltable = asdm+'.flux.cal', <br />
xaxis = 'time',yaxis = 'amp',<br />
plotrange = [0,0,0,0],<br />
antenna='0~7', iteration='antenna',<br />
showgui=False, subplot=421, figfile=asdm+'.flux.page1.png',<br />
fontsize=6.0)<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
plotcal(caltable = asdm+'.flux.cal', <br />
xaxis = 'time',yaxis = 'amp',<br />
plotrange = [0,0,0,0],<br />
antenna='8~15', iteration='antenna', fontsize=6.0,<br />
showgui=False, subplot=421, figfile=asdm+'.flux.page2.png')<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
</source><br />
<br />
==Apply the Calibrations and Inspect ==<br />
Now we will use {{applycal}} to apply the bandpass, phase, and amplitude calibration tables that we generated in the previous sections to the data. We apply the solutions separately to the bandpass and secondary ("phase") calibrator 3c279, the flux calibrator Titan, and the target source. In most data sets, the bandpass and secondary calibrator will not be the same and this step would include one additional {{applycal}}.<br />
<br />
<source lang="python"><br />
#In CASA<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
<br />
for asdm in basename_north: <br />
print "Applying calibrations for "+asdm<br />
applycal(vis=asdm+'.wvrtsys.ms',field='3c279',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='Titan',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','Titan','Titan'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='NGC*',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_south: <br />
print "Applying calibrations for "+asdm<br />
applycal(vis=asdm+'.wvrtsys.ms',field='3c279',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='Titan',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','Titan','Titan'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='Ant*',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
</source><br />
<br />
Here:<br />
* '''vis''' and '''field''' specify the measurement set and field to calibrate.<br />
* '''gaintable''' specifies the tables to apply to the data. There may be several tables applied all at once, here we apply the bandpass, phase, and flux calibrations.<br />
* '''interp''' specifies the type of interpolation used to match calibration tables to the data. If there are several gaintables then interp may be either a single value (e.g., "linear" or "nearest") or a list of values with size equal to the list of gaintables. In the case where interp is a list, applycal will match each element to the corresponding gaintable (e.g., first gaintable with first interp parameter).<br />
* '''gainfield''' specifies field from which to draw the calibration. As with interp, this can be a list of size matched to gaintable, so that the first element of gainfield will be the field used for the first table. For example, in the above commands the bandpass calibration (the first table) will always be applied from '3c279' (the first gainfield).<br />
* '''calwt''' indicates that the weights, which were derived from the Tsys measurements, should also be calibrated. Note that '''calwt''' is True by default.<br />
<br />
Once calibrations are applied, it is important to go back and inspect the calibrated data. New problematic antennas or baselines may be visible after calibration. Repeat the steps above, focusing on the CORRECTED data column. Bear in mind that for any point source calibrators we now expect to find phase scattering around zero and to find flat amplitudes as a function of u-v distance. Look for outliers and other signatures of problematic data. As a general rule, you will want to incorporate these data into your overall flagging script then rerun the whole calibration process, so that reduction is iterative. If the data only represent a minor problem, however, it may not be terribly harmful to flag them after the fact so that they do not interfere with imaging but trust that the calibrations are mostly unaffected.<br />
<br />
As an example of this inspection, we cycle through the corrected amplitudes and phases of 3c279 and Titan as a function u-v distance, to check that the phases are close to zero and the amplitudes are constant. <br />
<br />
<figure id="xb-checkcal-pha-cha.png"><br />
[[File:xb-checkcal-pha-cha.png|200px|thumb|right|<caption> Calibrated phase vs. channel plot for 3c279 (uid___A002_X1ff7b0_Xb dataset). </caption>]]<br />
</figure><br />
<figure id="xb-checkcal-amp-time.png"><br />
[[File:xb-checkcal-amp-time.png|200px|thumb|right|<caption> Calibrated amplitude vs. time plot for 3c279 (uid___A002_X1ff7b0_Xb dataset). </caption>]]<br />
</figure><br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='3c279',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='time', yaxis='amp',<br />
ydatacolumn='corrected', field='3c279',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='3c279',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='time', yaxis='phase',<br />
ydatacolumn='corrected', field='3c279',<br />
avgchannel='3840', avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
<br />
<br />
for asdm in basename_all:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='Titan',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='phase',<br />
ydatacolumn='corrected', field='Titan',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='Titan',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
In <xr id="xb-checkcal-pha-cha.png"/> and <xr id="xb-checkcal-amp-time.png"/> we plot phase vs. channel and amp vs. time for 3c279 for the uid___A002_X1ff7b0_Xb dataset. <br />
<br />
Finally we can use {{plotms}} to examine the corrected amplitude and phase of Antennae galaxies as a function of time and uv-distance (plots not shown):<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
for asdm in basename_north:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='NGC*',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='NGC*',<br />
avgtime='1e8', avgscan=True, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
for asdm in basename_south:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='Ant*',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='Ant*',<br />
avgtime='1e8', avgscan=True,avgbaseline=False, coloraxis='corr', showgui = True)<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
</source><br />
<br />
==Split and Concatenate Data for Northern and Southern Mosaics==<br />
The individual data sets are now calibrated. We can safely split out the calibrated data for our science target and drop the calibrators. As we do so, we will smooth the data in frequency, averaging together groups of 23 channels by setting '''width=23''' in {{split}}. The new data will have a channel width corresponding to about ~10 km/s, very similar to the SMA data being verified. The factor of >20 drop in data volume will also make the imaging steps ''much'' more tractable.<br />
<br />
<source lang="python"><br />
#In CASA<br />
<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_north:<br />
os.system('rm -rf '+asdm+'.cal.ms')<br />
split(vis = asdm+'.wvrtsys.ms',outputvis = asdm+'.cal.ms',<br />
field = 'NGC*',spw='0',width=23, keepflags=False)<br />
os.system('rm -rf '+asdm+'.cal.listobs.txt')<br />
listobs(asdm+'.cal.ms',listfile=asdm+'.cal.listobs.txt')<br />
<br />
for asdm in basename_south:<br />
os.system('rm -rf '+asdm+'.cal.ms')<br />
split(vis = asdm+'.wvrtsys.ms',outputvis = asdm+'.cal.ms',<br />
field = 'Ant*',spw='0',width=23, keepflags=False)<br />
os.system('rm -rf '+asdm+'.cal.listobs.txt')<br />
listobs(asdm+'.cal.ms',listfile=asdm+'.cal.listobs.txt')<br />
</source><br />
<br />
For convenience we concatenate all data for the Northern Mosaic into a single big MS and place all data for the Southern Mosaic into another file. To do this, we construct a list that holds the names of all the Southern Mosaic MS files and another that holds the name of all the Northern Mosaic MS files then feed these into the {{concat}} task. <br />
<br />
Before we do this, we'll take a brief aside to remove Pointing information from the calibrated data. Normally, the pointing information would apply important corrections to be used while imaging the data. However, some aspects of this are still under development and the pointing information in these data interacts poorly with CASA. We will remove the pointing information using the CASA toolkit Table tool (tb). ''This kind of operation is dangerous and should not be a regular feature of your CASA reduction.''<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Manually removing pointing table from "+asdm+".cal.ms ... Please be careful!"<br />
tb.open(asdm+'.cal.ms/POINTING',nomodify=False)<br />
a = tb.rownumbers()<br />
tb.removerows(a)<br />
tb.close()<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
cal_south_vis = [vis+'.cal.ms' for vis in basename_south]<br />
cal_north_vis = [vis+'.cal.ms' for vis in basename_north]<br />
<br />
os.system('rm -rf Antennae_South.cal.ms')<br />
concat(vis=cal_south_vis, concatvis='Antennae_South.cal.ms', timesort=True)<br />
<br />
os.system('rm -rf Antennae_North.cal.ms')<br />
concat(vis=cal_north_vis, concatvis='Antennae_North.cal.ms', timesort=True)<br />
</source><br />
<br />
The syntax used to construct the 'cal_south_vis' variable loops over basename_south and makes a list after adding '.cal.ms' to each member. To see the list 'print cal_south_vis'.<br />
<br />
==Continue on to Imaging of the Science Target==<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.5 imaging guide].<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Imaging_for_CASA_4.5&diff=21246NGC3256 Band3 Imaging for CASA 4.52017-04-04T14:50:37Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Spectral Line]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.5. If you are using an older version of CASA please see [[NGC3256 Band3 Calibration for CASA 4.3]].<br />
<br />
This portion of the '''[[NGC3256Band3]]''' CASA Guide for CASA 4.5 will cover the imaging of the continuum and spectral line data. It begins where the '''[[NGC3256 Band3 Calibration for CASA 4.5]]''' 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 ngc3256_line_target.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 />
[http://almascience.nrao.edu/almadata/sciver/NGC3256 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/NGC3256 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/NGC3256 East Asia]<br />
<br />
Once there, download the file 'NGC3256_Band3_CalibratedData4.1.tgz' to obtain the calibrated uvdata.<br />
The "4.1" in the file name means that the data were processed with the previous version of CASA but<br />
since that version is compatible with CASA 4.5, we have not regenerated the file.<br />
<br />
Once the download has finished, unpack the file:<br />
<source lang="bash"><br />
# In a terminal outside CASA<br />
tar -xvzf NGC3256_Band3_CalibratedData4.1.tgz<br />
<br />
cd NGC3256_Band3_CalibratedData<br />
<br />
# Start CASA<br />
casapy<br />
</source><br />
<br />
After that, you should have ngc3256_line_target.ms in your working directory.<br />
<br />
== Continuum image of the galaxy==<br />
<br />
We will start by making a continuum image of the galaxy using {{clean}}. Since this dataset contains spectral line emission from both CO and CN, we are careful to select only the channels that are free of line emission. These line-free channels are found by plotting the average amplitudes as a function of channel for each spectral window individually. You will find a strong CO(1-0) emission line in spw 0 in channels 55 to 69, and CN emission lines in spw 1 between channels 35~47 and channels 59~68. You will also find an increased noise level at the very lowest channels.<br />
<br />
[[File:amp_vs_chan_spw1.png|200px|thumb|right|Amplitude vs. channel for spw 1. The CN lines can be seen, as well as a slight upturn in noise for the lowest channels]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line_target.ms',spw='',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=True,iteraxis='spw', showgui = True)<br />
</source><br />
<br />
Before starting the cleaning, it makes sense to check if the continuum emission is resolved or not by plotting amplitude as a function of uv-distance. We just plot spw 2 here, because we know that this spectral window is free from line emission.<br />
<br />
[[File:amp_vs_uvdist_spw2.png|200px|thumb|right|Amplitude vs. uv-distance for spw 2. The continuum emission is clearly resolved]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line_target.ms',spw='2',xaxis='uvdist',yaxis='amp',<br />
avgtime='1e8',avgchannel='128',coloraxis='baseline', showgui = True)<br />
</source><br />
<br />
For the cleaning we select a spatial mask that just includes the extent of the continuum emission. Here, we use the default non-interactive mode, but if you want to define the clean boxes more carefully, specify interactive=True. In that case, the {{clean}} task will bring up a viewer where the clean region can be defined, either by selecting boxes or by selecting polygon regions.<br />
<br />
In the configuration that was used, the resolution in Band 3 is approximately 6 arcsec. We therefore choose a cell size of 1 arcsec, so as to oversample the beam sufficiently. The FWHM of the primary beam of ALMA in Band 3 is about 60 arcsec, and we want to image at least that extent. To be on the generous side, we choose to use 100 pixels.<br />
<br />
Finally, note that we delete any previous versions of the output images before proceeding with the clean command. This is an important step, because if images with the supplied root name already exist, CASA will clean those further instead of producing new output images.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_cont*')<br />
clean( vis='ngc3256_line_target.ms', imagename='result-ngc3256_cont',<br />
spw='0:20~53;71~120,1:70~120,2:20~120,3:20~120', psfmode='hogbom',<br />
mode='mfs', niter=500, threshold='0.3mJy', mask=[42,43,59,60],<br />
imsize=100, cell='1arcsec', weighting='briggs', robust=0.0, <br />
interactive=False, usescratch=False)<br />
</source><br />
The input parameters include:<br />
*vis='ngc3256_line_target.ms': The calibrated dataset on the science target<br />
*imagename='result-ngc3256_cont': The base name of the output images<br />
*spw='0:20~53;71~120,1:70~120,2:20~120,3:20~120': To specify only the channels in each spw free of line emission<br />
*psfmode='hogbom': The method used to calculated the PSF during minor clean cycles. Hogbom is a good choice for poorly-sampled uv-planes<br />
*mode='mfs': Multi-Frequency Synthesis: The default mode, which produces one image from all the specified data combined<br />
*niter=500: Maximum number of clean iterations<br />
*theshold='0.3mJy': Stop cleaning if the maximum residual is below this value. We choose the threshold to be ~1.5 times the rms noise in the image<br />
*mask=[42,43,59,60]: Limits the clean component placement to the region of the source<br />
*imsize=100, cell='1arcsec': Chosen to appropriately sample the resolution element and cover the primary beam<br />
*weighting='briggs', robust=0.0: a weighting scheme that offers a good compromise between sensitivity and resolution<br />
<br />
Note the parameter "usescratch" which was introduced in CASA 3.4. It determines whether the model information for later selfcal<br />
is explicitly stored in a MODEL_DATA column of the MS (usescratch=True) or if a rule for the creation of<br />
the model information on-demand in memory is stored in the MS header (usescratch=False, the default). The latter saves 30 % of disk space<br />
and much disk I/O.<br />
<br />
[[File:Ngc3256_cont.png|200px|thumb|right|Continuum image of NGC3256]]<br />
We will determine some statistics for the image using the task {{imstat}}:<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='result-ngc3256_cont.image', region='', box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='result-ngc3256_cont.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 peak flux density of the image is ~7 mJy and the dynamic range is approximately 22. For future reference, we create a png file of the continuum image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'result-ngc3256_cont.image', 'colorwedge':True,<br />
'range':[-0.001, 0.009], 'scaling':0, 'colormap':'Rainbow 2'},<br />
out='result-ngc3256_cont.png', zoom=2)<br />
</source><br />
<br />
==Self-Calibration==<br />
<br />
The continuum flux is fairly low in this galaxy, but given the large bandwidth of ALMA, we have sufficient signal-to-noise to attempt to self-calibrate the data. We will therefore do some phase-only self-calibration of the image using the task {{gaincal}}. This will compare the DATA column with the MODEL column, which has been filled with the clean components from the recent run of {{clean}}. We use a solution interval of 30 minutes, as we found that this gives just sufficient signal to noise per baseline. Using the ALMA sensitivity calculator, we estimate that the rms noise level per baseline for 30 min integration time and a total bandwidth of 5.1 GHz (excluding the emission lines) is 0.7 mJy. Compared to the peak flux of ~7 mJy, this should give us a sufficient SNR, taking into account that the emission is slightly resolved. <br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='ngc3256_line_target.ms', field='NGC*',<br />
caltable='cal-ngc3256_cont_30m.Gp',<br />
spw='0:20~53;71~120,1:70~120,2:20~120,3:20~120',<br />
solint='1800s', refant='DV07', calmode='p',<br />
minblperant=3)<br />
</source><br />
<br />
*caltable='cal-ngc3256_cont_900.Gp': The name of the output calibration table<br />
*spw='0:20~53;71~120,1:70~120,2:20~120,3:20~120': To select only the continuum channels<br />
*solint='1800s': To specify a 30-minute solution interval <br />
*refant='DV07': Our reference antenna<br />
*calmode='p': To select phase-only solutions<br />
*minblperant=3: To set the minimum number of baselines to other antennas that must be present for a given antenna to have a solution<br />
<br />
We then examine the derived phase solutions using {{plotcal}}:<br />
<br />
[[File:Ngc3256_selfcal_phase.png|200px|thumb|right|Phases of self-cal solutions for NGC3256 (only the first day is shown)]]<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256_cont_30m.Gp', xaxis = 'time', yaxis =<br />
'phase', poln='X', plotsymbol='o', plotrange = [0,0,-180,180],<br />
iteration = 'spw', figfile='cal-phase_vs_time_XX_30_Gp.png',<br />
subplot = 221, showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256_cont_30m.Gp', xaxis = 'time', yaxis =<br />
'phase', poln='Y', plotsymbol='o', plotrange = [0,0,-180,180],<br />
iteration = 'spw', figfile='cal-phase_vs_time_YY_30_Gp.png',<br />
subplot = 221, showgui = True)<br />
</source><br />
<br />
It is also possible to connect the points in a plot by using plotsymbol=":". The phase-only self-cal solutions look good, so we will apply them to the data with {{applycal}}. This will overwrite the data in the CORRECTED data column.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='ngc3256_line_target.ms', interp='linear',<br />
gaintable='cal-ngc3256_cont_30m.Gp')<br />
</source><br />
<br />
We then make another continuum map from the newly-corrected data, using the same clean parameters as before. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_cont_sc1*')<br />
clean( vis='ngc3256_line_target.ms', imagename='result-ngc3256_cont_sc1',<br />
spw='0:20~53;71~120,1:70~120,2:20~120,3:20~120', psfmode='hogbom', <br />
mode='mfs', niter=500, threshold='0.13mJy', mask=[42,43,59,60], <br />
imsize=100, cell='1arcsec', weighting='briggs', robust=0.0,<br />
interactive=False, usescratch=False)<br />
</source><br />
<br />
[[File:Ngc3256_cont_sc1.png|200px|thumb|right|Continuum image of NGC 3256 after self-calibration]]<br />
and again generate some statistics:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='result-ngc3256_cont_sc1.image', region='', <br />
box='10,10,90,35')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in continuum image: '+str(rms)<br />
calstat=imstat(imagename='result-ngc3256_cont_sc1.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 continuum image has improved a lot. The dynamic range is now ~126, whereas before it was only ~22. The image peak flux density is ~10 mJy. We will write this new image to the file 'result-ngc3256_cont_sc1.image' to indicate that an iteration of self-calibration was performed. We also create a new png file of the self-calibrated continuum image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'result-ngc3256_cont_sc1.image', 'colorwedge':True,<br />
'range':[-0.001, 0.010], 'scaling':0, 'colormap':'Rainbow 2'},<br />
out='result-ngc3256_cont_sc1.png', zoom=2)<br />
</source><br />
<br />
In principle, one could experiment further with self-calibration, changing the solution interval, or even adding amplitude self-calibration. To do this, just repeat the steps 1) gaincal, 2) applycal, and 3) clean until you are happy with the result. For the moment, we are happy with just one round of phase-only self-cal.<br />
<br />
== Line cubes of the galaxy==<br />
<br />
Before making cubes of the line emission of NGC 3256, we want to subtract the continuum emission from the spectral line data using the task {{uvcontsub}}. This task makes fits to the line free channels and subtracts the emission in the uv-domain. It will operate on the CORRECTED_DATA column and will write the continuum subtracted data to a new measurement set with the extension ".contsub". Remember that in the previous section we applied the self-calibration tables to the DATA column to generate this CORRECTED_DATA column. <br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis = 'ngc3256_line_target.ms',<br />
fitspw='0:20~53;71~120,1:70~120,2:20~120,3:20~120', solint ='int', <br />
fitorder = 1,<br />
combine='spw')<br />
</source><br />
<br />
*fitspw='0:20~53;71~120,1:70~120,2:20~120,3:20~120': To specify the spectral windows and channels to be used in the fit for the continuum. We avoid the spectral regions that include the CO and CN emission lines.<br />
*solint ='int': Timescale for the per-baseline fit. Here we are electing to have one fit per integration <br />
*fitorder = 1: We will fit a first-order polynomial to the continuum<br />
*combine='spw': Combine spws to form a spw-merged continuum estimate<br />
<br />
Next, we will {{clean}} the CO (1-0) line emission:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_line_CO.*')<br />
clean(vis='ngc3256_line_target.ms.contsub', imagename='result-ngc3256_line_CO',<br />
spw='0:38~87', mode='channel', start='', nchan=-1, width='', <br />
psfmode='hogbom', outframe='LSRK', restfreq='115.271201800GHz', <br />
mask=[53,50,87,83], niter=500, interactive=True, imsize=128, cell='1arcsec', <br />
weighting='briggs', robust=0.0, threshold='5mJy',<br />
usescratch=False)<br />
</source><br />
<br />
[[File:interactive_clean_channel.jpg|200px|thumb|right|One of the channels in the interactive clean, showing CO emission. The white region indicates the clean mask]]<br />
Notable parameters include:<br />
*spw='0:38~87': To specify the CO (1-0) line emission alone<br />
*mode='channel': To produce an image with different planes specified by the "start", "nchan", and "width" parameters<br />
*start=<nowiki>'',</nowiki> nchan=-1, width=<nowiki>''</nowiki>: To include all 50 channels specified by spw, with no channel averaging<br />
*threshold='5 mJy': Stop cleaning if the maximum residual is below this value. <br />
*outframe='LSRK': Shift the output reference frame to the local standard of rest<br />
*restfreq='115.271201800GHz': The rest frequency of the CO line<br />
*mask=[53,50,87,83]: The region in which to fit clean components (i.e., the source)<br />
*niter=500: Maximum number of clean iterations<br />
*interactive=T: To do interactive cleaning with the viewer GUI <br />
*psfmode='hogbom': The method used to calculated the PSF during minor clean cycles. Hogbom is a good choice for poorly-sample uv-planes<br />
<br />
Note that you can also find the frequencies of many spectral lines inside CASA. For example, the following commands will search for CO emission lines in ALMA band 3, and output the results to the logger:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf myresults.tbl')<br />
slsearch(outfile='myresults.tbl', freqrange = [84,116], species=['COv=0'])<br />
sl.open('myresults.tbl')<br />
sl.list()<br />
</source><br />
<br />
Or define the parameter restfreq directly using:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tb.open('myresults.tbl') <br />
restfreq=tb.getcol('FREQUENCY')[0]<br />
tb.close()<br />
</source><br />
<br />
Using interactive=T the viewer will open when it is ready to start an interactive clean. Step through to the channels to see how extended the emission is. Then either use "All Channels" to define the same clean mask for all channels, or select "This Channel" to select different masks for each channel. Once you have defined a polygon region, you need to double click inside it to save the mask region. You can use the "tape deck" to step through the channels again and check that the emission in all channels fits within the mask(s) you have created. Note that the mask we defined above does not include all emission -- you will have to change the mask interactively!<br />
To continue with clean use the "Next action" buttons in the green area on the Viewer Display GUI: The red X will stop clean where you are; the blue arrow will stop the interactive part of clean, but continue to clean non-interactively until reaching the stopping niter or threshold (whichever comes first); and the green arrow will clean until it reaches the "iterations" parameter on the left side of the green area.<br />
<br />
When the cleaning has finished, you may want to inspect the resulting cube and and use the tape deck to play the cube as a movie. Use Spectral Profile in the Tools tab to make an integrated spectrum of the CO(1-0) emission.<br />
<source lang="python"><br />
# In CASA<br />
imview('result-ngc3256_line_CO.image')<br />
</source><br />
<br />
The rms noise level in the cube is ~1 mJy per channel in the line-free channels. The ALMA sensitivity calculator gives a noise level of 0.80 mJy using 7 antennas, an integration time of 3.5 hours, and a bandwidth of 32.25 MHz (this is twice the channel separation because on-line Hanning smoothing was applied.)<br />
<br />
Next, we make the moment maps of the CO (1-0) emission using the task {{immoments}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_CO1-0.mom0*')<br />
immoments(imagename='result-ngc3256_line_CO.image', moments=[0],<br />
chans='15~34', box='38,38,90,90', axis='spectral',<br />
includepix=[0.02, 10000], outfile='result-ngc3256_CO1-0.mom0')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_CO1-0.mom1*')<br />
immoments(imagename='result-ngc3256_line_CO.image', moments=[1],<br />
chans='15~34', box='38,38,90,90', axis='spectral',<br />
includepix=[0.045, 10000], outfile='result-ngc3256_CO1-0.mom1')<br />
</source><br />
<br />
[[File:CO_velfield.png|200px|thumb|right|The CO(1-0) velocity field of NGC3256, with contours of the total line emission map overlaid]]<br />
[[File:CO_map.png|200px|thumb|right|The CO(1-0) "moment 0" total intensity maps of NGC3256, with contours of the velocity field overlaid]]<br />
[[File:result-CO_dispersion.png|200px|thumb|right|The CO(1-0) "moment 2" dispersion map of NGC3256]]<br />
*moments=[x]: To specify that we wish to make the xth moment map. The 0th moment map gives integrated emission and the 1st gives the intensity-weighted velocity field<br />
*chans='15~34': These are the channels that show line emission and therefore the ones we want to use for the moment map<br />
*box='38,38,90,90': To select a box region around the emission so as to not include any regions away from the galaxy<br />
*axis='spectral': Indicates the moment axis; in this case, 'spectral' <br />
*includepix=[0.045, 10000]: To select which pixel values in the cube to include in the moments. We find these values by looking for the faintest believable emission in the cube<br />
*outfile='result-ngc3256_CO1-0.mom0': The output image name<br />
<br />
Here, we have chosen to run the {{immoments}} separately for the total intensity map and the velocity field because we want to use different thresholds for flux inclusion. To find the lower limit in includepix, open the cube in the viewer, and identify the lowest believable flux levels in the cube.<br />
<br />
We also make a velocity dispersion map of the CO(1-0) gas, using moments=[2]<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_CO1-0.mom2*')<br />
immoments(imagename='result-ngc3256_line_CO.image', moments=[2],<br />
chans='5~44', box='38,38,90,90', axis='spectral',<br />
includepix=[0.035, 10000], outfile='result-ngc3256_CO1-0.mom2')<br />
</source><br />
<br />
Now we can make images of the CO(1-0) emission. First create a colour image of the velocity field, with contours of the total line emission overlaid:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CO1-0.mom0','levels': <br />
[5,10,20,40,80,160],'base':0,'unit':1}, <br />
raster={'file': 'result-ngc3256_CO1-0.mom1','range': [2630,2920],<br />
'colorwedge':True, 'colormap': 'Rainbow 2'}, out='result-CO_velfield.png')<br />
</source><br />
<br />
Or, make a colour image of the integrated CO(1-0) line emission, with contours of the velocity field overlaid:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CO1-0.mom1','levels': <br />
[2650,2700,2750,2800,2850,2900],'base':0,'unit':1}, <br />
raster={'file': 'result-ngc3256_CO1-0.mom0', 'colorwedge':True,<br />
'colormap': 'Rainbow 2','scaling':-1.0,'range': [0.8,250]}, <br />
out='result-CO_map.png')<br />
</source><br />
<br />
And make a greyscale image of the CO(1-0) gas velocity dispersion<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CO1-0.mom2','levels': <br />
[20,30,40,50,60],'base':0,'unit':1}, <br />
raster={'file': 'result-ngc3256_CO1-0.mom2', 'colorwedge':True,<br />
'colormap': 'Greyscale 1','scaling':-1.0,'range': [0,74]}, <br />
out='result-CO_dispersion.png')<br />
</source><br />
<br />
[[File:ngc3256_channels.png|200px|thumb|right|Channel maps of six central channels, with contours of the total continuum map overlaid]]<br />
Also, using the viewer, it is possible to make channel maps. The following image shows six velocity channels, with contours indicating the 3mm continuum emission.<br />
<br />
Next, we clean the CN line emission. There are two CN lines, the N=1-0, J=3/2-1/2 line at higher frequency and the N=1-0, J=1/2-1/2 line at lower frequency. We start with the higher frequency line emission. Again, we have set a mask here, but the best results are obtained if an interactive clean mask is defined.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_line_CNhi.*')<br />
clean(vis='ngc3256_line_target.ms', imagename='result-ngc3256_line_CNhi',<br />
outframe='LSRK', spw='1:50~76', start='', nchan=27, width='',<br />
restfreq='113.48812GHz', selectdata=T, mode='channel',<br />
niter=500, gain=0.1, psfmode='hogbom', mask=[53,50,87,83],<br />
interactive=True, imsize=128, cell='1arcsec',<br />
weighting='briggs', robust=0.0, threshold='2mJy',<br />
usescratch=False)<br />
</source><br />
<br />
Make the moment maps of the higher frequency CN line emission:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_CNhi.mom.*')<br />
immoments( imagename='result-ngc3256_line_CNhi.image', moments=[0,1],<br />
chans='5~18', axis='spectral', box='38,38,90,90',<br />
includepix=[0.005, 10000], outfile='result-ngc3256_CNhi.mom')<br />
</source><br />
<br />
Make images of the higher frequency CN line emission:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CNhi.mom.integrated','range': []}, <br />
raster={'file': 'result-ngc3256_CNhi.mom.weighted_coord',<br />
'range': [2630,2920],'colorwedge':True,<br />
'colormap': 'Rainbow 2'}, out='result-CNhi_velfield.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CNhi.mom.weighted_coord','levels': <br />
[2650,2700,2750,2800,2850,2900],'base':0,'unit':1}, <br />
raster={'file': 'result-ngc3256_CNhi.mom.integrated','colorwedge':True,<br />
'colormap': 'Rainbow 2'}, out='result-CNhi_map.png')<br />
</source><br />
<br />
And finally, clean the CN (N=1-0, J=1/2-1/2) emission:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_line_CNlo.*')<br />
clean( vis='ngc3256_line_target.ms', imagename='result-ngc3256_line_CNlo',<br />
outframe='LSRK', spw='1:29~54', start='', nchan=26, width='',<br />
restfreq='113.17049GHz', selectdata=True, mode='channel',<br />
niter=300, gain=0.1, psfmode='hogbom', mask=[53,50,87,83],<br />
interactive=True, imsize=128, cell='1arcsec',<br />
weighting='briggs', robust=0.0, threshold='2mJy',<br />
usescratch=False)<br />
</source><br />
<br />
Make the moment maps of the lower frequency CN emission<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ngc3256_CNlo.mom.*')<br />
immoments( imagename='result-ngc3256_line_CNlo.image', moments=[0,1],<br />
chans='8~18', axis='spectral', box='38,38,90,90',<br />
includepix=[0.003, 10000], outfile='result-ngc3256_CNlo.mom')<br />
</source><br />
<br />
Make images of the low frequency CN emission<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CNlo.mom.integrated','range': []}, <br />
raster={'file': 'result-ngc3256_CNlo.mom.weighted_coord',<br />
'range': [2630,2920],'colorwedge':True,<br />
'colormap': 'Rainbow 2'}, out='result-CNlo_velfield.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(contour={'file': 'result-ngc3256_CNlo.mom.weighted_coord','levels': <br />
[2650,2700,2750,2800,2850,2900],'base':0,'unit':1}, <br />
raster={'file': 'result-ngc3256_CNlo.mom.integrated','colorwedge':True,<br />
'colormap': 'Rainbow 2'}, out='result-CNlo_map.png')<br />
</source><br />
<br />
Note that with 'out' set, imview will just create the image file. It will not open an interactive viewer.<br />
<br />
This composite shows the CN maps and velocity fields.<br />
<br />
<gallery widths="280px" heights="200px" perrow="2"><br />
File:result-CNhi_map.png|The higher frequency CN(1-0) "moment 0" total intensity maps of NGC3256, with contours of the velocity field overlaid<br />
File:result-CNhi_velfield.png|The higher frequency CN(1-0) velocity field of NGC3256, with contours of the total line emission map overlaid<br />
File:result-CNlo_map.png|The lower frequency CN(1-0) "moment 0" total intensity maps of NGC3256, with contours of the velocity field overlaid<br />
File:result-CNlo_velfield.png|The lower frequency CN(1-0) velocity field of NGC3256, with contours of the total line emission map overlaid<br />
</gallery><br />
<br />
<br />
And finally we show the channel maps of all three emission lines overlaid. The 'hot metal' colours represent the higher frequency CN line, the green contours are the CO line, and the cyan contours are the lower frequency CN line.<br />
<br />
[[File:composite_channels.png|600px|thumb|left|Channel maps of all three lines]]<br />
<br />
<br />
<br />
<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=NGC3256_Band3_Calibration_for_CASA_4.5&diff=21245NGC3256 Band3 Calibration for CASA 4.52017-04-04T14:18:18Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
<br />
==Overview==<br />
<br />
This portion of the '''[[NGC3256Band3]]''' CASA Guide will cover the calibration of the raw visibility data. To skip to the imaging portion of the guide, see: '''[[NGC3256_Band3_Imaging_for_CASA_4.5]]'''.<br />
<br />
'''This guide is designed for CASA 4.5. If you are using an older version of CASA please see [[NGC3256_Band3_Calibration_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 'NGC3256_Band3_UnCalibratedMSandTablesForReduction.tgz':<br />
<br />
[http://almascience.nrao.edu/almadata/sciver/NGC3256 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/NGC3256 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/NGC3256 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 NGC3256_Band3_UnCalibratedMSandTablesForReduction.tgz<br />
<br />
cd NGC3256_Band3_UnCalibratedMSandTablesForReduction<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.5.0. 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.5.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 />
<br />
The data have already been converted to CASA Measurement Set (MS) format using the CASA task {{importasdm}}. Accompanying the data are some basic calibration tables you would need for the following reduction if you were working with CASA 3.3 as well as the *.ms.flagversions files that are automatically generated by importasdm. With CASA 3.4 or later you will only need the MS files.<br />
<br />
==Initial Inspection, Tsys and WVR caltable generation, and ''A priori '' Flagging==<br />
We will eventually concatenate the six datasets used here into one large 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 six 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. We will remind you of this in the relevant sections by repeating the command at the start.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=['uid___A002_X1d54a1_X5','uid___A002_X1d54a1_X174','uid___A002_X1d54a1_X2e3',<br />
'uid___A002_X1d5a20_X5','uid___A002_X1d5a20_X174','uid___A002_X1d5a20_X330']<br />
</source><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 />
for name in basename:<br />
listobs(vis=name+'.ms')<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]. You will have to scroll up to see the individual output for each of the six datasets. Here is an example of the most relevant output for the first file in the list.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Observation: ALMA<br />
Data records: 206024 Total integration time = 3801.6 seconds<br />
Observed from 16-Apr-2011/02:59:18.5 to 16-Apr-2011/04:02:40.1 (UTC)<br />
...<br />
Fields: 3<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none 1037-295 10:37:16.079000 -29.34.02.81300 J2000 0 38759<br />
1 none Titan 00:00:00.000000 +00.00.00.00000 J2000 1 16016<br />
2 none NGC3256 10:27:51.600000 -43.54.18.00000 J2000 2 151249<br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID Name #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) BBC Num Corrs <br />
0 4 TOPO 184550.000 1500000.000 7500000.0 0 I<br />
1 128 TOPO 113211.988 15625.000 2000000.0 1 XX YY<br />
2 1 TOPO 114188.550 1796875.000 1796875.0 1 XX YY<br />
3 128 TOPO 111450.813 15625.000 2000000.0 2 XX YY<br />
4 1 TOPO 112427.375 1796875.000 1796875.0 2 XX YY<br />
5 128 TOPO 101506.187 15625.000 2000000.0 3 XX YY<br />
6 1 TOPO 100498.375 1796875.000 1796875.0 3 XX YY<br />
7 128 TOPO 103050.863 15625.000 2000000.0 4 XX YY<br />
8 1 TOPO 102043.050 1796875.000 1796875.0 4 XX YY<br />
Sources: 48<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 1037-295 0 - - <br />
0 1037-295 9 - - <br />
0 1037-295 10 - - <br />
0 1037-295 11 - - <br />
0 1037-295 12 - - <br />
0 1037-295 13 - - <br />
0 1037-295 14 - - <br />
0 1037-295 15 - - <br />
0 1037-295 1 - - <br />
0 1037-295 2 - - <br />
0 1037-295 3 - - <br />
0 1037-295 4 - - <br />
0 1037-295 5 - - <br />
0 1037-295 6 - - <br />
0 1037-295 7 - - <br />
0 1037-295 8 - - <br />
1 Titan 0 - - <br />
1 Titan 9 - - <br />
1 Titan 10 - - <br />
1 Titan 11 - - <br />
1 Titan 12 - - <br />
1 Titan 13 - - <br />
1 Titan 14 - - <br />
1 Titan 15 - - <br />
1 Titan 1 - - <br />
1 Titan 2 - - <br />
1 Titan 3 - - <br />
1 Titan 4 - - <br />
1 Titan 5 - - <br />
1 Titan 6 - - <br />
1 Titan 7 - - <br />
1 Titan 8 - - <br />
2 NGC3256 0 - - <br />
2 NGC3256 9 - - <br />
2 NGC3256 10 - - <br />
2 NGC3256 11 - - <br />
2 NGC3256 12 - - <br />
2 NGC3256 13 - - <br />
2 NGC3256 14 - - <br />
2 NGC3256 15 - - <br />
2 NGC3256 1 - - <br />
2 NGC3256 2 - - <br />
2 NGC3256 3 - - <br />
2 NGC3256 4 - - <br />
2 NGC3256 5 - - <br />
2 NGC3256 6 - - <br />
2 NGC3256 7 - - <br />
2 NGC3256 8 - - <br />
Antennas: 7:<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 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8 -7.2138 -541.3512 15.0201 2225061.037523 -5440128.037088 -2481534.425893<br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1 42.8987 -520.1911 15.0694 2225110.551677 -5440116.726350 -2481514.951072<br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5 -0.3652 -563.8032 14.9605 2225064.049398 -5440117.310745 -2481555.086720<br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9 42.8799 -575.6930 14.6279 2225102.207607 -5440096.375770 -2481565.910931<br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3 8.8013 -527.8599 15.0524 2225077.857924 -5440126.859008 -2481522.009477<br />
5 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2 -29.1267 -522.7927 15.0566 2225043.501530 -5440143.044690 -2481517.342890<br />
6 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0 22.2012 -550.2540 14.9957 2225086.942900 -5440113.675900 -2481542.618100<br />
</pre><br />
<br />
This output shows that three fields were observed: 1037-295, Titan, and NGC3256. Field 0 (1037-295) will serve as the gain calibrator and bandpass calibrator; field 1 (Titan) will serve as the flux calibrator; and field 2 (NGC3256) is, of course, the science target. <br />
<br />
Note that there are more than four SpwIDs even though the observations were set up to have four spectral windows. The spectral line data themselves are found in spectral windows 1,3,5,7, which have 128 channels each. The first one (spw 1) is centered on the CO(1-0) emission line in the galaxy NGC 3256 and is our highest frequency spectral window. There is one additional spectral window (spw 3) in the Upper Side Band (USB), and there are two spectral windows (spw 5 and 7) in the Lower Side Band (LSB). These additional spectral windows are used to measure the continuum emission in the galaxy, and may contain other emission lines as well.<br />
<br />
Spectral windows 2,4,6,8 contain channel averages of the data in spectral windows 1,3,5,7, respectively. These are not useful for the offline data reduction. Spectral window 0 contains the WVR data. You may notice that there are additional SpwIDs listed in the "Sources" section which are not listed in the "Spectral Windows" section. These spectral windows are reserved for the WVRs of each antenna (seven in our case). At the moment, all WVRs point to spw 0, which contains nominal frequencies. The additional spectral windows (spw 9-15) are therefore not used and can be ignored.<br />
<br />
Another important thing to note is that the position of Titan is listed as 00:00:00.0000 +00.00.00.0000. This is due to the fact that for ephemeris objects, the positions were not stored in the ASDM by the version of the ALMA online system in use in April 2011. This is now fixed but with this historical data set, we have to fix this offline. We will correct the coordinates below by running the task fixplanets which takes the position from the pointing table at a representative time. <br />
<br />
The final column of the listobs output in the logger (not shown above) 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. Also these intents are being used for pipeline processing. <br />
<br />
Seven antennas were used for the dataset listed above. Note that numbering in python always begins with "0", so the antennas have IDs 0-6. To see what the antenna configuration looked like at the time of the this observation, we will use the task {{plotants}}. <br />
<br />
[[File:Uid___A002_X1d54a1_X5_plotants.png|200px|thumb|right|plotants output]]<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 as well as save it under the specified filename for future reference. This will be important later on when we need to choose a reference antenna, since the reference antenna should be close to the center of the array (as well as stable and present for the entire observation). <br />
<br />
If you repeat the plotants command for the other five datasets, you will see that there is an additional antenna (DV10) present on the second day of observations. Other than that, the configuration stays constant during the course of the observations.<br />
<br />
==== Tsys and WVR calibration table generation ====<br />
The System Temperature (Tsys) and Water Vapour Radiometer (WVR) calibration tables included in the data are in the old CASA 3.3 format and can not be used with CASA 4.5. We create them directly in the new format from the calibration data contained in the MSs and demonstrate the calibration table generation from scratch. The process is quite fast.<br />
Remember that you first need to redefine the "basename" array if you logged out of CASA prior to starting this section.<br />
<source lang="python"><br />
# In CASA<br />
basename=['uid___A002_X1d54a1_X5','uid___A002_X1d54a1_X174','uid___A002_X1d54a1_X2e3',<br />
'uid___A002_X1d5a20_X5','uid___A002_X1d5a20_X174','uid___A002_X1d5a20_X330']<br />
</source><br />
<br />
Now we will loop over the datasets, generating the Tsys and the WVR calibration tables for each of them.<br />
I the WVR calibration we use the "smooth" parameter to smooth the calibration table over a timescale of the integration time of the visibiltity data which is 2.88 seconds.<br />
The WVR calibration data is intrinsically taken with an integration time of about 1.15 s. So we smooth roughly over 3 samples. <br />
The smoothing avoids the introduction of additional phase noise. <br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
os.system('rm -rf cal-tsys_'+name+'.calnew cal-*'+name+'.Wnew')<br />
gencal(vis=name+'.ms',<br />
caltype='tsys',<br />
caltable='cal-tsys_'+name+'.calnew')<br />
wvrgcal(vis=name+'.ms', caltable='cal-'+name+'.Wnew', <br />
toffset=-1, segsource=True,<br />
tie=["Titan,1037-295,NGC3256"], statsource="1037-295",<br />
smooth='2.88s')<br />
</source><br />
<br />
==== Flagging ====<br />
The first editing we will do is some ''a priori'' flagging with {{flagdata}}. We will start by flagging the shadowed data and the autocorrelation data. ALMA data contains both the cross correlation and autocorrelation data, but here we are only interested in the cross-correlation data. Additionally, for compact configurations of the array, one antenna can shadow another, blocking its view. These data also need to be flagged.<br />
Remember again that you first need to redefine the "basename" array if you logged out of CASA prior to starting this section.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=['uid___A002_X1d54a1_X5','uid___A002_X1d54a1_X174','uid___A002_X1d54a1_X2e3',<br />
'uid___A002_X1d5a20_X5','uid___A002_X1d5a20_X174','uid___A002_X1d5a20_X330']<br />
</source><br />
<br />
Now we will loop over the datasets, running the two flagging commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms', flagbackup = False, mode = 'shadow')<br />
flagdata(vis=name+'.ms',mode='manual', autocorr=True)<br />
</source><br />
<br />
There are a number of scans in the data that were used by the online system for pointing calibration. These scans are no longer needed, and we can flag them easily with {{flagdata}} by selecting on 'intent':<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms', mode='manual', flagbackup = False, intent='*POINTING*')<br />
</source><br />
<br />
Similarly, we can flag the scans corresponding to atmospheric calibration since we no longer need them:<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
flagdata(vis=name+'.ms', mode='manual', flagbackup = False, intent='*ATMOSPHERE*')<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 />
==Delay Correction for Antenna DV07==<br />
<br />
Due to an issue with antenna DV07 during the commissioning period when these data were taken, it shows large delays in phase for the first three datasets. While the bandpass calibration will attempt to fit and remove small phase delays (i.e., less than one wrap over the bandpass), large delays like those seen here will result in failed solutions. If we want to salvage the data for this antenna, we therefore need to correct the delays by calculating a K-type delay calibration table with {{gencal}}. We emphasize that this is ''not'' usually a part of the typical calibration procedure, but it may be useful to the reader to see how such a correction is made. <br />
<br />
Remember that you first need to redefine the "basename" array if you logged out of CASA prior to starting this section.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=['uid___A002_X1d54a1_X5','uid___A002_X1d54a1_X174','uid___A002_X1d54a1_X2e3',<br />
'uid___A002_X1d5a20_X5','uid___A002_X1d5a20_X174','uid___A002_X1d5a20_X330']<br />
</source><br />
<br />
You can see the phase delays by plotting phase versus channel in {{plotms}}, as we do here for a single spw, correlation, and baseline with DV07:<br />
<br />
[[File:Cal-DV07delay.png|200px|thumb|right|DV07: Phase vs Channel]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=basename[0]+'.ms', xaxis='channel', yaxis='phase',<br />
spw='3', antenna='PM03&DV07', correlation='XX', avgtime='1e8',showgui = True)<br />
</source><br />
<br />
The parameters required by gencal are the delays measured in nanoseconds, first cycling over polarization product, and then over spectral window (thus giving eight numbers in total). We simply estimate these values by eye using the above plot and the corresponding plots for the other spectral windows and polarization products. The purpose here is to get the phases approximately flat as a function of frequency. Any additional phase variations will be corrected for later when we do the bandpass calibration. <br />
<br />
Based on the above plot, we estimate that the delay for this spw and correlation is approximately -3ns. One full phase wrap over 2GHz corresponds to a delay of 1/(2GHz)=0.5ns. Here we see six wraps and therefore estimate a 3ns delay. The sign convention is such that the delay is positive if the phase is increasing with respect to frequency and negative if it is decreasing, as it is here. Note that the sign convention is reversed between the two basebands, since the channels in the USB run in the ''opposite'' direction to those in the LSB. The wrapping in spectral windows 3,5,7 is therefore all in the same direction with respect to ''frequency''. The value of -3ns that we estimate is for spw 3, correlation XX, and will therefore be the third element in the parameter array.<br />
<br />
We then run {{gencal}} for the three datasets in question, supplying the estimated values in the "parameter" array. As the {{gencal}} task will not overwrite existing tables, the script starts by deleting any existing versions of the calibration tables with the same name.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for i in range(3): # loop over the first three ms's<br />
name=basename[i]<br />
os.system('rm -rf cal-'+name+'_del.K')<br />
gencal(vis=name+'.ms', caltable='cal-'+name+'_del.Knew',<br />
caltype='sbd', antenna='DV07', pol='X,Y', spw='1,3,5,7',<br />
parameter=[1.00, 1.10, -3.0, -3.0, -3.05, -3.05, -3.05, -3.05])<br />
</source><br />
<br />
We will apply these K tables to the data in the next section.<br />
<br />
==WVR Correction and Tsys Calibration==<br />
<br />
We will now apply the delay correction table and the WVR calibration tables to the data with the task {{applycal}}. We do this in two steps. First we will cycle over the three datasets from the first day of observations, because we have to correct the delay error for DV07 for those data. For the last three datasets (i.e. those taken during the second day), we do not need to correct the delays, so we just apply the WVR tables. In the call to applycal, we will specify interpolation="nearest". This is important for the WVR corrections, and it doesn't make a difference for the delay corrections because they have no time dependence.<br />
<br />
First, remember to redefine the "basename" array if you've logged out of CASA at any point up until now.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename=['uid___A002_X1d54a1_X5','uid___A002_X1d54a1_X174','uid___A002_X1d54a1_X2e3',<br />
'uid___A002_X1d5a20_X5','uid___A002_X1d5a20_X174','uid___A002_X1d5a20_X330']<br />
</source><br />
<br />
Now loop through the datasets as described above, applying the calibration tables:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for i in range(3): # loop over the first three data sets<br />
name=basename[i]<br />
applycal(vis=name+'.ms', flagbackup=False, spw='1,3,5,7',<br />
interp=['nearest','nearest'], gaintable=['cal-'+name+'_del.Knew', 'cal-'+name+'.Wnew'])<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
for i in range(3,6): # loop over the last three data sets<br />
name=basename[i]<br />
applycal(vis=name+'.ms', flagbackup=False, spw='1,3,5,7',<br />
interp='nearest', gaintable='cal-'+name+'.Wnew')<br />
</source><br />
<br />
Now you can use plotms to show some of the before-and-after effects of calibration. Just re-run the previous plotms command, repeated below, or if the window is still open, check 'force reload'. This will display the uncorrected phases across the band. To display the corrected phases, you will need to select the CORRECTED data column in the axes tab and replot.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=basename[0]+'.ms', xaxis='channel', yaxis='phase',<br />
spw='1', antenna='', correlation='XX', avgtime='1e8',<br />
coloraxis='baseline', avgscan=True, selectdata=True, field='1037*',showgui = True)<br />
</source><br />
<br />
Now we split out the CORRECTED data column of the datasets with the task {{split}}. We give the resulting datasets the extension "_K_WVR" to indicate that the delay tables and WVR tables have been applied in the DATA column, and we specify spectral windows 0-8 to get rid of the "WVR placeholder" spectral windows. Since split will not overwrite existing files, we start by removing any previous versions of the split ms's before running the split command.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
os.system('rm -rf '+name+'_K_WVR.ms*')<br />
split(vis=name+'.ms', outputvis=name+'_K_WVR.ms',<br />
datacolumn='corrected', spw='0~7') <br />
</source><br />
<br />
Next we do the Tsys calibration. Tsys measurements correct for the atmospheric opacity (to first-order) and allow the calibration sources to be measured at elevations that differ from the science target. We generated the Tsys tables above. We will start by inspecting them with the task {{plotbandpass}}:<br />
<br />
[[File:cal-tsys_per_spw_7_uid___A002_X1d54a1_X174.DV04.spw07.png|200px|thumb|right|Example Tsys plot with overlay='time']]<br />
[[File:cal-tsys_per_spw_7_uid___A002_X1d54a1_X174.spw07.t00.png|200px|thumb|right|Example Tsys plot with overlay='antenna']]<br />
<source lang="python"><br />
# In CASA<br />
for spw in ['1','3','5','7']:<br />
for name in basename:<br />
plotbandpass(caltable='cal-tsys_'+name+'.calnew', xaxis='freq', yaxis='amp',<br />
spw=spw, overlay='time', # also try overlay='antenna'<br />
plotrange=[0, 0, 40, 180],<br />
figfile='cal-tsys_per_spw_'+spw+'_'+name+'.png', interactive=False)<br />
</source><br />
<br />
Note that we only plot the spectral windows that contain the spectral line data. In addition to plotting on your screen, the above command will also produce a plot file (png) for each of the datasets and spectral windows. Example plots are shown to the right for uid___A002_X1d54a1_X174.ms one with parameter setting overlay='time' and one using overlay='antenna'. <br />
<br />
Upon examination of these plots, we see that for uid___A002_X1d54a1_X174.ms, there is a outlying feature in spw=7, antenna DV04. This feature influences scans 4 and 9. So we flag those data with the following command:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='uid___A002_X1d54a1_X174_K_WVR.ms', mode='manual',<br />
antenna='DV04', flagbackup = True, scan='4,5,9', spw='7')<br />
<br />
</source><br />
<br />
Aside from the large amplitudes in the edge channels (which we will handle below), the plots look acceptable. Note that in the lowest spectral window ID (spw 1), Tsys rises toward higher frequencies. This is due to a spectral line from O2 at 117 GHz.<br />
<br />
We will apply the Tsys tables with {{applycal}}. We do this for each field separately so that the appropriate calibration data are applied to the right fields. The "field" parameter specifies the field to which we will apply the calibration, and the "gainfield" parameter specifies the field from which we wish to take the calibration solutions from the gaintable. The interpolation option should be set to "linear" as the Tsys measurements are more sparse than the integrations and Tsys changes smoothly with time. In frequency, the recommended interpolation method is "spline".<br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
for field in ['Titan','1037*','NGC*']:<br />
applycal(vis=name+'_K_WVR.ms', spw='1,3,5,7', flagbackup=False, field=field, gainfield=field,<br />
interp='linear,spline', gaintable=['cal-tsys_'+name+'.calnew']) <br />
</source><br />
<br />
Without giving the full recipe here, we suggest at this point that you 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 />
We then once again split out the CORRECTED data column, this time only retaining spectral windows 1,3,5,7. This will get rid of the extraneous spectral windows, including the channel averaged spectral windows and spw 0, which is the one that contained the WVR data. <br />
<br />
<source lang="python"><br />
# In CASA<br />
for name in basename:<br />
os.system('rm -rf '+name+'_line.ms*')<br />
split(vis=name+'_K_WVR.ms', outputvis=name+'_line.ms',<br />
datacolumn='corrected', spw='1,3,5,7')<br />
</source><br />
<br />
The WVR and Tsys tables are now applied in the DATA column of the new measurement sets. These datasets have the extension "_line" to indicate that they only contain the spectral line data and no longer the "channel average" spectral windows. These measurement sets therefore have four spectral windows, with IDs 0-3.<br />
<br />
Now that we have applied the Tsys calibration and WVR corrections, we can concatenate the six individual data sets 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+'_line.ms')<br />
<br />
os.system('rm -rf ngc3256_line.ms*')<br />
concat(vis=comvis, concatvis='ngc3256_line.ms')<br />
</source><br />
<br />
We run a {{listobs}} on the resulting concatenated data set to check that it contains the fields, spectral windows and observing times that we expected:<br />
<br />
<source lang="python"><br />
# In CASA<br />
listobs('ngc3256_line.ms')<br />
</source><br />
<br />
There are now only four spectral windows left:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 128 TOPO 113211.988 15625 2000000 XX YY <br />
1 128 TOPO 111450.813 15625 2000000 XX YY <br />
2 128 TOPO 101506.187 15625 2000000 XX YY <br />
3 128 TOPO 103050.863 15625 2000000 XX YY <br />
</pre><br />
<br />
and eight antennas have been used in total:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Antennas: 8:<br />
ID Name Station Diam. Long. Lat. <br />
0 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8 <br />
1 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1 <br />
2 DV07 J510 12.0 m -067.45.17.8 -22.53.23.5 <br />
3 DV08 T703 12.0 m -067.45.16.2 -22.53.23.9 <br />
4 DV09 N602 12.0 m -067.45.17.4 -22.53.22.3 <br />
5 PM02 T701 12.0 m -067.45.18.8 -22.53.22.2 <br />
6 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0 <br />
7 DV10 N606 12.0 m -067.45.17.1 -22.53.23.6 <br />
</pre><br />
<br />
==Additional Data Inspection==<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 />
[[File:amp_vs_chan_ngc3256_line.png|200px|thumb|right|Amplitude vs. channel, averaged over all spw's and all baselines]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='channel', yaxis='amp',<br />
averagedata=True, avgbaseline=True, avgtime='1e8', avgscan=True,showgui = True)<br />
</source><br />
<br />
From this plot we see that the edge channels have abnormally high amplitudes. 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='ngc3256_line.ms', flagbackup=True, spw='*:0~16,*:125~127')<br />
</source><br />
<br />
Next, we will look at amplitude versus time, averaging over all channels and colorizing by field. Since the observations take place over two days, you will need to zoom in to examine the data in more detail. In particular, note the difference in Titan's amplitude between the two days and the change in amplitude during the second day. The plot on the right shows a zoom-in on the first day of observations, only showing spw 1 in this case. Scans on Titan are colored red, NGC3256 is orange, and the calibrator 1037-295 is colored black. If you select other spws, you can see some outlying points, which will be flagged later on.<br />
<br />
[[File:amp_vs_time.png|200px|thumb|right|Amplitude vs. time for spw 1, averaged over all channels]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='time', yaxis='amp',<br />
averagedata=True, avgchannel='128', coloraxis='field',<br />
iteraxis='spw',showgui = True)<br />
</source><br />
<br />
Titan is our primary flux calibrator. However, for the second day of observations, Titan had moved too close to Saturn, and Saturn's rings moved into the primary beam. Another way to see this is to plot amplitude versus uv-distance and colorize by scan: <br />
<br />
[[File:amp_vs_uvdistTitan_ngc3256_line.png|200px|thumb|right|Amplitude vs. uv-distance for Titan]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='uvdist', yaxis='amp', field='Titan',<br />
averagedata=True, avgchannel='128', avgtime='1e8', coloraxis='scan',showgui = True)<br />
</source><br />
<br />
If you use the "Mark a region" and "Locate" tools in {{plotms}}, you will see the signature of a bright, resolved source during the latter three (last day's) scans. We will therefore need to flag the Titan scans for the second day: <br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis = 'ngc3256_line.ms', flagbackup = True,<br />
timerange='>2011/04/16/12:00:00', field='Titan')<br />
</source><br />
<br />
We also find that during the first day, the Titan observations in spw 2 and 3 are also affected by Saturn. These spectral windows are at lower frequencies and therefore correspond to slightly larger primary beams. This results in Saturn just being picked up in spw 2 and 3, but not in spw 0 and 1. We do not flag these data here, but have to take this effect into account when we do the flux calibration later. <br />
<br />
Next, we will fix the position of Titan in the combined dataset. Recall that the position of the Titan field is currently set to 00:00:00.0000 +00.00.00.0000. The following call to the fixplanets task will replace this with the actual mean position observed by the telescopes and, at the same time, it will recalculate the uvw coordinates.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fixplanets(vis='ngc3256_line.ms', field='Titan', fixuvw=True)<br />
</source><br />
<br />
The third parameter in fixplanets, set to True, indicates that the uvw-coordinates for Titan are recalculated. Note that for Cycle 0 data, the coordinates of ephemeris objects will be treated correctly in the data.<br />
<br />
Now check to see that the coordinates for Titan have been corrected:<br />
<pre style="background-color: #fffacd;"><br />
INFO listobs ID Code Name RA Decl Epoch SrcId nVis <br />
INFO listobs 0 none 1037-295 10:37:16.0790 -29.34.02.8130 J2000 0 61440 <br />
INFO listobs 1 none Titan 12:51:24.5886 -02.31.59.7035 J2000 1 25344 <br />
INFO listobs 2 none NGC3256 10:27:51.6000 -43.54.18.0000 J2000 2 239616 <br />
</pre><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:<br />
*Baselines with DV07 have very high amplitudes in spw 3, correlation YY<br />
*Baselines with DV08 have very low amplitudes in spw 3, correlation YY, but only for the last observation<br />
*Baselines with PM03 have low amplitudes at 2011/04/17/02:15:00 for spw 0<br />
*Baselines with PM03 have low amplitudes at 2011/04/16/04:15:15 for spw 2 and 3<br />
*For the second day, the baseline DV10-PM03 is corrupted<br />
The times to insert in flagdata can be obtained using plotms Tools Hover/Display. Instead of using the following {{flagdata}} commands, you can also flag by hand in {{plotms}}. To do this, select your bad data by clicking on the 'Mark Regions" button, then on 'Flag".<br />
<br />
We flag the bad data with the following commands: <br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='ngc3256_line.ms', flagbackup=True, spw='3',<br />
correlation='YY', mode='manual',<br />
antenna='DV07', timerange='')<br />
<br />
flagdata(vis='ngc3256_line.ms', flagbackup=True, spw='3',<br />
correlation='YY', mode='manual',<br />
antenna='DV08', timerange='>2011/04/17/03:00:00')<br />
<br />
flagdata(vis='ngc3256_line.ms', flagbackup=True, spw='0',<br />
correlation='', mode='manual',<br />
antenna='PM03', timerange='2011/04/17/02:15:00~02:15:50')<br />
<br />
flagdata(vis='ngc3256_line.ms', flagbackup=True, spw='2,3', <br />
correlation='', mode='manual',<br />
antenna='PM03', timerange='2011/04/16/04:13:50~04:18:00')<br />
<br />
flagdata(vis='ngc3256_line.ms', flagbackup=True, spw='',<br />
correlation='', mode='manual',<br />
antenna='PM03&DV10', timerange='>2011/04/16/15:00:00')<br />
</source><br />
<br />
==Bandpass Calibration==<br />
<br />
We are now ready to begin the bandpass calibration. First, we will inspect the bandpass calibrator by plotting the phase as a function of frequency and time. For the first plot we use avgscan=T and avgtime='1E6' to average in time over all scans, and we specify coloraxis='baseline' to colorize by baseline. For the second, we use spw='0:30~90' and avgchannel='128' to average over the central 61 channels of the first spectral window. For both plots we will iterate on antenna, so you will need to use the green arrows at the bottom of the plotms GUI to view different antennas.<br />
<br />
[[File:phase_vs_frequency.png|200px|thumb|right|Phase vs. frequency for the phase calibrator, averaged over time]]<br />
[[File:phase_vs_time_PM03.png|200px|thumb|right|Phase vs. time for the phase calibrator, all baselines with antenna PM03]]<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='freq', yaxis='phase', selectdata=True,<br />
field='1037*', avgtime='1E6', avgscan=True, coloraxis='baseline', iteraxis='antenna',showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='time', yaxis='phase', selectdata=True,<br />
field='1037*', spw='0:30~90', avgchannel='128', avgscan=True, <br />
coloraxis='baseline', iteraxis='antenna',showgui = True)<br />
</source><br />
<br />
The top plot on the right shows the time-averaged phase as a function of frequency for the calibrator 1037-295, with all baselines shown at once (i.e., without iteraxis='antenna') for presentation purposes. We see that the phase variations across the spectral windows are modest, typically ~30 degrees. The second plot shows how the phase varies as function of time. For clarity, we only show baselines with one antenna and only for the first day of observations. There are clearly phase variations on short time scales that we wish to correct for before calculating the bandpass solutions.<br />
<br />
Hence, we 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 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 />
We will use the average of channels 40 to 80 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. For our reference antenna, we choose DV04. We call the output calibration table "cal-ngc3256.G1".<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='ngc3256_line.ms', caltable='cal-ngc3256.G1', spw='*:40~80', field='1037*',<br />
selectdata=True, solint='int', refant='DV04', calmode='p')<br />
</source><br />
<br />
We then check the time variations of the phase solutions with {{plotcal}}. We will plot the XX and YY polarization products separately and make different subplots for each of the spectral windows. This is done by setting the "iteration" parameter to "spw" and specifying subplot=221. By setting the parameter "figfile" to a non-blank value, it will also generate png files of the plots. <br />
<br />
[[File:cal-phase_vs_time_XX.G1.png|200px|thumb|right|Phase-only gaincal solutions vs. time for correlation XX]]<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256.G1', xaxis = 'time', yaxis = 'phase',<br />
poln='X', plotsymbol='o', plotrange = [0,0,-180,180], iteration = 'spw',<br />
figfile='cal-phase_vs_time_XX.G1.png', subplot = 221, showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256.G1', xaxis = 'time', yaxis = 'phase',<br />
poln='Y', plotsymbol='o', plotrange = [0,0,-180,180], iteration = 'spw',<br />
figfile='cal-phase_vs_time_YY.G1.png', subplot = 221, showgui = True)<br />
</source><br />
<br />
If you examine the solutions closely, you may notice some phase jumps. (For example: Correlation XX, spw 3, antenna DV09). These jumps occur between the individual observing blocks and will thus not affect the science data. Other than that, the solutions look reasonable.<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". Now that the phases are corrected, the data can be time-averaged over longer intervals to maximise SNR in each individual channel. We determine bandpass solutions for both days separately because we find that for some antennas, the response across the bandwidth has changed slightly in between the two sessions. We first calculate the bandpass solution for the first day. In order to achieve that only a single solution is created for the day, we set parameter "combine" to 'scan,obs' meaning that combination of solutions should neither halt at scan nor at observation boundaries. <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 />
bandpass(vis = 'ngc3256_line.ms', caltable = 'cal-ngc3256.B1', <br />
gaintable = 'cal-ngc3256.G1', timerange='<2011/04/16/15:00:00',<br />
field = '1037*', minblperant=3, minsnr=2, solint='inf', combine='scan,obs',<br />
bandtype='B', fillgaps=1, refant = 'DV04', solnorm = True)<br />
</source><br />
<br />
*caltable = 'cal-ngc3256.B1': Output bandpass calibration table<br />
*gaintable = 'cal-ngc3256.G1': Gain calibration table to apply<br />
*minblperant=3: Minimum number of baselines required per antenna for each solve<br />
*minsnr=2: Minimum SNR for solutions<br />
*solint='inf': This setting, combined with the default combine='scan', sets the solution interval to the entire observation<br />
*combine='scan,obs': The solutions cross scans and observations <br />
*timerange='<2011/04/16/15:00:00': Only determine solutions for the first day<br />
*bandtype='B': The default type of bandpass solution, which does a channel by channel solution for each specified spw<br />
*fillgaps=1: Interpolate channel gaps 1 channel wide<br />
*solnorm=True: Normalize the bandpass amplitudes and phases of the corrections to unity<br />
<br />
And then append the solutions (append=True) for the second day:<br />
<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis = 'ngc3256_line.ms', caltable = 'cal-ngc3256.B1', <br />
gaintable = 'cal-ngc3256.G1', timerange='>2011/04/16/15:00:00',<br />
field = '1037*', minblperant=3, minsnr=2, solint='inf', combine='scan,obs',<br />
bandtype='B', fillgaps=1, refant = 'DV04', solnorm = True, append=True)<br />
</source><br />
<br />
[[File:bandpass.B1.spw03.t00.png|200px|thumb|right|Bandpass phase solutions]]<br />
[[File:bandpass.B2.spw03.t00.png|200px|thumb|right|Bandpass amplitude solutions]]<br />
We then plot the bandpass solutions with the following commands:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = 'cal-ngc3256.B1', xaxis='freq', yaxis='phase', plotrange = [0,0,-70,70],<br />
overlay='antenna', figfile='bandpass.B1.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable = 'cal-ngc3256.B1', xaxis='freq', yaxis='amp', overlay='antenna',<br />
figfile='bandpass.B2.png')<br />
</source><br />
<br />
The solutions seem reasonable, so we will now apply them on-the-fly during gain calibration.<br />
<br />
== Gain Calibration ==<br />
<br />
The first step is to set the flux density for Titan using the task {{setjy}}. We will use the Butler-JPL-Horizons 2012 model:<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='ngc3256_line.ms', field='Titan', standard='Butler-JPL-Horizons 2012', <br />
spw='0,1,2,3', usescratch=False)<br />
</source><br />
<br />
The flux density of Titan is 382 mJy at 114 GHz (spw 0) and drops to 308 mJy at 101 GHz (spw 2):<br />
<br />
<pre style="background-color: #fffacd;"><br />
setjy::::casa Titan: spw0 Flux:[I=0.38239,Q=0.0,U=0.0,V=0.0] +/- [I=0.0,Q=0.0,U=0.0,V=0.0] Jy<br />
setjy::::casa Titan: spw1 Flux:[I=0.36941,Q=0.0,U=0.0,V=0.0] +/- [I=0.0,Q=0.0,U=0.0,V=0.0] Jy<br />
setjy::::casa Titan: spw2 Flux:[I=0.30803,Q=0.0,U=0.0,V=0.0] +/- [I=0.0,Q=0.0,U=0.0,V=0.0] Jy<br />
setjy::::casa Titan: spw3 Flux:[I=0.31667,Q=0.0,U=0.0,V=0.0] +/- [I=0.0,Q=0.0,U=0.0,V=0.0] Jy<br />
</pre><br />
<br />
Now we will do a new gain calibration, this time applying the bandpass calibration solutions on-the-fly. We solve for amplitude and phase simultaneously and determine average solutions per scan:<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis = 'ngc3256_line.ms', caltable = 'cal-ngc3256.G2', spw =<br />
'*:16~112', field = '1037*,Titan', minsnr=1.0,<br />
solint= 'inf', selectdata=True, solnorm=False, refant = 'DV04',<br />
gaintable = 'cal-ngc3256.B1', calmode = 'ap')<br />
</source><br />
<br />
*caltable = 'cal-ngc3256.G2': the output gain calibration table<br />
*minsnr=1.0: To reject solutions with a signal-to-noise less than 1.0<br />
*calmode = 'ap': To solve for amplitude and phase<br />
*spw='*:16~112': to select all spectral windows, but only the inner 75% of the channels of each<br />
*solint='inf': Together with the default for the "combine" parameter, this setting will solve for one solution per scan<br />
*solnorm=False: We do not want to normalize the solutions to unity since we wish to relate the measured amplitudes of the secondary calibrator (1037-295) to the flux calibrator (Titan)<br />
*gaintable = ['cal-ngc3256.B1']: We apply the bandpass calibration on-the-fly<br />
<br />
Now we will examine the amplitude and phase solutions as a function of time, iterating on spectral window and plotting the XX and YY correlations separately for clarity. Zoom in on the GUI to examine the plots in more detail. You can also use the "Mark Region" and "Locate" buttons on the toolbar to identify points. Use the field parameter to select which calibrator you want to plot the solutions for.<br />
<br />
[[File:Amp_vs_time_YY.G2.png|200px|thumb|right|Gain amplitude Solutions]]<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256.G2', xaxis = 'time', yaxis = 'phase',<br />
poln='X', plotsymbol='o', plotrange = [0,0,-180,180], iteration= 'spw', <br />
figfile='cal-phase_vs_time_XX.G2.png', subplot = 221, showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256.G2', xaxis = 'time', yaxis = 'phase',<br />
poln='Y', plotsymbol='o', plotrange = [0,0,-180,180], iteration= 'spw', <br />
figfile='cal-phase_vs_time_YY.G2.png', subplot = 221, showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256.G2', xaxis = 'time', yaxis = 'amp',<br />
poln='X', plotsymbol='o', plotrange = [], iteration = 'spw',<br />
figfile='cal-amp_vs_time_XX.G2.png', subplot = 221, showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable = 'cal-ngc3256.G2', xaxis = 'time', yaxis = 'amp',<br />
poln='Y', plotsymbol='o', plotrange = [], iteration = 'spw',<br />
figfile='cal-amp_vs_time_YY.G2.png', subplot = 221, showgui = True)<br />
</source><br />
<br />
We find very stable amplitude solutions for the phase calibrator. The lower points for the first day are the solutions for Titan.<br />
<br />
Finally, we will bootstrap the flux density of the secondary calibrator from that of Titan using the task {{fluxscale}}. <br />
The new flux table cal-ngc3256.G2.flux replaces the previous cal-ngc3256.G2 table in future application of the calibration to the data, i.e. the new flux table contains both cal-ngc3256.G2 and the newly acquired flux scaling. Unlike the gain calibration steps, this is not an incremental table.<br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale( vis="ngc3256_line.ms", caltable="cal-ngc3256.G2",<br />
fluxtable="cal-ngc3256.G2.flux", reference="Titan",<br />
transfer="1037*", refspwmap=[0,1,1,1])<br />
</source><br />
<br />
Note that we previously flagged the Titan scans from the second day due to contamination from nearby Saturn's rings. We have therefore used the Titan scans from the first day alone to flux calibrate both days' observations. This would not always be an acceptable solution; however, in this case, examination of the measured amplitudes for the phase calibrator over both days indicate that the flux scale is relatively stable. <br />
<br />
Also note that we have used refspwmap=[0,1,1,1]. This means that the 1037-295 observations in spw 2 and 3 are referenced to Titan observations observed in spw 1. We have to do this here because the Titan data in spw 2 and 3 are contaminated by Saturn, as explained above.<br />
<br />
The logger produces the following output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
INFO fluxscale:::: Flux density for 1037-295 in SpW=0 is: 1.89015 +/- 0.0301006 (SNR = 62.7946, N = 14)<br />
INFO fluxscale:::: Flux density for 1037-295 in SpW=1 is: 1.93009 +/- 0.0352334 (SNR = 54.7802, N = 14)<br />
INFO fluxscale:::: Flux density for 1037-295 in SpW=2 (ref SpW=1) is: 2.00355 +/- 0.0350797 (SNR = 57.1141, N = 14)<br />
INFO fluxscale:::: Flux density for 1037-295 in SpW=3 (ref SpW=1) is: 1.86306 +/- 0.041598 (SNR = 44.7873, N = 12)<br />
</pre><br />
<br />
We find that the flux density of 1037-295 is ~1.9 Jy in the higher frequency spectral windows and ~2.0 Jy in the lower frequency spectral windows. These fluxes are very well within the range of the 3mm measurements observed by the ATCA and OVRO of a few years ago (see the SMA calibrator list [http://sma1.sma.hawaii.edu/callist/callist.html?plot=1037-295]).<br />
<br />
==Applying the calibrations ==<br />
<br />
Now we will use {{applycal}} to apply the bandpass and gaincal tables that we generated in the previous sections. First, we will apply the solutions from the secondary calibrator to the science target and the secondary calibrator itself. We want to use the solutions from the secondary calibrator for the science target because, as the phase calibrator, it was observed throughout the observations. Its flux scale has also now been bootstrapped to that of the flux calibrator, so it can serve as an amplitude and phase calibrator. The application of the solutions to the secondary calibrator itself is a way for us to check the quality of the calibration. Below, we will do the same for the flux calibrator (Titan), applying its amplitude and phase solutions to itself to check the calibration.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal( vis='ngc3256_line.ms', flagbackup=False, field='NGC*,1037*',<br />
interp=['nearest','nearest'], gainfield = ['1037*', '1037*'],<br />
gaintable=['cal-ngc3256.G2.flux', 'cal-ngc3256.B1'])<br />
</source><br />
<br />
*gaintable=['cal-ngc3256.G2.flux', 'cal-ngc3256.B1']: We apply the gaincal table with the correct flux scaling and the bandpass table<br />
*gainfield = ['1037*', '1037*']: We use the solutions from the secondary calibrator (1037-295) in both tables<br />
*interp='nearest': We opt for interpolation mode "nearest"<br />
*flagbackup=False: We do not back up the state of the flags before applying calibration<br />
<br />
[[File:Amp_vs_freqNGC3256corr.png|200px|thumb|right|Amp vs Freq]]<br />
Let's now use {{plotms}} to examine the corrected amplitude of NGC3256 as a function of frequency:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='NGC*',<br />
averagedata=True, avgchannel='', avgtime='10000s',<br />
avgscan=True, avgbaseline=True, coloraxis='spw',showgui = True)<br />
</source><br />
<br />
Use the "Zoom" tool to zoom in on the different spectral windows. (Note that spw 2-3 are on the left). There are three emission lines in spectral windows 0-1. There is no emission in spw 2 and 3. Also note that there are still some high channels on the edge of spw 2-3. We will exclude these channels for our subsequent imaging.<br />
<br />
It also makes sense to plot the corrected amplitudes and phases of 1037-295 as a function of time and frequency, to check that the phases are close to zero and the amplitudes are constant. The result of the amplitude versus time plot is shown to the right.<br />
<br />
[[File:amp_vs_time_calibrator.png|200px|thumb|right|Corrected amplitude vs. time for the calibrator]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='time', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='1037*',<br />
averagedata=True, avgchannel='128', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='spw',showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='freq', yaxis='phase',<br />
ydatacolumn='corrected', selectdata=True, field='1037*',<br />
averagedata=True, avgchannel='', avgtime='1e8',<br />
avgscan=True, avgbaseline=False, coloraxis='baseline',showgui = True)<br />
</source><br />
<br />
Based on the inspection of these plots, we identify some bad data and flag them:<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='ngc3256_line.ms', mode='manual',<br />
timerange='2011/04/16/04:13:35~04:13:45', flagbackup = True)<br />
tget(flagdata)<br />
timerange='2011/04/16/05:21:13~05:21:19'<br />
flagdata()<br />
timerange='2011/04/16/04:16:40~04:16:49'<br />
flagdata()<br />
timerange='2011/04/16/04:14:00~04:17:10'; antenna='PM03'<br />
flagdata()<br />
timerange='2011/04/17/01:52:20~01:53:10'; antenna='DV10'<br />
flagdata()<br />
timerange='2011/04/17/00:35:30~01:20:20'; antenna='DV04'; spw='3'<br />
flagdata()<br />
</source><br />
<br />
Note that in the above command sequence, we utilize the CASA function [http://casa.nrao.edu/docs/userman/UserMansu36.html#x44-430001.3.5.6 tget]. This function retrieves the last input values for the function specified.<br />
<br />
Now that we have flagged some of the calibrator data, we should redo the calibration steps above. We start with a {{delmod}} to reinitialize the MODEL column in ngc3256_line.ms. After the {{delmod}}, the commands are identical to what has been done above. <br />
<br />
<source lang="python"><br />
# In CASA<br />
delmod('ngc3256_line.ms')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='ngc3256_line.ms', caltable='cal-ngc3256.G1n', spw='*:40~80', field='1037*',<br />
selectdata=True, solint='int', refant='DV04', calmode='p')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis = 'ngc3256_line.ms', caltable = 'cal-ngc3256.B1n', <br />
gaintable = 'cal-ngc3256.G1n', timerange='<2011/04/16/15:00:00',<br />
field = '1037*', minblperant=3, minsnr=2, solint='inf', combine='scan,obs',<br />
bandtype='B', fillgaps=1, refant = 'DV04', solnorm = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis = 'ngc3256_line.ms', caltable = 'cal-ngc3256.B1n', <br />
gaintable = 'cal-ngc3256.G1n', timerange='>2011/04/16/15:00:00',<br />
field = '1037*', minblperant=3, minsnr=2, solint='inf', combine='scan,obs',<br />
bandtype='B', fillgaps=1, refant = 'DV04', solnorm = True, append=True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='ngc3256_line.ms', field='Titan', standard='Butler-JPL-Horizons 2012', <br />
spw='0,1,2,3',usescratch=False)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis = 'ngc3256_line.ms', caltable = 'cal-ngc3256.G2n', spw =<br />
'*:16~112', field = '1037*,Titan', minsnr=1.0,<br />
solint= 'inf', selectdata=True, solnorm=False, refant = 'DV04',<br />
gaintable = 'cal-ngc3256.B1n', calmode = 'ap')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
fluxscale( vis="ngc3256_line.ms", caltable="cal-ngc3256.G2n",<br />
fluxtable="cal-ngc3256.G2n.flux", reference="Titan",<br />
transfer="1037*", refspwmap=[0,1,1,1])<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal( vis='ngc3256_line.ms', flagbackup=False, field='NGC*,1037*',<br />
interp=['nearest','nearest'], gainfield = ['1037*', '1037*'],<br />
gaintable=['cal-ngc3256.G2n.flux', 'cal-ngc3256.B1n'])<br />
</source><br />
<br />
Having redone the calibration, we will again look at amplitude and phase versus time to check that the amplitudes are stable and the phases are close to zero. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='time', yaxis='amp',<br />
ydatacolumn='corrected', selectdata=True, field='1037*',<br />
averagedata=True, avgchannel='128', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='spw',showgui = True)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='ngc3256_line.ms', xaxis='freq', yaxis='phase',<br />
ydatacolumn='corrected', selectdata=True, field='1037*',<br />
averagedata=True, avgchannel='', avgtime='1e8',<br />
avgscan=True, avgbaseline=False, coloraxis='baseline',showgui = True)<br />
</source><br />
<br />
<gallery widths="400px" heights="300px" perrow="2"><br />
File:amp_vs_time_calibrator2.png|Corrected amplitude vs. time<br />
File:phase_vs_freq_1037.png|Corrected phase vs. frequency<br />
</gallery><br />
<br />
<br />
In the first plot we show amplitude vs time, colorized by spectral window. This shows very clearly that the amplitude is constant in time, but varies as a function of frequency, which is intrinsic to the source. The second plot shows that the phases are very flat across all spectral windows.<br />
<br />
==Imaging the Calibrators==<br />
<br />
At this point, we will image the secondary calibrator as a check of our calibration. We do this using the task {{clean}}, after first removing any previous versions of the images that may exist in our directory. This is an important precaution, since if the image already exists, CASA will clean it further instead of producing a new image. In this {{clean}} run, we choose to use Multi-Frequency Synthesis (mfs) with nterms=2, which implies that the algorithm determines the continuum map and the spectral index map simultaneously. This is required here, because we found with {{fluxscale}} that the flux of 1037-295 increases significantly toward lower frequencies. Therefore, assuming a 'flat' spectral index would not give a good result. Do not be alarmed to see this message: "Multi-term MFS imaging algorithm is new and under active development and testing". The method is working fine and has been tested.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-phasecal_cont*')<br />
clean(vis='ngc3256_line.ms', imagename='result-phasecal_cont', field='1037*',<br />
spw='*:20~120', selectdata=True, mode='mfs', niter=500,<br />
gain=0.1, threshold='0.75mJy', psfmode='hogbom',<br />
interactive=False, mask=[62, 62, 67, 67], imsize=128,<br />
cell='1arcsec', weighting='briggs', robust=0.0, nterms=2)<br />
</source><br />
<br />
[[File:phasecal_map_lin.png|200px|thumb|right|Continuum image of phasecal]]<br />
[[File:phasecal_map.png|200px|thumb|right|Continuum image of phasecal, with logarithmic color scaling to bring out the weaker features in the map]]<br />
*imagename='result-phasecal_cont': the base name of the output images<br />
*spw='*:20~120': We image all spectral windows, ignoring the outermost channels of each<br />
*mode='mfs': Mult-Frequency Synthesis: the default mode, which produces one image from all the specified data combined<br />
*nterms=2: The number of Taylor terms to be used to model the frequency dependence of the sky emission<br />
*niter=500: Maximum number of clean iterations<br />
*theshold='0.75mJy': Stop cleaning if the maximum residual is below this value. Here we choose a threshold equal to ~1.5 times the rms noise level<br />
*psfmode='hogbom': The method used to calculate the PSF during minor clean cycles. Hogbom is a good choice for poorly-sampled uv-planes<br />
*mask=[62, 62, 67, 67]: Limits the clean component placement to the region of the source. We know the source is compact so we do not need to worry about boxing interactively<br />
*imsize=128, cell='1arcsec': Chosen to appropriately sample the resolution element and cover the primary beam<br />
*weighting='briggs', robust=0.0: a weighting scheme that offers a good compromise between sensitivity and resolution<br />
<br />
Note that using nterms=2 makes the {{clean}} task considerably slower than before. Once the imaging of the secondary calibrator is complete, we will generate some statistics on the image using the task {{imstat}}. Note that {{clean}} generates several output images when used with nterms=2. The continuum intensity map has suffix .tt0. The spectral index map has suffix .alpha. For more see http://casa.nrao.edu/docs/UserMan/UserManse27.html .<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename='result-phasecal_cont.image.tt0', region='', box='85,8,120,120')<br />
rms=(calstat['rms'][0])<br />
print '>> rms in phase calibrator image: '+str(rms)<br />
calstat=imstat(imagename='result-phasecal_cont.image.tt0', region='')<br />
peak=(calstat['max'][0])<br />
print '>> Peak in phase calibrator image: '+str(peak)<br />
print '>> Dynamic range in phase calibrator image: '+str(peak/rms)<br />
</source><br />
<br />
Here, we have used the "box" parameter in the first call of {{imstat}} to find the image rms in a region away from the strong central point source. The image dynamic range in the calibrator image is ~1900. We will then look at the image of the secondary calibrator with {{imview}}. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'result-phasecal_cont.image.tt0', 'colorwedge':True,<br />
'range':[-0.004, 0.250], 'scaling':-1.5, 'colormap':'Rainbow 2'},<br />
out='result-phasecal_map.png', zoom=1)<br />
</source><br />
<br />
This command rasters the image of the phase calibrator to the GUI and outputs the file phasecal_map.png. It uses the Rainbow 2 colomap scheme and includes a colorwedge on the plot. The "range" and "scaling" parameters have been chosen to bring out the weaker features in the map. The calibrator image looks pretty good, from which we conclude that the gain calibration has worked well and we will move on. If the image quality was not acceptable, we would need to flag some more data and redo the calibration to this point. <br />
<br />
Now we will apply the calibration to the flux calibrator, Titan, using the time-dependent solutions we derived for Titan itself and the bandpass solutions from 1037*.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='ngc3256_line.ms', flagbackup=False, field='Titan',<br />
interp=['nearest', 'nearest'], gainfield = ['Titan', '1037*'],<br />
gaintable=['cal-ngc3256.G2.flux', 'cal-ngc3256.B1'])<br />
</source><br />
<br />
Now we will image the flux calibrator (Titan). See the previous call to {{clean}} for a description of the various inputs. This time we will only use spectral windows 0 and 1 because we know that the Titan data in spectral windows 2 and 3 are corrupted by Saturn. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf result-ampcal_cont*')<br />
clean(vis='ngc3256_line.ms', imagename='result-ampcal_cont', <br />
field='Titan', spw='0:20~120,1:20~120', mode='mfs', niter=200, <br />
threshold='5mJy', psfmode='hogbom', mask=[62, 62, 67, 67], imsize=128,<br />
cell='1arcsec', weighting='briggs', robust=0.0, interactive=True)<br />
</source><br />
<br />
[[File:ampcal_map_lin.png|200px|thumb|right|Continuum image of Titan]]<br />
[[File:ampcal_map.png|200px|thumb|right|Continuum image of Titan, with logarithmic color scaling to bring out the weaker features in the map]]<br />
As before, we will generate some statistics on the image:<br />
<br />
<source lang="python"><br />
# In CASA<br />
calstat=imstat(imagename="result-ampcal_cont.image",region="",box="85,8,120,120")<br />
rms=(calstat['rms'][0])<br />
print ">> rms in amp calibrator image: "+str(rms)<br />
calstat=imstat(imagename="result-ampcal_cont.image",region="")<br />
peak=(calstat['max'][0])<br />
print ">> Peak in amp calibrator image: "+str(peak)<br />
print ">> Dynamic range in amp calibrator image: "+str(peak/rms)<br />
</source><br />
<br />
The dynamic range in this image is ~74. It's much less than the image of the secondary calibrator because less time was spent observing it (the total on-source time on Titan is only 9 minutes). We will then take a look at the image with {{imview}}, again choosing the data range and scaling parameter to bring out weak features in the map:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'result-ampcal_cont.image', 'colorwedge':True,<br />
'range':[-0.02, 0.250], 'scaling':-1.5, 'colormap':'Rainbow 2'},<br />
out='result-ampcal_map.png', zoom=1)<br />
</source><br />
<br />
The image of Titan has the expected shape and noise properties, which further confirms the quality of the calibration. <br />
<br />
The last step is to split out the science target, since we no longer need the calibrator data. We run {{split}} with field='NGC*' to create ngc3256_line_target.ms:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf ngc3256_line_target.ms*')<br />
split(vis='ngc3256_line.ms', outputvis='ngc3256_line_target.ms',<br />
field='NGC*')<br />
</source><br />
<br />
This concludes the Calibration section of this CASA Guide. To proceed to the Imaging section, click here: '''[[NGC3256_Band3_Imaging_for_CASA_4.5]]'''. To go back to the main NGC3256 page, see: '''[[NGC3256Band3]]'''.<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Calibration_for_CASA_4.5&diff=212443C286 Band6Pol Calibration for CASA 4.52017-04-04T13:52:10Z<p>Jthorley: </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.5]]'''.<br />
<br />
'''This guide is designed for CASA 4.5.'''<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.5. 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.5.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=False)<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=False)<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=False)<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.5 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.5#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 = True,<br />
flagbackup = False)<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 = True,<br />
flagbackup = False)<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 = True,<br />
flagbackup = False)<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=True, avgbaseline=True, avgtime='1e8', avgscan=True, 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=True, 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=True, 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.5 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.5#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=True, <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=True: 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=True,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G2ph','3c286_Band6.ms.flux'],<br />
interp=['nearest','linear','linear'], parang=False)<br />
<br />
</source><br />
<br />
*calwt=True: 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=True, avgchannel='128', avgbaseline=True, 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.5#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=True,<br />
gaintable=['3c286_Band6.ms.Bscan','3c286_Band6.ms.G1'],<br />
interp=['nearest','linear'], parang=False)<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=True,<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=True: 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=True,<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=True,<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=True)<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=True: this time the parallactic angle dependence is corrected for in computing the gains.<br />
<br />
With parang=True 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=True)<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=True, 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=True)<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=True,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=True)<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=True, <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=True)<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=True: 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=True, 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.5 |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.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=3C286_Band6Pol_Imaging_for_CASA_4.5&diff=212433C286 Band6Pol Imaging for CASA 4.52017-04-04T13:46:30Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Imaging]][[Category:Polarization]]<br />
<br />
==Overview==<br />
'''This guide is designed for CASA 4.5.'''<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.5]]''' 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.5 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.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.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=M100_Band3_Combine_4.5&diff=21242M100 Band3 Combine 4.52017-04-04T13:36:14Z<p>Jthorley: </p>
<hr />
<div><pre style="background-color: #ffa07a;"><br />
WARNING: Note that this guide has been prepared exclusively for the 2016 Synthesis Imaging Summer School and is not intended for general use. <br />
<br />
The currently maintained combination CASAguide, written for CASA 4.3.0, can be found here: https://casaguides.nrao.edu/index.php/M100_Band3_Combine_4.3<br />
</pre><br />
<br />
<br />
= Overview =<br />
<br />
This guide describes how to combine the 7m and 12m interferometric data and then how to feather the resulting image with the total power TP image. All of the data for this SV project can be found at https://almascience.nrao.edu/alma-data/science-verification. '''This guide has been written for data reduced in CASA 4.5.0''' and assumes that all calibration tables (Tsys and gain tables) have been applied to the visibility weights using calwt=True. If either of these is not the case for your data, do not follow this guide, instead look at https://casaguides.nrao.edu/index.php/DataWeightsAndCombination for methods to correct the data weights for data reduced in earlier versions of CASA.<br />
<br />
In order to run this guide you will need the following three files:<br />
* 12m array calibrated data: M100_Band3_12m_CalibratedData.ms<br />
* 7m array calibrated data: M100_Band3_7m_CalibratedData.ms<br />
* Total Power image: M100_TP_CO_cube.bl.image<br />
<br />
To obtain the '''fully calibrated 12m data''' M100_Band3_12m_CalibratedData.ms, either download the file M100_Band3_12m_CalibratedData.tgz or download the uncalibrated 12m data (M100_Band3_12m_UnalibratedData.tgz) and execute the calibration scripts (M100_Band3_12m_CalibrationScripts.tgz). How to obtain the data is described in [[M100_Band3#Obtaining the Data]]. An overview of the 12m data and its calibration is located at [[M100_Band3]].<br />
<br />
<pre style="background-color: #ffa07a;"><br />
WARNING: Note that the imaging presented in this Guide uses the new calibration (using CASA 4.5)<br />
of the same 12-m array data that were released previously (using CASA 3.3).<br />
<br />
Do not use the previously released CASA 3.3 version of the calibrated 12-m data (either downloaded <br />
before 28 July 2015 or identified by the suffix "_CASA3.3" after 28 July 2015) for this tutorial.<br />
</pre><br />
<br />
To obtain the '''fully calibrated 7m data''' M100_Band3_7m_CalibratedData.ms, either download the file M100_Band3_7m_CalibratedData.tgz or download the uncalibrated 7m data (M100_Band3_7m_UnalibratedData.tgz) and execute the calibration scripts (M100_Band3_7m_CalibrationScripts.tgz). How to obtain the data is described in [[M100_Band3#Obtaining the Data]]. An overview of the 7m data and its calibration is located at [[M100_Band3]].<br />
<br />
To obtain the '''Total Power image''' M100_TP_CO_cube.bl.image, either run the [[M100_Band3_SingleDish_4.5]] guide to calibrate and image the Total Power data or download the image file from M100_ACA_ReferenceImages.tgz. How to obtain the data is described in [[M100_Band3#Obtaining the Data]]. An overview of the Total Power data and its calibration is located at [[M100_Band3]].<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
= Combine and Image the 7m+12m Interferometric Data =<br />
<br />
<br />
== Split off CO spectral windows (SPWs) ==<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf m100_*m.ms.listobs')<br />
listobs('M100_Band3_12m_CalibratedData.ms',listfile='M100_12m.ms.listobs')<br />
listobs('M100_Band3_7m_CalibratedData.ms',listfile='M100_7m.ms.listobs')<br />
</source><br />
<br />
Running the task "listobs" provides the setups used in the observations at a glance. Below are the first target scans of the 12m and 7m observations and the spectral window tables as generated by listobs; these are excerpts from the complete files obtained in each case. Notice that the six 7m data sets were taken with two slightly different correlator setups (one with four SPWs and the other with two SPWs), so the concatenated data set has six total SPWs. <br />
<br />
12m data:<br />
<pre style="background-color: #fffacd;"><br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
10-Aug-2011/19:38:05.8 - 19:50:22.8 11 1 M100 1500 [0,1,2,3] [6.05, 6.05, 6.05, 6.05] [CALIBRATE_WVR#ON_SOURCE,OBSERVE_TARGET#ON_SOURCE]<br />
<br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs<br />
0 3840 TOPO 113726.419 488.281 1875000.0 114663.6750 1 XX YY<br />
1 3840 TOPO 111851.419 488.281 1875000.0 112788.6750 2 XX YY<br />
2 3840 TOPO 103663.431 -488.281 1875000.0 102726.1750 3 XX YY<br />
3 3840 TOPO 101850.931 -488.281 1875000.0 100913.6750 4 XX YY<br />
</pre><br />
<br />
<br />
7m data:<br />
<pre style="background-color: #fffacd;"><br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
17-Mar-2013/04:44:04.3 - 04:50:43.7 11 1 M100 261 [0,1,2,3] [10.1, 10.1, 10.1, 10.1] [OBSERVE_TARGET#ON_SOURCE]<br />
<br />
Spectral Windows: (6 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs<br />
0 ALMA_RB_03#BB_1#SW-01#FULL_RES 4080 TOPO 101945.850 -488.281 1992187.5 100950.0000 1 XX YY<br />
1 ALMA_RB_03#BB_2#SW-01#FULL_RES 4080 TOPO 103761.000 -488.281 1992187.5 102765.1500 2 XX YY<br />
2 ALMA_RB_03#BB_3#SW-01#FULL_RES 4080 TOPO 111811.300 488.281 1992187.5 112807.1500 3 XX YY<br />
3 ALMA_RB_03#BB_4#SW-01#FULL_RES 4080 TOPO 113686.300 488.281 1992187.5 114682.1500 4 XX YY<br />
4 ALMA_RB_03#BB_1#SW-01#FULL_RES 4080 TOPO 111798.250 488.281 1992187.5 112794.1000 1 XX YY<br />
5 ALMA_RB_03#BB_2#SW-01#FULL_RES 4080 TOPO 113673.250 488.281 1992187.5 114669.1000 2 XX YY<br />
</pre><br />
<br />
<figure id="12m_mosaic.png"><br />
[[Image:12m_mosaic.png|300px|thumb|right|<caption>FOV of 12m mosaic.</caption>]]<br />
</figure><br />
<br />
<figure id="7m_mosaic.png"><br />
[[Image:7m_mosaic.png|300px|thumb|right|<caption>FOV of 7m mosaic.</caption>]]<br />
</figure><br />
<br />
Examination of the listobs files shows that the CO is in SPW='0' for the 12m data and in SPW='3,5' for the 7m data. There are two SPWs containing CO in the 7m data due to the slightly differing correlator setups.<br />
<br />
Also note that the integration time per visibility (average interval parameter in listobs) is different:<br />
6.05s for the 12m data and 10.1s for the 7m. This will be important to know later when we check the visibility weights. <br />
<br />
Next we split out the CO spectral windows.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_12m_CO.ms')<br />
split(vis='M100_Band3_12m_CalibratedData.ms',<br />
outputvis='M100_12m_CO.ms',spw='0',field='M100',<br />
datacolumn='data',keepflags=False)<br />
os.system('rm -rf M100_7m_CO.ms')<br />
split(vis='M100_Band3_7m_CalibratedData.ms',<br />
outputvis='M100_7m_CO.ms',spw='3,5',field='M100',<br />
datacolumn='data',keepflags=False)<br />
</source><br />
<br />
Also of interest is that the 12m data has 47 fields and the 7m has 23 fields (not shown in the excerpts above). The difference in number of pointings is because the 7m antennas have a FWHP (full width half power) primary beam diameter that is 12/7 times larger than the 12m antennas. '''One easy way to see how the mosaics compare is to install the AnalysisUtils package (see [[Analysis_Utilities]] for information on how to download and import AnalysisUtils)'''. Then with AnalysisUtils you can make the following plots (look at the listobs to obtain the sourceid):<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf *m_mosaic.png')<br />
au.plotmosaic('M100_12m_CO.ms',sourceid='0',figfile='12m_mosaic.png')<br />
au.plotmosaic('M100_7m_CO.ms',sourceid='0',figfile='7m_mosaic.png')<br />
</source><br />
<br />
We see that the mosaics cover a common area but that the 7m mosaic is a bit larger. This means that the outer edges of the combined mosaic will be noisier than expected if they overlapped perfectly; this is just something to keep in mind. If you had the case where the mosaic coverages are dramatically different, it would be best to exclude the completely non-overlapping fields from the combination.<br />
<br />
NOTE: At this stage one would typically do continuum subtraction (if there is any). However we already know from the individual data reductions that the 3mm continuum emission is quite weak and does not significantly contribute to a 5km/s channel, so we will forgo the the continuum subtraction step. Examples of how to do this if you are so inclined are located in various other ALMA CASAguides.<br />
<br />
== Checking the weights and concatenating the data ==<br />
<br />
<figure id="7m_WT.png"><br />
[[File:12m_WT.png|200px|thumb|right|<caption> 12m weights.</caption>]]<br />
</figure><br />
<br />
<figure id="12m_WT.png"><br />
[[File:7m_WT_update.png|200px|thumb|right|<caption> 7m weights.</caption>]]<br />
</figure><br />
<br />
When combining data with disparate properties it is very important that the relative weights of each visibility be in the correct proportion to the other data according to the radiometer equation. Formally, the<br />
visibility weights should be proportional to 1/sigma<sup>2</sup> where sigma is the variance or rms noise of a given visibility.<br />
<br />
The rms noise in a single channel for a single visibility is:<br />
<br />
<math> <br />
\sigma_{ij} (Jy) =\frac{2k}{\eta_{q}\eta_{c}A_{eff}} <br />
</math><br />
<math> <br />
\sqrt{\frac{T_{sys,i} T_{sys,j}}{2\Delta\nu_{ch} t_{ij}}}<br />
</math><br />
<math> <br />
\times 10^{26},<br />
</math><br />
<br />
where:<br />
<br />
''k'' is Boltzmann's constant. <br />
<br />
''A<sub>eff</sub>'' is the effective antenna area which is equal to the aperture efficiency x the geometric area of the antenna. The aperture efficiency depends on the rms antenna surface accuracy. <br />
<br />
''&eta;<sub>q</sub>'' and ''&eta;<sub>c</sub>'' are the quantization and correlator efficiencies, respectively. These have values near 1 and will be ignored for the purposes of this casaguide, but see the ALMA Technical Handbook for more information.<br />
<br />
''T<sub>sys,i</sub>'' is the system temperature for antenna i, and ''T<sub>sys,j</sub>'' is the system temperature for antenna j<br />
<br />
''&Delta;&nu;<sub>ch</sub>'' is the channel frequency width.<br />
<br />
''t<sub>ij</sub>'' is the integration time per visibility. <br />
<br />
As of CASA 4.3.1, weights are initially scaled by 2&Delta;&nu;<sub>ch</sub>&Delta;t<sub>ij</sub>, and after the Tsys table applycal step of the calibration process, it further scales the weights by 1/[(Tsys(i) * Tsys(j)] as long as calwt=True. In the subsequent amplitude gain calibration table applycal step of the calibration, the weights are further scaled by a factor of [gain(i)<sup>2</sup> * gain(j)<sup>2</sup>] if calwt=True. This step up-weights data from the best performing antennas from the gain point of view, and importantly for data combination, makes the weights correctly proportional to the antenna size. <br />
<br />
In the calibration scripts for all executions of the 12m and 7m data, both applycal steps set calwt=True. To verify that the weights come out as expected, we plot the weights of the 7m and 12m data and measure their ratio to be, on average, 7m/12m ~ 0.055/0.3 ~ 0.18. Note that in the plots the points are colored by SPW, so there is only one 12m CO SPW but there are two 7m CO SPWs, and that no averaging can be turned on when plotting the weights. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf 7m_WT.png 12m_WT.png')<br />
plotms(vis='M100_12m_CO.ms',yaxis='wt',xaxis='uvdist',spw='0:200',<br />
coloraxis='spw',plotfile='12m_WT.png')<br />
#<br />
plotms(vis='M100_7m_CO.ms',yaxis='wt',xaxis='uvdist',spw='0~1:200',<br />
coloraxis='spw',plotfile='7m_WT.png')<br />
</source><br />
<br />
<figure id="combine_CO_WT.png"><br />
[[File:combine_CO_WT_update.png|200px|thumb|right|<caption> 7m and 12m weights after concatenation.</caption>]]<br />
</figure><br />
<br />
The two key things that are different between the 7m and 12m-array data are that the effective dish areas are different by (7/12)<sup>2</sup>, and the integration times are different by (10.1/6.05). Since the dish area and the integration time per visibility are in the denominator of the radiometer equation, and assuming the weight of an individual visibility is proportional to 1/sigma<sup>2</sup>, the ratio of the weights should be (7./12.)<sup>4</sup> x (10.1/6.05) = 0.19. This is very close to the value we measure for the ratio of the weights, particularly given that the 7m flux calibration relied on a source which changed substantially over the course of the six 7m-array observations. <br />
<br />
Now concatenate the two data sets and plot the concatenated weights to verify that they are as expected.<br />
<br />
<source lang="python"><br />
# In CASA<br />
# Concat and scale weights<br />
os.system('rm -rf M100_combine_CO.ms')<br />
concat(vis=['M100_12m_CO.ms','M100_7m_CO.ms'],<br />
concatvis='M100_combine_CO.ms')<br />
<br />
# In CASA<br />
os.system('rm -rf combine_CO_WT.png')<br />
plotms(vis='M100_combine_CO.ms',yaxis='wt',xaxis='uvdist',spw='0~2:200',<br />
coloraxis='spw',plotfile='combine_CO_WT.png')<br />
</source><br />
<br />
Here, we create more instructive plots of the combined data to check that things are in order. (''Let each plot finish before cutting and pasting next plot. If plotms gui disappears, exit CASA and restart.'')<br />
<br />
<figure id="M100_combine_vel.png"><br />
[[File:M100_combine_vel_update.png|200px|thumb|right|<caption> Amplitude as a function of velocity.</caption>]]<br />
</figure><br />
<br />
One way to assess the relative noise in the combined data is to plot amplitude as a function of uv-distance. Here, it's clear that the 7m data is noisier than the 12m data (note also that this plot is not shown):<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_uvdist.png')<br />
plotms(vis='M100_combine_CO.ms',yaxis='amp',xaxis='uvdist',spw='', avgscan=True,<br />
avgchannel='5000', coloraxis='spw',plotfile='M100_combine_uvdist.png') <br />
</source><br />
<br />
A fairer comparison of these data is achieved by isolating the brightest line channels in individual 12m and 7m data sets (i.e., not the concatenated data sets) and comparing only those channels in amplitude vs. uv-distance. Here the agreement is better, as it is less dominated by the scatter among the several 7m executions.<br />
<br />
To plot the CO line as a function of velocity (this plot takes a while):<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_vel.png')<br />
plotms(vis='M100_combine_CO.ms',yaxis='amp',xaxis='velocity',spw='', avgtime='1e8',avgscan=True,coloraxis='spw',avgchannel='5',<br />
transform=True,freqframe='LSRK',restfreq='115.271201800GHz', plotfile='M100_combine_vel.png')<br />
</source><br />
<br />
To see each spectral window independently in plotms, run the command again but remove the call to "plotfile" and add " iteraxis='spw' ".<br />
<br />
== Image The Combined Data ==<br />
<br />
The commands in this section enable the user to choose between interactive cleaning -- i.e., building your own cleaning mask -- and using a provided mask to do the cleaning. Imaging this data requires using the imagemode='mosaic' mode of clean. This mode automatically calculates the correct convolution of the primary beam response of the mosaic when different antenna dish diameters are present. '''NOTE:''' even if these data had only been comprised of a single pointing of 7m and 12m-array data, the imagemode='mosaic' mode would be needed to correctly image data with different antenna sizes.<br />
<br />
Any time it is necessary to enter a long series of commands, typing '''cpaste''' before the start of the series and '''--''' at the end of the series lets CASA know that there are more commands coming. This can be very helpful when needing to cut and paste a lot of lines at once. These commands are not explicitly included in any of the sets of commands below, but they can be applicable for any of them. <br />
<br />
=== Define Parameters ===<br />
<br />
<source lang="python"><br />
<br />
### Define clean parameters<br />
vis='M100_combine_CO.ms'<br />
prename='M100_combine_CO_cube'<br />
myimage=prename+'.image'<br />
imsize=[540,600]<br />
cell='0.5arcsec'<br />
minpb=0.2<br />
restfreq='115.271201800GHz'<br />
outframe='LSRK'<br />
spw='0~2:1500~2500'<br />
width='5km/s'<br />
start='1400km/s'<br />
nchan=70<br />
robust=0.5<br />
phasecenter='J2000 12h22m54.3 +15d48m46.7'<br />
scales=[0]<br />
smallscalebias=0.6<br />
thresh=0.04502129927277565<br />
<br />
</source><br />
<br />
=== Interactive Cleaning ===<br />
<br />
To create your own clean mask, run the following clean command with interactive=True. <br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf M100_combine_CO_cube*')<br />
clean(vis=vis,imagename='M100_combine_CO_cube',<br />
imagermode='mosaic',ftmachine='mosaic',minpb=minpb,<br />
imsize=imsize,cell=cell,spw=spw,<br />
weighting='briggs',robust=robust,phasecenter=phasecenter,<br />
mode='velocity',width=width,start=start,nchan=nchan,<br />
restfreq=restfreq,outframe=outframe,veltype='radio',<br />
multiscale=scales,smallscalebias=smallscalebias,<br />
interactive = True,<br />
niter = 10000,threshold = str(thresh) +'Jy/beam')<br />
<br />
</source><br />
<br />
The viewer will pop up and allow you to draw regions around emission (or absorption!) peaks that you believe to be real. The tools for drawing elliptical, rectangular, or polygonal regions are located at the top of the viewer window. You have the option to clean "all channels" or a "single channel" at a time; for M100, where the emission moves spatially from channel to channel, make sure to select the option to clean one channel at a time. Click through the channels with the channel iterator on the right in the viewer window to draw per channel clean boxes. Once you're satisfied with the boxes drawn in each channel, click the green arrow button to continue to the next major cycle of cleaning. Iterate through this process until the residual image returned looks like noise. You'll need several iterations of this process. <br />
<br />
Once you're satisfied that you have cleaned all of the emission that needs cleaning, hit the red X to finish the process. The outputs of clean include several useful image cubes: the cleaned image (.image), the final mask created from all of your rounds of cleaning (.mask), the map of all of the clean components used in the model (.model), the beam (.psf), and the residuals remaining after all of your rounds of clean (.residual).<br />
<br />
Another option: instead of starting your own mask from scratch, you could also use the provided mask as a starting place to do interactive cleaning. It is possible to "reuse" and change a mask anytime you create one. To use the provided mask, M100_combine_CO_provided.mask, as a starting place, use the following command with interactive=True. <br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf M100_combine_CO_cube*')<br />
clean(vis=vis,imagename='M100_combine_CO_cube',<br />
imagermode='mosaic',ftmachine='mosaic',minpb=minpb,<br />
imsize=imsize,cell=cell,spw=spw,<br />
weighting='briggs',robust=robust,phasecenter=phasecenter,<br />
mode='velocity',width=width,start=start,nchan=nchan,<br />
restfreq=restfreq,outframe=outframe,veltype='radio',<br />
multiscale=scales,smallscalebias=smallscalebias,<br />
mask = 'M100_combine_CO_provided.mask',<br />
interactive = True,<br />
niter = 10000,threshold = str(thresh) +'Jy/beam')<br />
<br />
</source><br />
<br />
=== Non-Interactive Cleaning ===<br />
<br />
If you would instead prefer to use the provided per channel mask, M100_combine_CO_provided.mask, you can find it in your directory. In this case, the mask file is specified and the clean command uses interactive=False.<br />
<br />
<source lang="python"><br />
<br />
os.system('rm -rf M100_combine_CO_cube*')<br />
clean(vis=vis,imagename='M100_combine_CO_cube',<br />
imagermode='mosaic',ftmachine='mosaic',minpb=minpb,<br />
imsize=imsize,cell=cell,spw=spw,<br />
weighting='briggs',robust=robust,phasecenter=phasecenter,<br />
mode='velocity',width=width,start=start,nchan=nchan,<br />
restfreq=restfreq,outframe=outframe,veltype='radio',<br />
multiscale=scales,smallscalebias=smallscalebias,<br />
mask = 'M100_combine_CO_provided.mask',<br />
interactive = False,<br />
niter = 10000,threshold = str(thresh) +'Jy/beam')<br />
<br />
</source><br />
<br />
== Image Analysis for the 7m+12m Data ==<br />
<br />
=== Moment Maps for 7m+12m CO (1-0) Cube ===<br />
<br />
Start by examining the final image cube. Determine the start and stopping channels for the line emission -- this will be used in the "chans" parameter of immoments.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('M100_combine_CO_cube.image')<br />
</source><br />
<br />
Next determine the rms noise per channel and use that to exclude pixels from the moment images. All images are shown in the gallery at the end of the following section.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myimage='M100_combine_CO_cube.image'<br />
chanstat=imstat(imagename=myimage,chans='4')<br />
rms1= chanstat['rms'][0]<br />
chanstat=imstat(imagename=myimage,chans='66')<br />
rms2= chanstat['rms'][0]<br />
rms=0.5*(rms1+rms2)<br />
print 'rms in a channel = '+str(rms) <br />
</source><br />
<br />
Next make the moment maps. For the integrated intensity: moment 0, a 2 sigma cut often considerably improves the appearance of the image with little effect on the integrated intensity as long as emission free channels are excluded. For higher order moments it is necessary to exclude all low S/N data. Typically 5-6 sigma for the higher moments works well. We also apply further masking based on the .flux image because the edges of the combined mosaic are especially noisy because the 7m mosaic is somewhat larger than the 12m mosaic as described above (see Figures 1 & 2). <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom0')<br />
immoments(imagename = 'M100_combine_CO_cube.image',<br />
moments = [0],<br />
axis = 'spectral',chans = '9~61',<br />
mask='M100_combine_CO_cube.flux>0.3',<br />
includepix = [rms*2,100.],<br />
outfile = 'M100_combine_CO_cube.image.mom0')<br />
<br />
os.system('rm -rf M100_combine_CO_cube.image.mom1')<br />
immoments(imagename = 'M100_combine_CO_cube.image',<br />
moments = [1],<br />
axis = 'spectral',chans = '9~61',<br />
mask='M100_combine_CO_cube.flux>0.3',<br />
includepix = [rms*5.5,100.],<br />
outfile = 'M100_combine_CO_cube.image.mom1')<br />
<br />
</source><br />
<br />
Now we can make some figures showing the moment maps:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom*.png')<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom0',<br />
'range': [-0.3,25.],'scaling': -1.3,'colorwedge': T}],<br />
zoom={'blc': [48,46],'trc': [488,569]},<br />
out='M100_combine_CO_cube.image.mom0.png')<br />
<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom1',<br />
'range': [1440,1695],'colorwedge': T}],<br />
zoom={'blc': [48,46],'trc': [488,569]}, <br />
out='M100_combine_CO_cube.image.mom1.png')<br />
<br />
</source><br />
<br />
If you plan to use your moment 0 image to make measurements, it needs to be primary beam corrected first. First we need to subimage the .flux cube to extract a single plane that can be used to primary beam correct the moment 0 image.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.flux.1ch')<br />
imsubimage(imagename='M100_combine_CO_cube.flux',<br />
outfile='M100_combine_CO_cube.flux.1ch',<br />
chans='35')<br />
</source><br />
<br />
Next, primary beam correct the moment 0 image. This is the version that would be used for measurements, though the uncorrected one can be useful for figures. The difference is clear in the images seen below in the following section.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom0.pbcor')<br />
immath(imagename=['M100_combine_CO_cube.image.mom0', \<br />
'M100_combine_CO_cube.flux.1ch'],<br />
expr='IM0/IM1',<br />
outfile='M100_combine_CO_cube.image.mom0.pbcor')<br />
</source><br />
<br />
Have a look at the difference the primary beam correction makes. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom0',<br />
'range': [-0.3,25.],'scaling': -1.3},<br />
{'file': 'M100_combine_CO_cube.image.mom0.pbcor',<br />
'range': [-0.3,25.],'scaling': -1.3}],<br />
zoom={'blc': [48,46],'trc': [488,569]})<br />
</source><br />
<br />
With the viewer open, you can flip back and forth between the images to compare them. Next, make a figure.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf M100_combine_CO_cube.image.mom0.pbcor.png')<br />
imview (raster=[{'file': 'M100_combine_CO_cube.image.mom0.pbcor',<br />
'range': [-0.3,25.],'scaling': -1.3,'colorwedge': T}],<br />
zoom={'blc': [48,46],'trc': [488,569]},<br />
out='M100_combine_CO_cube.image.mom0.pbcor.png')<br />
<br />
</source><br />
<br />
=== Comparison with 7m, 12m Moment Maps ===<br />
<br />
Below the moment maps from the 7m-only and the 12m-only data are shown for comparison. The moment maps were made using clean masks drawn by hand. Details on the creation of these images (masking, thresholding, and the number of iterations of clean) can be found within the 12m and 7m imaging scripts available with the downloaded package. The range and scaling for the 12m-only figures are the same as that used for the 7m+12m figures for ease of comparison.<br />
<br />
As expected, the 7m+12m image shows considerably more extended emission than the 12m-only data and finer detail than the 7m-only data. For comparison, the 7m+12m synthesized beam is 3.82"x2.55", while the 12m-only beam is 3.46"x2.37" and the 7m-only beam is 12.72"x10.12".<br />
<br />
<gallery widths=300px heights=300px><br />
File:12m.png | Moment 0 for 12m data alone (no primary beam correction).<br />
File:7m_mom0.png | Moment 0 for 7m data alone (no primary beam correction).<br />
File:combined.png | Moment 0 for 12m+7m data (no primary beam correction).<br />
File:combine_pbcor.png | Moment 0 for 12m+7m data with primary beam correction.<br />
</gallery><br />
<br />
<gallery widths=300px heights=300px><br />
File:12m_mom1.png | Moment 1 for 12m data alone.<br />
File:7m_mom1.png | Moment 1 for 7m data alone.<br />
File:combine_mom1.png | Moment 1 for 12m+7m data.<br />
</gallery><br />
<br />
=== Convert 7m+12m Images to Fits Format ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf *.fits')<br />
exportfits(imagename='M100_combine_CO_cube.image',fitsimage='M100_combine_CO_cube.image.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.flux',fitsimage='M100_combine_CO_cube.flux.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.image.mom0',fitsimage='M100_combine_CO_cube.image.mom0.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.image.mom0.pbcor',fitsimage='M100_combine_CO_cube.image.mom0.pbcor.fits')<br />
<br />
exportfits(imagename='M100_combine_CO_cube.image.mom1',fitsimage='M100_combine_CO_cube.image.mom1.fits')<br />
<br />
</source><br />
<br />
= Feathering the Total Power and 7m+12m Interferometric Images =<br />
<br />
In this section the interferometric (7m+12m) image produced above is combined with the Total Power (single dish) image.<br />
The "feather" algorithm is employed, in which the two images are combined in the spatial frequency domain, i.e.,<br />
the low and high spatial frequency components are predominantly taken from the TP and interferometric images, respectively.<br />
<br />
== Prepare Images for Feathering ==<br />
<br />
Regrid the TP image to match the shape of the 7m+12m image using the task {{imregrid}}.<br />
The TP image is resampled onto the same grid as that of the "template" 7m+12m image along the first two axes of the cube (i.e., RA and Dec; it is not necessary to regrid the velocity axis, since the axis is already common to the both images).<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_TP_CO_cube.regrid')<br />
imregrid(imagename='M100_TP_CO_cube.bl.image',<br />
template='M100_combine_CO_cube.image',<br />
axes=[0, 1],<br />
output='M100_TP_CO_cube.regrid')<br />
</source><br />
<br />
Now we trim the 7m+12m and (regridded) TP images, in order to exclude the regions masked by the {{clean}} task with minpb=0.2 and/or noisy edge regions in the TP image. The {{viewer}} task can be used to determine the trimming box. Here we use (x, y) = (48,46) and (488,569) [pixels] as the bottom-left and top-right corners, respectively, and set these values to the "box" parameter of the {{imsubimage}} task.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim')<br />
imsubimage(imagename='M100_TP_CO_cube.regrid',<br />
outfile='M100_TP_CO_cube.regrid.subim',<br />
box='48,46,488,569')<br />
os.system('rm -rf M100_combine_CO_cube.image.subim')<br />
imsubimage(imagename='M100_combine_CO_cube.image',<br />
outfile='M100_combine_CO_cube.image.subim',<br />
box='48,46,488,569')<br />
</source><br />
<br />
While the 7m+12m image (before the primary-beam correction) has non-uniform primary beam response (i.e., lower response in the outskirts of the mosaic field), the TP image does not have such non-uniformity.<br />
In order to feather the TP and 7m+12m images together, they should have the common response on the sky.<br />
Hence we need to multiply the TP image by the 7m+12m primary beam response before proceeding.<br />
To do this, create the subimage of the 7m+12m response,<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_combine_CO_cube.flux.subim')<br />
imsubimage(imagename='M100_combine_CO_cube.flux',<br />
outfile='M100_combine_CO_cube.flux.subim',<br />
box='48,46,488,569')<br />
</source><br />
<br />
then multiply it and the TP image using the task {{immath}}.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.depb')<br />
immath(imagename=['M100_TP_CO_cube.regrid.subim',<br />
'M100_combine_CO_cube.flux.subim'],<br />
expr='IM0*IM1',<br />
outfile='M100_TP_CO_cube.regrid.subim.depb')<br />
</source><br />
<br />
As a result, the feathered image will have the same response as that of the 7m+12m image.<br />
The primary-beam correction can be done after the feathering process (see below).<br />
<br />
== Feather TP Cube with 7m+12m Cube ==<br />
<br />
Now we are ready to execute the {{feather}} task to combine the TP and 7m+12m images.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_Feather_CO.image')<br />
feather(imagename='M100_Feather_CO.image',<br />
highres='M100_combine_CO_cube.image.subim',<br />
lowres='M100_TP_CO_cube.regrid.subim.depb')<br />
</source><br />
<br />
The task produces the combined image in the following way:<br />
* Convert the input images specified by the "highres" and "lowres" parameters onto the spatial frequency plane.<br />
* Combine them on the spatial frequency plane. The weighting is determined by the beam sizes/shapes of the input images.<br />
* Convert it back to the image plane.<br />
Please refer to the online help and documents for the details.<br />
<br />
== Make Moment Maps of the Feathered Images ==<br />
<br />
We will use the same technique as the [[#Moment_Maps_for_7m.2B12m_CO_.281-0.29_Cube|7m+12m image analysis above]] to make moment maps.<br />
<br />
First (but optionally; this is solely for comparison to the feathered images and not needed to create the final feathered images), make moment maps for the (regridded) TP image.<br />
<br />
<source lang="python"><br />
#In CASA<br />
myimage = 'M100_TP_CO_cube.regrid.subim'<br />
chanstat = imstat(imagename=myimage,chans='4')<br />
rms1 = chanstat['rms'][0]<br />
chanstat = imstat(imagename=myimage,chans='66')<br />
rms2 = chanstat['rms'][0]<br />
rms = 0.5*(rms1+rms2) <br />
<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.mom0')<br />
immoments(imagename='M100_TP_CO_cube.regrid.subim',<br />
moments=[0],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*2., 50],<br />
outfile='M100_TP_CO_cube.regrid.subim.mom0')<br />
<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.mom1')<br />
immoments(imagename='M100_TP_CO_cube.regrid.subim',<br />
moments=[1],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*5.5, 50],<br />
outfile='M100_TP_CO_cube.regrid.subim.mom1')<br />
<br />
os.system('rm -rf M100_TP_CO_cube.regrid.subim.mom*.png')<br />
imview(raster=[{'file': 'M100_TP_CO_cube.regrid.subim.mom0',<br />
'range': [0., 1080.],<br />
'scaling': -1.3,<br />
'colorwedge': T}],<br />
out='M100_TP_CO_cube.regrid.subim.mom0.png')<br />
<br />
imview(raster=[{'file': 'M100_TP_CO_cube.regrid.subim.mom1',<br />
'range': [1440, 1695],<br />
'colorwedge': T}], <br />
out='M100_TP_CO_cube.regrid.subim.mom1.png')<br />
</source><br />
<br />
Then make moment maps for the feathered image.<br />
<br />
<source lang="python"><br />
#In CASA<br />
myimage = 'M100_Feather_CO.image'<br />
chanstat = imstat(imagename=myimage,chans='4')<br />
rms1 = chanstat['rms'][0]<br />
chanstat = imstat(imagename=myimage,chans='66')<br />
rms2 = chanstat['rms'][0]<br />
rms = 0.5*(rms1+rms2) <br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom0')<br />
immoments(imagename='M100_Feather_CO.image',<br />
moments=[0],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*2., 50],<br />
outfile='M100_Feather_CO.image.mom0')<br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom1')<br />
immoments(imagename='M100_Feather_CO.image',<br />
moments=[1],<br />
axis='spectral',<br />
chans='10~61',<br />
includepix=[rms*5.5, 50],<br />
outfile='M100_Feather_CO.image.mom1')<br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom*.png')<br />
imview(raster=[{'file': 'M100_Feather_CO.image.mom0',<br />
'range': [-0.3, 25.],<br />
'scaling': -1.3,<br />
'colorwedge': T}],<br />
out='M100_Feather_CO.image.mom0.png')<br />
<br />
imview(raster=[{'file': 'M100_Feather_CO.image.mom1',<br />
'range': [1440, 1695],<br />
'colorwedge': T}], <br />
out='M100_Feather_CO.image.mom1.png')<br />
</source><br />
<br />
=== Correct the Primary Beam Response ===<br />
<br />
Apply the primary beam response to the feathered image using the task {{immath}},<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_Feather_CO.image.pbcor')<br />
immath(imagename=['M100_Feather_CO.image',<br />
'M100_combine_CO_cube.flux.subim'],<br />
expr='IM0/IM1',<br />
outfile='M100_Feather_CO.image.pbcor')<br />
</source><br />
<br />
and also to the moment 0 image.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_combine_CO_cube.flux.1ch.subim')<br />
imsubimage(imagename='M100_combine_CO_cube.flux.subim',<br />
outfile='M100_combine_CO_cube.flux.1ch.subim',<br />
chans='35')<br />
<br />
os.system('rm -rf M100_Feather_CO.image.mom0.pbcor')<br />
immath(imagename=['M100_Feather_CO.image.mom0',<br />
'M100_combine_CO_cube.flux.1ch.subim'],<br />
expr='IM0/IM1',<br />
outfile='M100_Feather_CO.image.mom0.pbcor')<br />
</source><br />
<br />
Save the primary-beam corrected moment 0 image to a PNG file.<br />
<br />
<source lang="python"><br />
#In CASA<br />
os.system('rm -rf M100_Feather_CO.image.mom0.pbcor.png')<br />
imview(raster=[{'file': 'M100_Feather_CO.image.mom0.pbcor',<br />
'range': [-0.3, 25.],<br />
'scaling': -1.3,<br />
'colorwedge': T}],<br />
out='M100_Feather_CO.image.mom0.pbcor.png')<br />
</source><br />
<br />
=== Compare the Various Images ===<br />
<br />
Now we compare all the images:<br />
<br />
<gallery perrow=3 widths=300px heights=300px><br />
File:12m_pbcor.png | Primary beam corrected moment 0 for the 12m data.<br />
File:7m_pbcor.png | Primary beam corrected moment 0 for the 7m data.<br />
File:TP_CO_cube_Jy.regrid.subim.mom0.png | Moment 0 for the TP data.<br />
File:combine_pbcor.png | Primary beam corrected moment 0 for 7m+12m data.<br />
File:M100_Feather_CO.mom0.pbcor.png | Primary beam corrected moment 0 for TP+7m+12m data.<br />
</gallery><br />
<br />
<gallery perrow=3 widths=300px heights=300px><br />
File:12m_mom1.png | Moment 1 for 12m data.<br />
File:7m_mom1.png | Moment 1 for 7m data.<br />
File:TP_CO_cube_Jy.regrid.subim.mom1.png | Moment 1 for the TP data.<br />
File:combine_mom1.png | Moment 1 for 7m+12m data.<br />
File:M100_Feather_CO.mom1.png | Moment 1 for TP+7m+12m data.<br />
</gallery><br />
<br />
You can see that more extended emission is recovered by adding the TP data to the interferometric data.<br />
<br />
For quantitative comparison, we measure the total line fluxes of the various images.<br />
The task {{imstat}} can be used to do this.<br />
For example, for the subimage of the 7m+12m image,<br />
<br />
<source lang="python"><br />
#In CASA<br />
imstat('M100_combine_CO_cube.image.subim')<br />
</source><br />
<br />
yields the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '12:23:01.990, +15.46.39.692, I, 1.14733e+11Hz',<br />
'flux': array([ 1031.66933033]),<br />
'max': array([ 0.67689651]),<br />
'maxpos': array([195, 312, 0, 49], dtype=int32),<br />
'maxposf': '12:22:55.235, +15.49.15.700, I, 1.14639e+11Hz',<br />
'mean': array([ 0.00060066]),<br />
'medabsdevmed': array([ 0.00857783]),<br />
'median': array([-0.00013253]),<br />
'min': array([-0.0872678]),<br />
'minpos': array([273, 316, 0, 25], dtype=int32),<br />
'minposf': '12:22:52.533, +15.49.17.700, I, 1.14685e+11Hz',<br />
'npts': array([ 15434710.]),<br />
'q1': array([-0.00867673]),<br />
'q3': array([ 0.00847944]),<br />
'quartile': array([ 0.01715617]),<br />
'rms': array([ 0.01700558]),<br />
'sigma': array([ 0.01699497]),<br />
'sum': array([ 9270.95406483]),<br />
'sumsq': array([ 4463.55839316]),<br />
'trc': array([440, 523, 0, 69], dtype=int32),<br />
'trcf': '12:22:46.746, +15.51.01.192, I, 1.146e+11Hz'}<br />
<br />
</pre><br />
<br />
The 'flux' value in the result is the total integrated line flux in Jy km/s. Note that these values are the ones obtained using the provided mask file and interactive=False cleaning. If you adjusted the masking of the 12m+7m cleaning run, your results may vary here. <br />
<br />
Similarly, the total line fluxes of the TP image (after multiplying the 7m+12m primary beam response), feathered image, and feathered image after the primary-beam correction are<br />
<br />
<source lang="python"><br />
#In CASA<br />
imstat('M100_TP_CO_cube.regrid.subim.depb')['flux']<br />
imstat('M100_Feather_CO.image')['flux']<br />
imstat('M100_Feather_CO.image.pbcor')['flux']<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
array([ 2934.61181467])<br />
array([ 2931.0992893])<br />
array([ 3402.22025601])<br />
</pre><br />
<br />
We see the followings from these values:<br />
* The flux recovered by the 7m+12m observations is about a third of the total flux (998/2931).<br />
* The feathering process preserves the flux of the TP data.<br />
* The flux of the primary-beam corrected feathered image is consistent with the values from the literature (2972 +/- 319 Jy km/s from the BIMA SONG; Helfer et al. 2003).<br />
<br />
{{Checked 4.5.2}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=M100_Band3_SingleDish_4.5&diff=21241M100 Band3 SingleDish 4.52017-04-04T13:34:00Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
<br />
*'''This guide requires CASA 4.5 and assumes that you have downloaded M100_Band3_TP_UncalibratedData.tgz as described in [[M100_Band3#Obtaining_the_Data]]'''<br />
<br />
*'''The processes described below WILL NOT OPERATE in CASA versions earlier than 4.5'''<br />
<br />
*'''Details of the ALMA observations are described at [[M100_Band3]]<br />
<br />
*'''This portion of the guide covers calibration and imaging starting from the raw visibility data.'''<br />
<br />
<br />
= Overview =<br />
<br />
This portion of CASA Guide will cover the data reduction of the Total Power (TP) array observations of M100. The objective is to generate from the TP dataset, a position-position-velocity cube suitable for merging with 7m and 12m datasets.<br />
<br />
The data consist of "amplitude calibrator" datasets (containing observational data of the quasar 3C279) and "science" datasets containing data for the science target M100. To be clear - the observations of 3C279 and M100 both follow the same general process - i.e. they are themselves calibrated with frequent observations of ''blank sky'' - the so-called 'OFF', which is used to determine the System temperature as a function of frequency, and form a ''referenced'' bandpass, in units of Antenna Temperature (Ta*) [K].<br />
<br />
Ultimately the quasar data are compared with recent flux measurements (in Jy/beam), obtained from archived 12m data, to determine the scaling factor between Ta* and Jy/beam, and that scaling factor is then applied to the science data, to bootstrap to Jy/beam.<br />
<br />
The combination of the resultant image with the interferometric (12-m array and 7-m array) data is explained in a separate page, valid for both CASA versions 4.3 and 4.5 [[M100_Band3_Combine_4.3]].<br />
<br />
This guide is designed for CASA 4.5.0.<br />
<br />
----<br />
<br />
==Confirm Your Version of CASA==<br />
This guide has been written for CASA release 4.5.0.,Please confirm your version before proceeding.<br />
The value returned from ''casadef.casa_version'' should be 4.5.0. If not, please obtain at least version 4.5.0 (or later), from [http://casa.nrao.edu/current_casa.shtml]<br />
<source lang="python"><br />
# In CASA<br />
casadef.casa_version<br />
</source><br />
<br />
== Summary of Datasets ==<br />
<br />
The observations were made on the 1st, 5th, 7th, and 17th July 2014, using two or three 12-m antennas and the ACA correlator.<br />
The table below indicates the ID's of the Execution Blocks, their start and end times, and the antennas in the array.<br />
There are nine science datasets (i.e., two or three per day).<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
#Science<br />
uid___A002_X85c183_X36f Observed from 2014-07-01T21:51:26.2 to 2014-07-01T22:40:28.4 (UTC) DA61, PM03, PM04<br />
uid___A002_X85c183_X60b Observed from 2014-07-01T22:43:50.0 to 2014-07-01T23:32:39.6 (UTC) DA61, PM03, PM04<br />
uid___A002_X8602fa_X2ab Observed from 2014-07-05T23:58:03.6 to 2014-07-06T00:46:52.0 (UTC) PM02, PM03, PM04<br />
uid___A002_X8602fa_X577 Observed from 2014-07-06T00:55:17.8 to 2014-07-06T01:44:07.3 (UTC) PM02, PM03, PM04<br />
uid___A002_X864236_X2d4 Observed from 2014-07-07T23:03:48.1 to 2014-07-07T23:53:47.9 (UTC) PM03, PM04<br />
uid___A002_X864236_X693 Observed from 2014-07-07T23:56:09.6 to 2014-07-08T00:46:07.1 (UTC) PM03, PM04<br />
uid___A002_X86fcfa_Xd9 Observed from 2014-07-17T20:55:15.5 to 2014-07-17T21:44:06.1 (UTC) DV10, PM03, PM04<br />
uid___A002_X86fcfa_X664 Observed from 2014-07-17T22:24:17.3 to 2014-07-17T23:13:08.0 (UTC) DV10, PM03, PM04<br />
uid___A002_X86fcfa_X96c Observed from 2014-07-17T23:23:37.0 to 2014-07-18T00:12:25.3 (UTC) DV10, PM03, PM04<br />
</pre><br />
<br />
Similarly, the concomitant ''Calibration'' datasets (used to convert from Antenna temperature units into Jy/beam units, for combination), are:<br />
<pre style="background-color: #E0FFFF;"><br />
#Amplitude Calibrator<br />
uid___A002_X85c183_X895 Observed from 2014-07-01T23:35:23.1 to 2014-07-02T00:07:54.6 (UTC) DA61, PM03, PM04<br />
uid___A002_X8602fa_Xc3 Observed from 2014-07-05T23:21:25.6 to 2014-07-05T23:53:41.0 (UTC) PM02, PM03, PM04<br />
uid___A002_X864236_Xe1 Observed from 2014-07-07T22:27:35.4 to 2014-07-07T23:01:05.7 (UTC) PM03, PM04<br />
uid___A002_X86fcfa_X3ae Observed from 2014-07-17T21:48:30.0 to 2014-07-17T22:20:52.2 (UTC) DV10, PM03, PM04<br />
</pre><br />
<br />
= Script Calibration =<br />
The scripts listed below process all the single-dish science and calibrator data, using a few loops. <br />
<br />
# The science data are processed with - [[media:M100.casa4p5.calib.py|M100.casa4p5.calib.py]] <br />
# The calibrator (i.e. quasar) data are processed with - media:M100.casa4p5.calib.calib.py|M100.casa4p5.calib.calib.py<br />
#* (This step is to be confirmed. For the interim, the relevant calibration parameters are hard-coded into the calibration script)<br />
# and the (calibrated) science data are imaged with [[media:M100.casa4p5.imaging.py|M100.casa4p5.imaging.py]]<br />
<br />
Executing each of these scripts in order, will be sufficient to calibrate and image the science data (although the calibrator processing script can be omitted, as the relevant parameters are actually already explicitly written into the script).<br />
<br />
They can be invoked from the command line using the execfile command.<br />
<source lang="python"><br />
# In CASA<br />
execfile('M100.casa4p5.calib.py')<br />
</source><br />
<br />
= Manual Calibration =<br />
<br />
By way of description, and as a means to introduce and demonstrate some of the interactive and diagnostic tools here we describe in more detail, the steps taken by the scripts - although in this case we demonstrate the process for only one of the ASDM datasets. In the ''Imaging'' section, we assume all the ASDMs are appropriately reduced either by the manual process, or by using the script. <br />
<br />
The entire process takes less than 30 minutes.<br />
<br />
There are three basic steps to the Calibration of the Science data:<br />
# Import, inspection and flagging<br />
# Calibration<br />
#* Sky and bandpass calibration (i.e. Tsys and frequency sampling function)<br />
#* Adjustment for Correlator non-linearity<br />
#* Conversion to Jy/beam<br />
# Imaging<br />
<br />
=== Import "Analysis Utilities" ===<br />
<br />
The [[Analysis_Utilities]] package will be used most critically for the imaging processes. While it is not necessary for completing the calibration stages,it is used to check data quality, and should be loaded.<br />
<br />
Import the package from https://casaguides.nrao.edu/index.php/Analysis_Utilities, and apply the class therein.<br />
<source lang="python"><br />
# In CASA<br />
import analysisUtils as aU<br />
</source><br />
<br />
<br />
== Import, inspection and flagging ==<br />
<br />
=== Import ===<br />
The first thing to do is to convert the dataset into the CASA Measurement Set (MS) format. The raw data have been provided to you in the ASDM (ALMA Science Data Model), which is the native format of the data produced by the observatory but cannot be processed by CASA. The conversion from ASDM to MS is done with the task {{importasdm}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
importasdm('uid___A002_X85c183_X36f',<br />
asis='Antenna Station Receiver Source CalAtmosphere CalWVR', bdfflags=False)<br />
os.system(os.environ['CASAPATH'].split()[0] + '/bdflags2MS -f "COR DELA INT MIS SIG SYN TFB WVR ZER" ' + fname+' '+msname)<br />
</source><br />
<br />
The converted dataset (with a suffix ".ms") is created with data flags embedded in the ASDM dataset (so-called "BDF flags") necessary for single-dish data.<br />
<br />
'''Note:''' The above code should be used for cycle 2 data, or earlier. Cycle 3+ data can simply use:<br />
<br />
<source lang="python"><br />
# In CASA<br />
importasdm('uid___A002_X85c183_X36f',<br />
asis='Antenna Station Receiver Source CalAtmosphere CalWVR', bdfflags=True)<br />
</source><br />
<br />
=== Inspection - listobs ===<br />
After import, the usual first step is then to get some basic information about the data.<br />
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 />
listobs(vis='uid___A002_X85c183_X36f.ms',<br />
listfile='uid___A002_X85c183_X36f.ms.listobs')<br />
</source><br />
<br />
The output will be written in a file named uid___A002_X85c183_X36f.ms.listobs which you can (and should) view at your leisure.<br />
{{listobs}} displays information about the targets, dates, frequencies, etc. Below is an excerpt from listobs for uid___A002_X85c183_X36f:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 none J1215+1654 12:15:03.979140 +16.54.37.95680 J2000 0 14661<br />
1 none M100 12:22:54.360000 +15.48.50.60000 J2000 1 61653<br />
Spectral Windows: (25 unique spectral windows and 2 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_03#BB_1#SW-01#FULL_RES 124 TOPO 91955.512 -15625.000 1937500.0 90994.5750 1 XX YY<br />
2 ALMA_RB_03#BB_1#SW-01#CH_AVG 1 TOPO 90978.950 1734375.000 1734375.0 90978.9500 1 XX YY<br />
3 ALMA_RB_03#BB_2#SW-01#FULL_RES 124 TOPO 93893.012 -15625.000 1937500.0 92932.0750 2 XX YY<br />
4 ALMA_RB_03#BB_2#SW-01#CH_AVG 1 TOPO 92924.262 1937500.000 1937500.0 92924.2625 2 XX YY<br />
5 ALMA_RB_03#BB_3#SW-01#FULL_RES 124 TOPO 102033.637 15625.000 1937500.0 102994.5750 3 XX YY<br />
6 ALMA_RB_03#BB_3#SW-01#CH_AVG 1 TOPO 102986.762 1937500.000 1937500.0 102986.7625 3 XX YY<br />
7 ALMA_RB_03#BB_4#SW-01#FULL_RES 124 TOPO 104033.637 15625.000 1937500.0 104994.5750 4 XX YY<br />
8 ALMA_RB_03#BB_4#SW-01#CH_AVG 1 TOPO 104986.762 1937500.000 1937500.0 104986.7625 4 XX YY<br />
9 ALMA_RB_03#BB_1#SW-01#FULL_RES 128 TOPO 101942.187 -15625.000 2000000.0 100950.0000 1 XX YY<br />
10 ALMA_RB_03#BB_1#SW-01#CH_AVG 1 TOPO 100926.562 1781250.000 1781250.0 100926.5625 1 XX YY<br />
11 ALMA_RB_03#BB_2#SW-01#FULL_RES 128 TOPO 103757.337 -15625.000 2000000.0 102765.1500 2 XX YY<br />
12 ALMA_RB_03#BB_2#SW-01#CH_AVG 1 TOPO 102741.712 1781250.000 1781250.0 102741.7125 2 XX YY<br />
13 ALMA_RB_03#BB_3#SW-01#FULL_RES 128 TOPO 111814.962 15625.000 2000000.0 112807.1500 3 XX YY<br />
14 ALMA_RB_03#BB_3#SW-01#CH_AVG 1 TOPO 112783.712 1781250.000 1781250.0 112783.7125 3 XX YY<br />
15 ALMA_RB_03#BB_4#SW-01#FULL_RES 128 TOPO 113689.962 15625.000 2000000.0 114682.1500 4 XX YY<br />
16 ALMA_RB_03#BB_4#SW-01#CH_AVG 1 TOPO 114658.712 1781250.000 1781250.0 114658.7125 4 XX YY<br />
17 ALMA_RB_03#BB_1#SW-01#FULL_RES 4080 TOPO 101945.850 -488.281 1992187.5 100950.0000 1 XX YY<br />
18 ALMA_RB_03#BB_1#SW-01#CH_AVG 1 TOPO 100949.756 1992187.500 1992187.5 100949.7559 1 XX YY<br />
19 ALMA_RB_03#BB_2#SW-01#FULL_RES 4080 TOPO 103761.000 -488.281 1992187.5 102765.1500 2 XX YY<br />
20 ALMA_RB_03#BB_2#SW-01#CH_AVG 1 TOPO 102764.906 1992187.500 1992187.5 102764.9059 2 XX YY<br />
21 ALMA_RB_03#BB_3#SW-01#FULL_RES 4080 TOPO 111811.300 488.281 1992187.5 112807.1500 3 XX YY<br />
22 ALMA_RB_03#BB_3#SW-01#CH_AVG 1 TOPO 112806.906 1992187.500 1992187.5 112806.9059 3 XX YY<br />
23 ALMA_RB_03#BB_4#SW-01#FULL_RES 4080 TOPO 113686.300 488.281 1992187.5 114682.1500 4 XX YY<br />
24 ALMA_RB_03#BB_4#SW-01#CH_AVG 1 TOPO 114681.906 1992187.500 1992187.5 114681.9059 4 XX YY<br />
Sources: 48<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1215+1654 0 - - <br />
0 J1215+1654 25 - - <br />
0 J1215+1654 26 - - <br />
0 J1215+1654 27 - - <br />
0 J1215+1654 1 - - <br />
0 J1215+1654 2 - - <br />
0 J1215+1654 3 - - <br />
0 J1215+1654 4 - - <br />
0 J1215+1654 5 - - <br />
0 J1215+1654 6 - - <br />
0 J1215+1654 7 - - <br />
0 J1215+1654 8 - - <br />
0 J1215+1654 9 - - <br />
0 J1215+1654 10 - - <br />
0 J1215+1654 11 - - <br />
0 J1215+1654 12 - - <br />
0 J1215+1654 13 - - <br />
0 J1215+1654 14 - - <br />
0 J1215+1654 15 - - <br />
0 J1215+1654 16 - - <br />
0 J1215+1654 17 100950 0 <br />
0 J1215+1654 18 100950 0 <br />
0 J1215+1654 19 102794.1 0 <br />
0 J1215+1654 20 102794.1 0 <br />
0 J1215+1654 21 112794.1 0 <br />
0 J1215+1654 22 112794.1 0 <br />
0 J1215+1654 23 114669.1 0 <br />
0 J1215+1654 24 114669.1 0 <br />
1 M100 0 - - <br />
1 M100 25 - - <br />
1 M100 26 - - <br />
1 M100 27 - - <br />
1 M100 9 - - <br />
1 M100 10 - - <br />
1 M100 11 - - <br />
1 M100 12 - - <br />
1 M100 13 - - <br />
1 M100 14 - - <br />
1 M100 15 - - <br />
1 M100 16 - - <br />
1 M100 17 100950 0 <br />
1 M100 18 100950 0 <br />
1 M100 19 102794.1 0 <br />
1 M100 20 102794.1 0 <br />
1 M100 21 112794.1 0 <br />
1 M100 22 112794.1 0 <br />
1 M100 23 114669.1 0 <br />
1 M100 24 114669.1 0 <br />
Antennas: 3:<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 DA61 A075 12.0 m -067.45.17.9 -22.53.21.4 -4.5609 -499.7012 23.0322 2225072.419944 -5440148.858968 -2481499.171703<br />
1 PM03 T701 12.0 m -067.45.18.8 -22.53.22.2 -29.1265 -522.7875 22.2052 2225045.995589 -5440149.141967 -2481520.118569<br />
2 PM04 T703 12.0 m -067.45.16.2 -22.53.23.9 42.8797 -575.6910 21.7763 2225104.700870 -5440102.471978 -2481568.689518<br />
</pre><br />
<br />
From this output you can for example see the followings.<br />
<br />
* From "Data records" section (not shown here): The execution consists of 15 scans with various scan intents.<br />
** Scans 1 and 2 are pointing and sideband gain ratio calibrations (done interferometrically), which need to be done prior to observing the target, on the quasar J1215+1654.<br />
** Scans 3 and 4 are interferometric delay and system noise temperature (Tsys) measurements also on J1215+1654 (they are in principle unnecessary; just a hack to make things happen on the telescope control software).<br />
** Scans 6, 7, 9, 10, 12, 13, and 15, whose scan intents contain "OBSERVE_TARGET", are for raster mapping of the target M100. The associated spectral window (SPW) ID's are 0 and 17-24.<br />
** Scans 5, 8, 11, and 14 with scan intents "CALIBRATE_ATMOSPHERE" are Tsys measurements for M100. The SPW ID's for Tsys scans are 0 and 9-16.<br />
* From "Spectral Windows" section:<br />
** SPW 0 contains the Water Vapor Radiometer (WVR) data, which are taken for all scans, but which are not used here.<br />
** SPW's 1, 3, 5, and 7 are placed on standard continuum frequencies and are used for the pointing scan only.<br />
** SPW's 9, 11, 13, and 15 cover the same frequency range as the science SPW's (see the next bullet) and are used to measure the Tsys used for calibration. They have 128 spectral channels (15.6 MHz spacing) in 2000 MHz bandwidth.<br />
** SPW's 17, 19, 21, and 23 cover the frequency ranges used for the actual science observations. They have 4080 spectral channels (488 kHz spacing) in 1992 MHz bandwidth. Hereafter these SPW's are referred to as "science" SPW's. The target line, CO J=1-0, is placed in SPW 23, the corresponding Tsys is taken from SPW 15.<br />
** The remaining, even-number SPW's contain channel-averages of the actually used SPW's (e.g., SPW 24 corresponds to SPW 23 averaged into one channel).<br />
* From "Antennas" section: Three 12-m antennas (DA61, PM03, and PM04) were used for the observations.<br />
<br />
=== Inspection - scanpattern ===<br />
The scan pattern of the raster mapping can be visualized by issuing the following command (after import of Analysis Utils - see the top of this page for information).<br />
A plot will be shown in a window and also saved as a PNG file uid___A002_X85c183_X36f.ms.sampling.png.<br />
<br />
<figure id="X36f.TPSampling.png"><br />
[[File:X36f.TPSampling.png|200px|thumb|right|<caption>The scan pattern of the raster mapping for uid___A002_X85c183_X36f.</caption>]]<br />
</figure><br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
aU.getTPSampling(vis='uid___A002_X85c183_X36f.ms',<br />
showplot=True,<br />
plotfile='uid___A002_X85c183_X36f.ms.sampling.png')<br />
</source><br />
<br />
=== Inspection - System Noise Temperature ===<br />
Let's start by checking the Tsys.<br />
We use the task {{gencal}} to extract the Tsys into a CASA calibration table. This table is only used for inspection of Tsys quality, and not in further processing.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='uid___A002_X85c183_X36f.ms',<br />
caltable='uid___A002_X85c183_X36f.ms.tsys',<br />
caltype='tsys')<br />
</source><br />
<br />
The generated Tsys calibration table can be plotted using the task {{plotbandpass}}. The generated plots are saved in the directories<br />
uid___A002_X85c183_X36f.ms.tsys.plots.overlayTime and uid___A002_X85c183_X36f.ms.tsys.plots.<br />
<br />
<figure id="X36f.Tsys.overlayTime.png"><br />
[[File:X36f.Tsys.overlayTime.png|200px|thumb|right|<caption>The Tsys as a function of frequency for DA61 in uid___A002_X85c183_X36f. Colors represent time.</caption>]]<br />
</figure><br />
<br />
<figure id="X36f.Tsys.overlayAntenna.png.png"><br />
[[File:X36f.Tsys.overlayAntenna.png.png|200px|thumb|right|<caption>The Tsys as a function of frequency for SPW 15 in uid___A002_X85c183_X36f. Colors represent antennas.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotbandpass(caltable='uid___A002_X85c183_X36f.ms.tsys',<br />
overlay='time',<br />
xaxis='freq',<br />
yaxis='amp',<br />
subplot=22,<br />
buildpdf=False,<br />
interactive=False,<br />
showatm=True,<br />
pwv='auto',<br />
chanrange='5~123',<br />
showfdm=True,<br />
field='',<br />
figfile='uid___A002_X85c183_X36f.ms.tsys.plots.overlayTime/uid___A002_X85c183_X36f.ms.tsys')<br />
</source><br />
<br />
=== Flagging ===<br />
<br />
Although the "science" SPW's have 1992 MHz bandwidths with 4080 spectral channels, their edge channels can be very noisy because each intermediate frequency signal path (baseband) is equipped with a bandpass filter of ~1.8 GHz width. Note that this is not necessarily always the case, it is in general, safest to flag out the edge channels, unless a spectral line of interest falls very close to the edge of the SPW band-edge.<br />
We flag 120 channels on each side of the "science" SPW's.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis = 'uid___A002_X85c183_X36f.ms',<br />
mode = 'manual',<br />
spw = '17:0~119;3960~4079,19:0~119;3960~4079,21:0~119;3960~4079,23:0~119;3960~4079',<br />
action = 'apply',<br />
flagbackup = True)<br />
</source><br />
<br />
==Calibration - sky, bandpass, nonlinearity and baseline ==<br />
<br />
=== Tsys Calibration ===<br />
We calibrate the data into Antenna temperature in units of K, using the equation Ta* = Tsys*(ON-OFF)/OFF, where ON and OFF are the data on-source (i.e., during the raster scanning) and off-source (on a reference position where only background emission exists), respectively.<br />
The calibration is done by the task {{tsdcal}} which requires matching of list of the "science" and Tsys spectral windows. <br />
Tsys observations will always have 128 channels over 2GHz bandwidth, and as described in {{listobs}}, we already know which spectral windows match the science spectral windows most closely, in frequency.<br />
for example, spectral window 9, with 128 channels matches well with spectral window 17, 11 with 19, 13 with 21 and 15 with 2. Thus, we form the Tsys and Science spectral window mapping input parameters, with the syntax: {9:[17], 11:[19], 13:[21],15:[23]}<br />
<br />
<pre style="background-color: #fffacd;"><br />
9 ALMA_RB_03#BB_1#SW-01#FULL_RES 128 TOPO 101942.187 -15625.000 2000000.0 100950.0000 1 XX YY<br />
.<br />
.<br />
17 ALMA_RB_03#BB_1#SW-01#FULL_RES 4080 TOPO 101945.850 -488.281 1992187.5 100950.0000 1 XX YY<br />
</pre><br />
<pre style="background-color: #fffacd;"><br />
11 ALMA_RB_03#BB_2#SW-01#FULL_RES 128 TOPO 103757.337 -15625.000 2000000.0 102765.1500 2 XX YY<br />
.<br />
.<br />
19 ALMA_RB_03#BB_2#SW-01#FULL_RES 4080 TOPO 103761.000 -488.281 1992187.5 102765.1500 2 XX YY<br />
</pre><br />
<pre style="background-color: #fffacd;"><br />
13 ALMA_RB_03#BB_3#SW-01#FULL_RES 128 TOPO 111814.962 15625.000 2000000.0 112807.1500 3 XX YY<br />
.<br />
.<br />
21 ALMA_RB_03#BB_3#SW-01#FULL_RES 4080 TOPO 111811.300 488.281 1992187.5 112807.1500 3 XX YY<br />
</pre><br />
<pre style="background-color: #fffacd;"><br />
15 ALMA_RB_03#BB_4#SW-01#FULL_RES 128 TOPO 113689.962 15625.000 2000000.0 114682.1500 4 XX YY<br />
.<br />
.<br />
23 ALMA_RB_03#BB_4#SW-01#FULL_RES 4080 TOPO 113686.300 488.281 1992187.5 114682.1500 4 XX YY<br />
</pre><br />
<br />
And the Tsys calibration command is formed like the following:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsdcal(infile = 'uid___A002_X85c183_X36f.ms',<br />
calmode = 'ps,tsys,apply',<br />
spwmap = {9:[17], 11:[19], 13:[21],15:[23]},<br />
spw = '9,11,13,15,17,19,21,23')<br />
</source><br />
<br />
'''Note:''' in this step, the calibrations are applied in situ. That is: the calibrated data are written into the original data - however it is written in such a way that any ''additional'' calls to tsdcal will not apply any further calibrations. We will examine the quality of the bandpass and Tsys calibration after the correction for non-linearity, next.<br />
<br />
<br />
<figure id="Vis_Scan6_7_9_10_12_13_15.png"><br />
[[File:Vis_Scan6_7_9_10_12_13_15.png|200px|thumb|right|<caption>Output of plotms, showing spectra in Ta* [K]</caption>]]<br />
</figure><br />
<br />
The calibrated bandpasses, averaged over each scan, can be plotted with:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='uid___A002_X85c183_X36f.ms',<br />
xaxis='freq', yaxis='amp', ydatacolumn='corrected',<br />
field='M100',spw='23',<br />
scan='6,7,9,10,12,13,15',<br />
averagedata=True,avgtime='9999',<br />
gridcols=3,gridrows=3,iteraxis='scan',<br />
plotrange=[113.5, 116, -0.01, 0.08],<br />
plotfile='vis.png',<br />
showgui=False)<br />
</source><br />
<br />
'''Note:''' For ''amplitude calibrator datasets'', (as opposed to science target maps) the calmode option for tsdcal should be 'otfraster,tsys,apply' ('otfraster' instead of 'ps').<br />
'otfraster' tells the task to use both ends of each raster row as "OFF" data (as opposed to a dedicated "OFF" sky measurement).<br />
This is because temporal fluctuation of atmospheric emission is the dominant source of noise in radio continuum observations, and hence the "OFF" needs to be as close as possible to the "ON" in time (and spatial location).<br />
<br />
=== Application of Non-Linearity Correction Factor ===<br />
<br />
In Cycle 1 and 2, single-dish data taken with the ACA correlator suffer from non-linearity which originates in the digital signal processing.<br />
Its impact was thoroughly studied both experimentally and theoretically, and it was concluded that multiplication by a correction factor of 1.25 yields an amplitude accuracy of +/-5%.<br />
<br />
To preserve the data history, we use here the tasks {{split}} to split out the science ''corrected'' data columns - note that from here on, the spectral windows are '''renumbered: [0,1,2,3]'''. We then generate a calibration table, using a defined function ''to_amp_factor'', with {{gencal}}. Finally, we apply the calibration with {{applycal}}.<br />
We apply the correction here using tasks gencal and applycal - this is different to the methods used in the past, and are available now because of the migration to MS-only format of Single-dish CASA.<br />
<br />
'''Note:''' The ACA online software has been equipped with this correction for data from cycle 3 and later (it should be applied for data from cycle 2 and earlier).<br />
<br />
<source lang="python"><br />
# In CASA<br />
to_amp_factor = lambda x: 1. / sqrt(x)<br />
<br />
split(vis='uid___A002_X85c183_X36f.ms',<br />
outputvis='uid___A002_X85c183_X36f.ms.cal.split',<br />
datacolumn='corrected',<br />
spw='17,19,21,23')<br />
<br />
gencal(vis='uid___A002_X85c183_X36f.ms.cal.split',<br />
caltable='uid___A002_X85c183_X36f.ms.nlc',<br />
caltype='amp', spw='',<br />
parameter=[to_amp_factor(1.25)])<br />
<br />
applycal(vis='uid___A002_X85c183_X36f.ms.cal.split',<br />
gaintable='uid___A002_X85c183_X36f.ms.nlc')<br />
</source><br />
<br />
'''Note:''' the Python command ''lambda'' simply defines a function. Thus the line above : ''to_amp_factor = lambda x: 1. / sqrt(x)'' defines a function where the call: ''to_amp_factor(4)'' will return: ''0.5''<br />
<br />
=== Baseline Subtraction (only for Science Datasets) ===<br />
<br />
'''Note:''' this step is appropriate for spectral line observations (science datasets) but ''should not be done for the continuum observations (amplitude calibrator datasets) -- it would eliminate the continuum emission!''<br />
'''Note:''' this step is optional and need not be completed to produce an image - however it is recommended for the majority of cases (esp. where the bandpass is affected by low-order modulations, and where the line-emission does not completely dominate the bandpass.)<br />
<br />
We will subtract low-order spectral baselines using the task {{tsdbaseline}}. Typically these manifest from structure in the distribution of water in the atmosphere: the ON and OFF positions are slightly different, and the difference manifests as - typically - a low frequency variation in the spectra. The situation is exacerbated for observations closer to water lines and also for higher frequencies.<br />
<br />
<source lang="python"><br />
# In CASA<br />
tsdbaseline(infile='uid___A002_X85c183_X36f.ms.cal.split',<br />
datacolumn='corrected',<br />
spw='',<br />
blfunc='poly',<br />
order=1,<br />
outfile='uid___A002_X85c183_X36f.ms.bl',<br />
overwrite=True)<br />
</source><br />
<br />
<br />
<figure id="vis_bl_Scan6_7_9_10_12_13_15.png"><br />
[[File: vis_bl_Scan6_7_9_10_12_13_15.png |200px|thumb|right|<caption>Output of plotms, showing result of baseline step, units in Ta* [K]</caption>]]<br />
</figure><br />
<br />
The spectra can be checked using {{plotms}}, which we have already used in a previous step.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='uid___A002_X85c183_X36f.ms.bl',<br />
xaxis='freq', yaxis='amp', ydatacolumn='corrected',<br />
field='M100',spw='3',<br />
scan='6,7,9,10,12,13,15',<br />
averagedata=True,avgtime='9999',<br />
gridcols=3,gridrows=3,iteraxis='scan',<br />
plotrange=[113.5, 116, -0.01, 0.08],<br />
plotfile='vis_bl.png',<br />
showgui=False)<br />
</source><br />
<br />
or also with {{sdplot}}:<br />
<figure id="X36f.spw23.cal.bl.png"><br />
[[File:X36f.spw23.cal.bl.png|200px|thumb|right|<caption>The spectra after baseline subtraction for DA61 SPW 23 in uid___A002_X85c183_X36f. Colors represent polarizations.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
sdplot(infile='uid___A002_X85c183_X36f.ms.bl',<br />
antenna='PM03',<br />
fluxunit='amp',<br />
specunit='GHz',<br />
field='M100',<br />
spw='3',<br />
scan='6,7,9,10,12,13,15',<br />
rastermode='row',<br />
timeaverage=True,<br />
scanaverage=True,<br />
plottype='spectra',<br />
stack='p',<br />
panel='s',<br />
flrange=[-0.1,0.16],<br />
sprange=[113.5,116],<br />
subplot=33,<br />
outfile='vis_bl_plotms.png')<br />
</source><br />
<br />
We do not concatenate separate Execution Blocks, because we need to determine and apply day-by-day Jy/K conversion factor.<br />
<br />
Note that one of the antennas, PM02, had a problem in the first baseband (SPW 17) on 2014-07-05, and its impact may not be specific to this one SPW (e.g., it may have resulted in poor pointing calibration).<br />
Therefore the PM02 data should be flagged from the affected datasets: uid___A002_X8602fa_X2ab (science), and uid___A002_X8602fa_X577 (science). The calibrator set uid___A002_X8602fa_Xc3 will also be affected, and will be flagged out in the subsequent processing of the calibrators.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='uid___A002_X8602fa_X2ab.ms.bl',<br />
antenna='PM02')<br />
flagdata(vis='uid___A002_X8602fa_X577.ms.bl',<br />
antenna='PM02')<br />
</source><br />
<br />
<br />
== Convert science data from Kelvin to Jansky ==<br />
<br />
At this stage the data have been calibrated into units of antenna temperature, in Kelvins.<br />
<br />
It now remains to convert the science data into Jy/beam units - the ''Jy per K'' factors. This is important for combination of the data, with 7m and 12m sets. Later in this guide we show how to determine the correct factors from the calibrator datasets, for conversion (the process is essentially identical to processing the science datasets, with the exception that the baseline step is omitted from the calibration dataset processing). However to determine the factors, the calibration data must also be imaged and then interrogated to determine the appropriate values. <br />
<br />
Applying the calibration factors to the science data is the last step in the script [[media:M100.casa4p5.calib.py|M100.casa4p5.calib.py]]. <br />
<br />
We continue to use only one ASDM as an example; uid___A002_X85c183_X36f. The script should be consulted for treatment of all the M100 Single-dish ASDMs (and the correct application of the Jy per K factors). Again, we apply the factors by making use of the {{gencal}} and {{applycal}} tasks. Also as before, we make use of the python function defined earlier: ''to_amp_factor''<br />
<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
factors = [41.37, 42.39, 43.45, 42.82]<br />
gencal(vis='uid___A002_X85c183_X36f.ms.bl',<br />
caltable=jypkcaltable,<br />
caltype='amp',<br />
spw='0,1,2,3',<br />
parameter=[to_amp_factor(jyperk)])<br />
<br />
applycal(vis='uid___A002_X85c183_X36f.ms.bl',<br />
gaintable=jypkcaltable)<br />
</source><br />
<br />
== Image the Science Target ==<br />
<br />
The final stage is to image the science data. This step is done by the script "[[media: M100.casa4p5.imaging.py|M100.casa4p5.imaging.py]]" which is invoked with ''execfile('M100.casa4p5.imaging.py') '' in CASA.<br />
This step uses a number of helper utilities to automatically determine the properties of the image data - the analysis Utilities library must be loaded (see the text above).<br />
<br />
=== Determining grid parameters, gridding and obtaining grid metadata ===<br />
Define the list of the calibrated science datasets, which the CASA task {{sdimaging}} accepts. Note that this step is the same for science and calibrator data.<br />
This section is a little more python-heavy than the calibration step. CASA 4.5 has benefited from significant effort in streamlining the calibration steps, and the imaging steps are to be more automated in coming cycles.<br />
<br />
In this section, we will simply process all the calibrated science data. The calibrator data should never be combined. There is no need to ''concatenate'' the calibrated data, as the imaging task can explicitly accept multiple datasets as input.<br />
<br />
<source lang="python"><br />
# In CASA<br />
asdmlist = ['uid___A002_X85c183_X36f',<br />
'uid___A002_X85c183_X60b',<br />
'uid___A002_X8602fa_X2ab',<br />
'uid___A002_X8602fa_X577',<br />
'uid___A002_X864236_X2d4',<br />
'uid___A002_X864236_X693',<br />
'uid___A002_X86fcfa_X664',<br />
'uid___A002_X86fcfa_X96c',<br />
'uid___A002_X86fcfa_Xd9']<br />
vislist = map(lambda x: x + '.ms.bl', asdmlist)<br />
</source><br />
<br />
<br />
We first have to define and obtain some basic parameters. As all the ASDMs are ostensibly of the same kinds of observations, we refer to the first science ASDM to determine the basic properties of the resulting data cube. The cube size, pixel size, theoretical beam size, central frequency and other basic parameters are extracted using some CASA-fu and the Analysis Utils library (see the top of this page for information on Analysis Utils).<br />
<br />
<source lang="python"><br />
# In CASA<br />
imagename = 'M100_TP_CO_cube.spw%s.image'%(spw)<br />
blimagename = imagename + '.bl'<br />
integimagename = imagename + '.integ'<br />
fwhmfactor = 1.13<br />
diameter = 12<br />
spw = 3<br />
<br />
xSampling, ySampling, maxsize = aU.getTPSampling(uid___A002_X85c183_X36f.ms, showplot=False)<br />
<br />
msmd.open(sciencedata[0])<br />
freq = msmd.meanfreq(spw)<br />
msmd.close()<br />
print "SPW %d: %.3f GHz" % (spw, freq*1e-9)<br />
<br />
theorybeam = aU.primaryBeamArcsec(frequency=freq*1e-9,<br />
fwhmfactor=fwhmfactor,<br />
diameter=diameter)<br />
<br />
cell = theorybeam/9.0<br />
imsize = int(round(maxsize/cell)*2)<br />
</source><br />
And now we learn the central frequency of spectral window 3, is 114.682 GHz.<br />
Our cube will have a total length of 254.0 arcsec ('''maxsize'''), and with a cell side of 5.64 arcsec ('''cell''') -which samples the theoretical beam (''theory beam'') with 9x9 pixels, we will need 90 pixels along the image side ('''imsize''').<br />
<br />
'''Note:''' The Jy/K value depends on the parameters of gridding convolution (i.e., "gridfunction", "cell", and function-specific parameters ["convsupport" for gridfunction='SF']). That is, the same gridding parameters should be used for both amplitude calibrator and science images -- otherwise the calibration into Jy unit becomes invalid. Please refer to the CASA cookbook for information on the gridding kernels.<br />
<br />
<br />
Now the data are imaged.<br />
The velocity channel maps of the CO J=1-0 line (restfreq='115.271201800GHz') are created as a data cube which covers the velocity range of 1400-1700 km/s at a spacing of 5 km/s (start='1400km/s', width='5km/s', nchan=70).<br />
<br />
<source lang="python"><br />
# In CASA <br />
sdimaging(infiles=vislist,<br />
field='M100',<br />
spw='%s'%(spw),<br />
nchan=70,<br />
mode='velocity',<br />
start='1400km/s',<br />
width='5km/s',<br />
veltype='radio',<br />
outframe='lsrk',<br />
restfreq='115.271204GHz',<br />
gridfunction='SF',<br />
convsupport=6,<br />
stokes='I',<br />
phasecenter='J2000 12h22m54.9 +15d49m15',<br />
ephemsrcname='',<br />
imsize=imsize,<br />
cell='%sarcsec'%(cell),<br />
overwrite=True,<br />
outfile=imagename)<br />
</source><br />
<br />
The produced image has the brightness unit of K in the image header, which is not correct.<br />
Modify the header using the task {{imhead}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imhead(imagename=imagename,<br />
mode='put',<br />
hdkey='bunit',<br />
hdvalue='Jy/beam')<br />
</source><br />
<br />
Now you can browse the data cube using the viewer.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer(imagename)<br />
</source><br />
<br />
=== Subtract a Residual Background from the Image ===<br />
<br />
If you plot the line profile using the viewer, you may notice that the background (i.e., line-free channels) level is slightly negative.<br />
To correct this, spectral baselines are subtracted from the image using the task {{imcontsub}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imcontsub(imagename=imagename,<br />
linefile=blimagename,<br />
contfile='M100.residualbaseline.image',<br />
fitorder=1,<br />
chans='0~7;62~69')<br />
os.system('rm -rf M100.residualbaseline.image')<br />
</source><br />
<br />
This task has two outputs - the baselined data is returned in the same input file (''image name - M100_TP_CO_cube.spw3.image.bl''), while the subtracted component is returned in ''M100.residual baseline.image"". We have no further need for the subtracted component, and it can be discarded.<br />
<br />
== Basic Analysis - Moments==<br />
<br />
Make a 0th moment (integrated intensity) map using the task {{immoments}} and browse it using the viewer.<br />
<br />
<figure id="M100.CO.cube.bl.image.mom0.png"><br />
[[File:M100.CO.cube.bl.image.mom0.png|200px|thumb|right|<caption>The integrated intensity map of M100.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments(imagename=blimagename,<br />
moments=[0],<br />
axis='spectral',<br />
chans='8~61',<br />
outfile=integimagename)<br />
<br />
viewer('M100_TP_CO_cube.bl.image.mom0')<br />
</source><br />
<br />
== Imaging the Amplitude Calibrator and Measure the Value of Jy/K ==<br />
<br />
Determination of the Jy/K conversion factor is achieved by imaging a source whose continuum flux is known and measuring the observed brightness temperature. One observation of this source - the amplitude calibrator - was made per day, giving a total of four datasets (see top).<br />
<br />
The true size of the beam (point spread function), on which the Jy/K value depends, in a map is determined be several ingredients.<br />
* The intrinsic beam size is determined by the antenna diameter and optics (and of course wavelength). Here we assume the intrinsic beam size of 1.13*lambda/D, where D=12 [m] is the diameter of the antennas, and the factor 1.13 is derived from the optics design of the ALMA 12-m antennas.<br />
* The effective beam size is broadened by the following causes:<br />
** The scanning pattern used to observe the map (i.e., sample spacing in both directions).<br />
** The method used to grid the individual spectra into a map/cube.<br />
The Analysis Utilities provides several tools to get estimates of these.<br />
<br />
It is not necessary, but If you wish to try this out for yourself, you will first need to download the raw amplitude calibrator data file M100_Band3_TP_ampcal_UncalibratedData.tgz. How to obtain the data is described at [[M100_Band3#Obtaining the Data]]. Once you have unpacked the data you will have a directory called M100_Band3_TP_ampcal_UncalibratedData. In this directory, execute the scripts for individual datasets. <br />
The script to do this is not yet complete, but the general approach is almost identical to that of calibrating the science target data, with the exception of the baselining step. <br />
<br />
The reader may wish to refer to the user guide for Cycle 4.3, to obtain a full description of how this step is accomplished in that version of CASA.<br />
<br />
The Calibration Jy/K values are determined as follows. Note that the values for individual antennas are averaged for each day, each SPW, because the antennas used for the Science observations were not necessarily available for the corresponding amplitude calibrator observations.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
#Date Amp_Cal_Dataset SPW17 SPW19 SPW21 SPW23<br />
2014-07-01 uid___A002_X85c183_X895 41.37 42.39 43.45 42.82<br />
2014-07-05 uid___A002_X8602fa_Xc3 40.99 42.74 40.08 42.09<br />
2014-07-07 uid___A002_X864236_Xe1 39.42 42.08 40.18 40.82<br />
2014-07-17 uid___A002_X86fcfa_X3ae 43.49 43.70 42.01 43.04<br />
</pre><br />
<br />
== Combination with 12m and 7m Array Data ==<br />
<br />
If you wish to learn how to combine the Total Power data with interferometric 12m and 7m data, see the guide for Data Combination [[M100_Band3_Combine_4.3]]<br />
<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=IRAS16293_Band9_-_Imaging_for_CASA_4.5&diff=21240IRAS16293 Band9 - Imaging for CASA 4.52017-04-04T13:31:47Z<p>Jthorley: </p>
<hr />
<div><pre style="background-color: #ffa07a;"><br />
WARNING: On June 15, 2012 the calibration guide and the final data products (calibrated science <br />
data: IRAS16293_Band9_CalibratedMS_FIXED.tgz and reference images: IRAS16293_Band9_ReferenceImages_FIXED.tgz)) <br />
were changed to correct for a 1.2" position error in the phase calibrator (1625-254). Without <br />
correction, the science images will suffer from a similar offset. <br />
</pre><br />
<br />
== Overview ==<br />
This section of the casa guide continues from [http://casaguides.nrao.edu/index.php?title=IRAS16293_Band9_-_Calibration_for_CASA_4.5 IRAS16293_Band9_-_Calibration_for_CASA_4.5] . If you completed the calibration section, then you already have the final calibrated dataset. If you just started to work on this IRAS16293 B9 data, you can download the fully calibrated dataset '''IRAS16293_Band9_CalibratedMS''' from<br />
<br />
[https://almascience.nrao.edu/almadata/sciver/IRAS16293B9 North America]<br />
<br />
[http://almascience.eso.org/almadata/sciver/IRAS16293B9 Europe]<br />
<br />
[http://almascience.nao.ac.jp/almadata/sciver/IRAS16293B9 East Asia]<br />
<br />
This casa guide covers imaging of both continuum and spectral lines of IRAS16293 Band 9. '''This guide requires CASA 4.5'''. In this casa guide you will also need the [http://casaguides.nrao.edu/index.php?title=Analysis_Utilities Analysis Utils] package, so make sure you have it imported into CASA.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see the CASA 3.3 version of the guide linked at the top of this page for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, its probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
== List the contents of the Data==<br />
<br />
Before we start with the imaging itself, do a {{listobs}} to the calibrated dataset, so you can check that everything is ok.<br />
<br />
<source lang="python"><br />
# listobs to check data<br />
listobs(vis='IRAS16293_Band9.fixed.rebin.ms',<br />
listfile='IRAS16293_Band9.fixed.rebin.ms.listobs',verbose=False)<br />
</source><br />
<br />
You should see the next information in the .listobs file.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 7<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none IRAS16293-2422-a 16:32:22.99200 -24.28.36.0000 J2000 0 7811 <br />
1 none IRAS16293-2422-a 16:32:22.47925 -24.28.36.0000 J2000 0 7829 <br />
2 none IRAS16293-2422-a 16:32:22.73563 -24.28.36.0000 J2000 0 7829 <br />
3 none IRAS16293-2422-a 16:32:22.73563 -24.28.32.5000 J2000 0 7829 <br />
4 none IRAS16293-2422-a 16:32:22.47925 -24.28.29.0000 J2000 0 7429 <br />
5 none IRAS16293-2422-a 16:32:22.73563 -24.28.29.0000 J2000 0 7151 <br />
6 none IRAS16293-2422-a 16:32:22.99200 -24.28.29.0000 J2000 0 7151 <br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 703312.744 488.28125 1875000 XX YY <br />
1 3840 TOPO 692237.256 -488.28125 1875000 XX YY <br />
2 3840 TOPO 690437.256 -488.28125 1875000 XX YY <br />
3 3840 TOPO 688437.256 -488.28125 1875000 XX YY <br />
Antennas: 13 'name'='station' <br />
ID= 0-3: 'DA41'='A003', 'DA43'='A075', 'DA47'='A026', 'DV02'='A077', <br />
ID= 4-8: 'DV03'='A137', 'DV07'='A076', 'DV09'='A046', 'DV10'='A071', <br />
ID= 9-13: 'DV12'='A011', 'DV13'='A072', 'DV14'='A025', 'DV17'='A138', <br />
</pre><br />
<br />
'''Unless you have calibrated yourself the measurement set you are using for imaging, it is essential to do the following.'''<br />
<br />
<source lang="python"><br />
# In CASA<br />
tb.open('IRAS16293_Band9.fixed.rebin.ms/POINTING', nomodify = False)<br />
a = tb.rownumbers()<br />
tb.removerows(a)<br />
tb.close()<br />
</source><br />
<br />
== Continuum Emission Imaging ==<br />
As shown in Figure 2 of [[IRAS16293Band9]], these observations have a 7 pointing mosaic, which you can visualize with the next command (see also Figure 1).<br />
<br />
[[File:mosaic_pattern.png|200px|thumb|right|'''Fig. 1.''' Pointings showing the mosaic used for the observations. The circles mark the FWHM of the primary beam response.]]<br />
<br />
<source lang="python"><br />
# Make a plot of the mosaic pattern with field ids identified<br />
au.plotmosaic(vis='IRAS16293_Band9.fixed.rebin.ms',sourceid='0',<br />
doplot=True,figfile='mosaic_pattern.png')<br />
</source><br />
<br />
You might wonder which of these pointings or fields have stronger line emission. You can determine this by running the next command. We set spw='1' which contains CO (6-5), and you can check all the plots for all the fields by just hitting the arrow for "next". Also see Figure 2 for an example of the output.<br />
<br />
[[File:IRAS16293_Band9.AVG.ms_uvamp_f0_spw1.png|200px|thumb|right|'''Fig. 2.''' UV-amp distribution for the field 0 (spw 1) in the mosaic.]]<br />
<br />
<source lang="python"><br />
# See which mosaic fields have the brightest line emission<br />
plotms(vis='IRAS16293_Band9.fixed.rebin.ms', <br />
field='',xaxis='uvdist', yaxis='amp',<br />
spw='1', avgchannel='3840',coloraxis='field',<br />
iteraxis='field')<br />
</source><br />
<br />
Another way to visualize the uv-amp distribution is with the next {{plotms}}. This will load all the fields for pointing into the plot, and you can change interactively between the spws using the appropriate button in plotms. See Figure 3 for a plot of spw 0.<br />
<br />
[[File:IRAS16293_Band9.AVG.ms_uvamp_allf_spw0.png|200px|thumb|right|'''Fig. 3.''' UV-amp distribution for spw 0 using all the fields or pointings in the mosaic.]]<br />
<br />
<source lang="python"><br />
# Iterate over spws all fields<br />
plotms(vis='IRAS16293_Band9.fixed.rebin.ms', <br />
field='',xaxis='uvdist', yaxis='amp',<br />
spw='', avgchannel='3840',coloraxis='field',<br />
iteraxis='spw')<br />
</source><br />
<br />
We need to note the channels that do not present line emission. To identify them we can plot the amplitude vs frequency for all the spectral windows. Figure 4 shows the output from the next command for spw 1 (field 3). You are dealing with a set of data which were split so the calibrated data now reside in the "data" column of the new measurement set. Therefore the following call to plotms must specify ydatacolumn = "data". If you had never performed the split, the calibrated data would have been accessed from the "corrected" column of the old, unsplit, measurement set. Those who have used previous versions of CASA should note that in those older versions, plotms would default to using the "data" column if there were no data in the "corrected" column and one specified ydatacolumn="corrected".<br />
<br />
[[File:amp_vs_channel.spw1.png|200px|thumb|right|'''Fig. 4.''' Frequency-amplitude plot for spw=1 of field=3. ]]<br />
<br />
<source lang="python"><br />
# Select Channels for uvcontsub. Average every 8 channels for<br />
# increased S/N.<br />
<br />
plotms(vis='IRAS16293_Band9.fixed.rebin.ms', <br />
xaxis='channel', yaxis='amp',field='3',<br />
spw='', avgtime='1e8',avgscan=True,coloraxis='corr',<br />
avgchannel='',iteraxis='spw',ydatacolumn='data',<br />
xselfscale=True,yselfscale=True)<br />
</source><br />
<br />
Using the plots from the previous command you can select a block of channels that are free of strong line emission. To do this in the most rigorous way, you would first need to make dirty image cubes and then examine the spectra on and near the continuum sources, because many more weaker lines will become apparent in the cubes. Here we provide you with the channel selection we used for continuum emission.<br />
<br />
The next {{flagmanager}} command will save the flags state in case you might need to re-do the steps from this point.<br />
<br />
<source lang="python"><br />
flagmanager(vis='IRAS16293_Band9.fixed.rebin.ms',mode='save',versionname='Original')<br />
</source><br />
<br />
Now we will flag the channels identified to have line emission, so we will be ready to proceed with the continuum imaging.<br />
<br />
<source lang="python"><br />
# flagging the line channels<br />
flagdata(vis='IRAS16293_Band9.fixed.rebin.ms',<br />
spw='0:1700~2500,1:400~500;1100~1900;3000~3450,2:1700~2200;3100~3839,3:0~800;1600~2900;3300~3839',action='apply', flagbackup=False)<br />
</source><br />
<br />
To help {{clean}} to be faster, you can average 200 channels, as you do not need to have a high spectral resolution for continuum imaging.<br />
<br />
<source lang="python"><br />
split(vis='IRAS16293_Band9.fixed.rebin.ms',<br />
outputvis='IRAS16293_Band9.fixed.CONT.msAVG',field='',<br />
datacolumn='data',width=200,spw='0~3:20~3819')<br />
</source><br />
<br />
=== Clean and self-calibrate the continuum ===<br />
<br />
Now we proceed with the cleaning itself. For the {{clean}} task you will need to choose the right cell size, map size, etc. Below are the parameters that were used in this casaguide. Note that the command will be interactive and you will have to set the cleaning boxes.<br />
<br />
<source lang="python"><br />
# cleaning 1<br />
os.system('rm -rf *CONTIN*')<br />
clean(vis='IRAS16293_Band9.fixed.CONT.msAVG',<br />
imagename='IRAS16293_Band9.fixed.CONTIN',<br />
spw='0~3',field='',phasecenter='3',<br />
mode='mfs',imagermode='mosaic',<br />
imsize=500,cell='0.04arcsec',minpb=0.25,<br />
interactive=True,<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='0.3mJy',usescratch=False)<br />
</source><br />
<br />
<br />
Now we proceed with {{gaincal}} to perform self calibration (for phases) on the data. Even with minsnr=3.0 there will be some failed solutions.<br />
<br />
<source lang="python"><br />
# get one scan per field<br />
os.system('rm -rf cont_pcal1')<br />
gaincal(vis='IRAS16293_Band9.fixed.CONT.msAVG',caltable='cont_pcal1',gaintype='T',<br />
refant='DV14',calmode='p',combine='',spw='',field='',<br />
solint='inf',minsnr=3.0,minblperant=4)<br />
</source><br />
<br />
The solutions for five antennas are shown in Figure 6, and are produced with the next {{plotcal}}. Be sure to check all the antennas.<br />
<br />
[[File:cont_pcal1.png|200px|thumb|right|'''Fig. 6.''' Phase solutions for the first self-cal run.]]<br />
<br />
<source lang="python"><br />
plotcal(caltable='cont_pcal1',xaxis='time',yaxis='phase',<br />
spw='',iteration='antenna',subplot=511,plotrange=[0,0,-80,80],<br />
antenna='',timerange='')<br />
<br />
# The phases are remarkably stable for Band 9! <br />
</source><br />
<br />
We then apply the table to the data to proceed right after with the proper cleaning, to check the improvement of the data.<br />
<br />
<source lang="python"><br />
# application of the table<br />
applycal(vis='IRAS16293_Band9.fixed.CONT.msAVG',spwmap=[],spw='',<br />
gaintable=['cont_pcal1'],calwt=False,flagbackup=False)<br />
</source><br />
<br />
Now you are ready for the second cleaning. For this one we are using the mask resulting from the previous cleaning. In the next blocks of commands we will repeat this process (clean, viewer, gaincal, plotcal, applycal, clean, etc.) to improve the overall quality of the image.<br />
<br />
<source lang="python"><br />
# cleaning 2<br />
os.system('rm -rf *CONTIN_P1*')<br />
clean(vis='IRAS16293_Band9.fixed.CONT.msAVG',<br />
imagename='IRAS16293_Band9.fixed.CONTIN_P1',<br />
spw='0~3',field='',phasecenter='3',<br />
mode='mfs',imagermode='mosaic',<br />
imsize=500,cell='0.04arcsec',minpb=0.25,<br />
interactive=True,<br />
weighting='briggs',robust=0.5,<br />
mask='IRAS16293_Band9.fixed.CONTIN.mask',<br />
niter=10000, threshold='0.3mJy', usescratch=False)<br />
<br />
# visualize the image<br />
imview (raster=[{'file':'IRAS16293_Band9.fixed.CONTIN.image',<br />
'range': [-0.01,0.5]},<br />
{'file': 'IRAS16293_Band9.fixed.CONTIN_P1.image',<br />
'range': [-0.01,0.5]}])<br />
</source><br />
<br />
The image "IRAS16293_Band9.fixed.CONTIN_P1.image" should have 2 very clearly defined regions of emission, moreso then the first clean run "IRAS16293_Band9.fixed.CONTIN.image," following self-calibration.<br />
<br />
Second {{gaincal}} step for self calibration.<br />
<br />
<source lang="python"><br />
# second self-cal<br />
os.system('rm -rf cont_pcal2')<br />
gaincal(vis='IRAS16293_Band9.fixed.CONT.msAVG',caltable='cont_pcal2',gaintype='T',<br />
refant='DV14',calmode='p',combine='',spw='',field='',<br />
solint='inf',minsnr=3.0,minblperant=4)<br />
<br />
#Checking the table<br />
plotcal(caltable='cont_pcal2',xaxis='time',yaxis='phase',<br />
spw='',iteration='antenna',subplot=511,plotrange=[0,0,-80,80],<br />
antenna='',timerange='')<br />
<br />
# Applying results to the data<br />
applycal(vis='IRAS16293_Band9.fixed.CONT.msAVG',spwmap=[],spw='',<br />
gaintable=['cont_pcal2'],calwt=False,flagbackup=False)<br />
</source><br />
<br />
We continue with the next cleaning.<br />
<br />
<source lang="python"><br />
# Cleaning 3<br />
os.system('rm -rf *CONTIN_P2*')<br />
clean(vis='IRAS16293_Band9.fixed.CONT.msAVG',<br />
imagename='IRAS16293_Band9.fixed.CONTIN_P2',<br />
spw='0~3',field='',phasecenter='3',<br />
mode='mfs',imagermode='mosaic',<br />
imsize=500,cell='0.04arcsec',minpb=0.25,<br />
interactive=True,<br />
weighting='briggs',robust=0.5,<br />
mask='IRAS16293_Band9.fixed.CONTIN.mask',<br />
niter=10000, threshold='0.3mJy', usescratch=False)<br />
<br />
# to view the resulting image<br />
imview (raster=[{'file':'IRAS16293_Band9.fixed.CONTIN_P1.image',<br />
'range': [-0.01,0.5]},<br />
{'file': 'IRAS16293_Band9.fixed.CONTIN_P2.image',<br />
'range': [-0.01,0.5]}])<br />
<br />
# There is very little change, the bold could try another iteration using a shorter<br />
# solint phase self-cal. For now, moving on to amplitude.<br />
</source><br />
<br />
[[File:cont_apcal.png|200px|thumb|right|'''Fig. 6.''' Amplitude self-calibration solutions.]]<br />
<br />
Next iteration with gaincal, now using amplitude and phase for "calmode".<br />
<br />
<source lang="python"><br />
# For amplitude self-cal we only want to get one solution per spw, per dataset<br />
os.system('rm -rf cont_apcal')<br />
gaincal(vis='IRAS16293_Band9.fixed.CONT.msAVG',caltable='cont_apcal',gaintype='T',<br />
refant='DV14',calmode='ap',combine='scan,field',spw='',field='',<br />
solint='8000s',minsnr=3.0,minblperant=4,gaintable='cont_pcal2')<br />
<br />
# plotting the table<br />
plotcal(caltable='cont_apcal',xaxis='time',yaxis='amp',<br />
spw='',iteration='antenna',subplot=511,plotrange=[0,0,0.5,2],<br />
antenna='',timerange='')<br />
<br />
# and applying to the data<br />
applycal(vis='IRAS16293_Band9.fixed.CONT.msAVG',spwmap=[],spw='',<br />
gaintable=['cont_pcal2','cont_apcal'],calwt=False,flagbackup=False)<br />
<br />
# A large correction is present for the 2nd dataset. This amplitude<br />
# error was causing many of the artifacts noticeable in the previous<br />
# images.<br />
</source><br />
<br />
Continuing the final cleaning step.<br />
<br />
<source lang="python"><br />
# Cleaning 4<br />
os.system('rm -rf *CONTIN_AP*')<br />
clean(vis='IRAS16293_Band9.fixed.CONT.msAVG',<br />
imagename='IRAS16293_Band9.fixed.CONTIN_AP',<br />
spw='0~3',field='',phasecenter='3',<br />
mode='mfs',imagermode='mosaic',<br />
imsize=500,cell='0.04arcsec',minpb=0.25,<br />
interactive=True,<br />
weighting='briggs',robust=0.5,<br />
mask='IRAS16293_Band9.fixed.CONTIN_P2.mask',<br />
niter=10000, threshold='0.3mJy', usescratch=False)<br />
<br />
# and to view the image<br />
imview (raster=[{'file':'IRAS16293_Band9.fixed.CONTIN_P2.image',<br />
'range': [-0.01,0.5]},<br />
{'file': 'IRAS16293_Band9.fixed.CONTIN_AP.image',<br />
'range': [-0.01,0.5]}])<br />
</source><br />
<br />
We use now impbcor to produce an image corrected by the primary beam response. We are<br />
outputting a sub-region of the cube because the area covered is large compared to <br />
the area of interest, and we want to keep the file size of the result as small<br />
as possible.<br />
<br />
<source lang="python"><br />
# correcting for primary beam<br />
impbcor(imagename='IRAS16293_Band9.fixed.CONTIN_AP.image',<br />
pbimage='IRAS16293_Band9.fixed.CONTIN_AP.flux',<br />
outfile='IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim',<br />
box='150,104,345,299')<br />
<br />
# and checking the image<br />
imview (raster=[{'file': 'IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim',<br />
'range': [-0.01,1.5],'colorwedge':True}],<br />
out='IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim.png')<br />
<br />
</source><br />
<br />
In Figure 7 we show the final image of the self-calibration process. Source A is the weaker source to the SE and Source B is the stronger source to the NW. The rms noise is about 18 mJy/beam, and the restoring beam is 0.29 x 0.17 arcsec, PA=-71 deg with robust=0.5 weighting. The peak intensities for the two components are about 3.19 (B) and 1.07 (A) Jy/beam, while the flux densities are about 11.9 (B) and 9 (A) Jy.<br />
<br />
<br />
[[File:IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim_c.png|200px|thumb|right|'''Fig. 7.''' Continuum image resulted from the complete process of self calibration for the mosaic of IRAS16293 Band 9.]]<br />
<br />
<br />
Now you can export your final image in FITS format, so you can analyze it in other software packages if desired.<br />
<source lang="python"><br />
exportfits(imagename='IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim',<br />
fitsimage='IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim.fits')<br />
</source><br />
<br />
== Spectral Line Imaging ==<br />
<br />
<source lang="python"><br />
# Restore the flags made for the continuum imaging<br />
flagmanager(vis='IRAS16293_Band9.fixed.rebin.ms',mode='restore',versionname='Original')<br />
</source><br />
<br />
Then we subtract the continuum, using the line free channels<br />
<br />
<source lang="python"><br />
# Subtract the continuum from the line data<br />
contspw='0:20~1700;2500~3820,1:20~400;500~1100;1900~3000;3450~3800,2:20~1700;2200~3100,3:800~1600;2900~3300'<br />
uvcontsub(vis='IRAS16293_Band9.fixed.rebin.ms',fitspw=contspw,fitorder=1,combine='spw')<br />
</source><br />
<br />
Before we commence with the cleaning we also need to apply the tables we produced in the self calibration steps.<br />
<br />
<source lang="python"><br />
# Apply final self-calibration to the line data<br />
applycal(vis='IRAS16293_Band9.fixed.rebin.ms.contsub',spwmap=[],spw='',<br />
gaintable=['cont_pcal2','cont_apcal'],calwt=False,flagbackup=False)<br />
</source><br />
<br />
<br />
Some notes for this sections: the threshold was chosen after doing a couple of smaller test images. This is about 3 sigma in channels with weak line emission. The mask was also chosen from a few test images. <br />
<br />
=== Create a velocity cube for H13CN (J=8-7) ===<br />
<br />
In this section we provide an example for how to create a Doppler corrected velocity cube for one of the interesting lines in the data: H13CN (J=8-7). <br />
<br />
A good reference for finding rest frequencies is http://www.splatalogue.net/. Another good reference for Band 9 specifically is the 450 micron CSO survey of Orion: http://iopscience.iop.org/0067-0049/132/2/281/<br />
<br />
First, determine the velocity range for H13CN 690.55207 GHz<br />
with the help of the next {{plotms}}<br />
<br />
<source lang="python"><br />
plotms(vis='IRAS16293_Band9.fixed.rebin.ms.contsub',<br />
xaxis='velocity', yaxis='amp',field='',<br />
spw='1', avgtime='1e8',avgscan=True,coloraxis='field',<br />
transform=True,freqframe='LSRK',restfreq='690.55207GHz',<br />
avgchannel='8',<br />
ydatacolumn='data',plotfile='Vel_H13CN.png')<br />
</source><br />
<br />
Now do an interactive clean, making clean boxes for the emission. Stop<br />
cleaning when noise like residuals remain. Number of iterations<br />
between showing each interactive window can be controlled within the<br />
interactive viewer. We used about 400 iterations.<br />
<br />
<source lang="python"><br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7*') <br />
clean(vis='IRAS16293_Band9.fixed.rebin.ms.contsub',<br />
imagename='IRAS16293_Band9.fixed.H13CN_8_7',<br />
spw='1',field='',phasecenter='3',<br />
mode='velocity',outframe='LSRK',restfreq='690.55207GHz',<br />
nchan=60,start='-10km/s',width='0.5km/s',<br />
imagermode='mosaic',<br />
imsize=500,cell='0.04arcsec',minpb=0.25,<br />
interactive=True,<br />
weighting='briggs',robust=0.5,<br />
niter=500, threshold='220.0mJy')<br />
</source><br />
<br />
You need to correct for the primary beam attenuation and subimage the cubes to a <br />
smaller more manageable size since most of the mosaic is empty.<br />
<br />
<source lang="python"><br />
<br />
impbcor(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image',<br />
pbimage='IRAS16293_Band9.fixed.H13CN_8_7.flux',<br />
outfile='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim',<br />
box='150,104,345,299')<br />
</source><br />
<br />
<br />
To enable analysis in other software packages, you can export the data from CASA to FITS format using {{exportfits}}<br />
<br />
<source lang="python"><br />
<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.fits')<br />
</source><br />
<br />
=== Moment Maps for H13CN (J=8-7) ===<br />
To proceed with the moment maps generation, you will need to determine the channel range and pixel range for inclusion for higher order moments.<br />
<br />
<source lang="python"><br />
viewer('IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim')<br />
</source><br />
<br />
Generation of moment 0<br />
<br />
<source lang="python"><br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.mom0')<br />
immoments(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim',moments=[0],<br />
outfile='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.mom0',<br />
chans='10~44')<br />
</source><br />
<br />
which you can see in Figure 8. To produce that figure run the following command<br />
<br />
[[File:IRAS16293_Band9.fixed.H13CN_8_7.mom0.png|200px|thumb|right|'''Fig. 8.''' Moment 0 map for the spectral line H13CN J=8-7.]]<br />
<br />
[[File:IRAS16293_Band9.fixed.H13CN_8_7.Positive_mom1.png|200px|thumb|right|'''Fig. 9.''' Positive part of the moment 1 map.]]<br />
<br />
[[File:IRAS16293_Band9.fixed.H13CN_8_7.Negative_mom1.png|200px|thumb|right|'''Fig. 10.''' Negative part of the moment 1.]]<br />
<br />
<source lang="python"><br />
imview( raster=[ {'file':'IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.mom0',<br />
'range': [-1.,5.5]} ], <br />
contour={'file':'IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim', <br />
'base':0, 'unit':0.025, 'levels':[3]},<br />
out='IRAS16293_Band9.fixed.H13CN_8_7.mom0.png')<br />
</source><br />
<br />
One cannot make higher order moments that simultaneously include<br />
both positive and negative emission. So we separate them<br />
below. Also, we need to restrict the higher order moments to regions<br />
of real signal. Below we demonstrate using the clean mask for this<br />
purpose. We must first subimage it to match the primary beam corrected image. We<br />
also set the included pixels to about 5sigma.<br />
<br />
<source lang="python"><br />
immath(imagename='IRAS16293_Band9.fixed.H13CN_8_7.mask',<br />
mode='evalexpr',expr='IM0',box='150,104,345,299',<br />
outfile='IRAS16293_Band9.fixed.H13CN_8_7.mask.subim')<br />
</source><br />
<br />
Producing moment 1 and 2<br />
<br />
<source lang="python"><br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive*')<br />
immoments(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim',moments=[1,2],<br />
outfile='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive',<br />
mask='IRAS16293_Band9.fixed.H13CN_8_7.mask.subim',<br />
chans='10~44',includepix=[0.4,100])<br />
<br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative*')<br />
immoments(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim',moments=[1,2],<br />
outfile='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative',<br />
mask='IRAS16293_Band9.fixed.H13CN_8_7.mask.subim',<br />
chans='10~44',includepix=[-100,-0.4])<br />
</source><br />
<br />
Visualizing the maps<br />
<br />
<source lang="python"><br />
imview( raster=[ {'file':'IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_coord',<br />
'colorwedge':True}], <br />
contour={'file':'IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim', <br />
'base':0, 'unit':0.025, 'levels':[3]},<br />
out='IRAS16293_Band9.fixed.H13CN_8_7.Negative_mom1.png')<br />
</source><br />
<br />
<source lang="python"><br />
imview( raster=[ {'file':'IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_coord',<br />
'colorwedge':True}], <br />
contour={'file':'IRAS16293_Band9.fixed.CONTIN_AP.image.pbcor.subim', <br />
'base':0, 'unit':0.025, 'levels':[3]},<br />
out='IRAS16293_Band9.fixed.H13CN_8_7.Positive_mom1.png')<br />
</source><br />
<br />
And finally export the result to FITS format<br />
<br />
<source lang="python"><br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.fits')<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.fits')<br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.mom0.fits')<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.mom0',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.mom0.fits')<br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_coord.fits')<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_coord',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_coord.fits')<br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_coord.fits')<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_coord',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_coord.fits')<br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_dispersion_coord.fits')<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_dispersion_coord',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Negative.weighted_dispersion_coord.fits')<br />
os.system('rm -rf IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_dispersion_coord.fits')<br />
exportfits(imagename='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_dispersion_coord',<br />
fitsimage='IRAS16293_Band9.fixed.H13CN_8_7.image.pbcor.subim.Positive.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=IRAS16293_Band9_-_Calibration_for_CASA_4.5&diff=21236IRAS16293 Band9 - Calibration for CASA 4.52017-04-03T18:22:38Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This script assumes that you have downloaded IRAS16293_Band9_UnCalibratedMS.tgz from [[IRAS16293Band9#Obtaining the Data]]'''.<br />
<br />
*'''Details of the ALMA observations are provided at [[IRAS16293Band9]].<br />
<br />
*'''This portion of the guide covers calibration of the raw visibility data. To skip to the imaging portion of the guide, see: [[IRAS16293 Band9 - Imaging for CASA 4.5]]'''.<br />
<br />
<pre style="background-color: #ffa07a;"><br />
WARNING: On June 15, 2012 the calibration guide and the final data products (calibrated science <br />
data: IRAS16293_Band9_CalibratedMS_FIXED.tgz and reference images: IRAS16293_Band9_ReferenceImages_FIXED.tgz)) <br />
were changed to correct for a 1.2" position error in the phase calibrator (1625-254). Without <br />
correction, the science images will suffer from a similar offset. <br />
</pre><br />
<br />
==Overview==<br />
<br />
This part of the casa guide will guide you through the basic inspection of the data, paying special attention to identifying data that needs to be flagged. The guide shows the complete process to get fully calibrated data.<br />
<br />
The general procedure in this guide follows the other ALMA CASA guides: [[NGC3256Band3]] and [[AntennaeBand7]].<br />
<br />
<br />
==Unpack the Data==<br />
<br />
Once you have downloaded the IRAS16293_Band9_UnCalibratedMS.tgz, unpack the file in a terminal outside CASA using<br />
<br />
<source lang="bash"><br />
<br />
tar -xvzf IRAS16293_Band9_UnCalibratedMS.tgz<br />
<br />
cd IRAS16293_Band9_UnCalibratedMS<br />
<br />
</source><br />
<br />
You have a number of files with extensions ".ms", which are CASA measurement set (MS) files. You will also see files containing system temperature (Tsys), water vapor radiometer (WVR), and antenna position information.<br />
<br />
To start CASA type<br />
<br />
<source lang="bash"><br />
casapy<br />
</source><br />
<br />
Be sure that you are using the right version indicated for this guide.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. Please confirm your version before proceeding. This guide will not work in earlier versions (< r19874).<br />
<source lang="python"><br />
# In CASA<br />
version = casadef.casa_version<br />
print "You are using " + version<br />
if (version < '4.5.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 />
==Install Analysis Utilities==<br />
<br />
Analysis Utilities (or analysisUtils for short) is a small set of Python scripts that provide a number of analysis and plotting utilities for ALMA data reduction. This guide uses a few of these utilities. They are very easy to install (just download and untar). See <br />
<br />
http://casaguides.nrao.edu/index.php?title=Analysis_Utilities<br />
<br />
for a full description and download instructions. If you do not wish to do this, see a CASA 3.3 version of one of the other ALMA guides for alternative (but slow) plotting options. Analysis Utilities are updated frequently so if its been a while since you installed it, it's probably worth doing it again. If you are at an ALMA site or ARC, the analysis utilities are probably already installed and up to date.<br />
<br />
==Initial Inspection==<br />
<br />
The first step we will do through all the calibration process is to define an array with the uid's that correspond to the dataset names. This will allow us to make the calibration of the four datasets one after another, using a for-loop inside python. We will then calibrate the data individually and concatenate them at the end, before proceeding with the imaging part.<br />
<br />
Note that if you exit CASA and want to continue with the calibration using these arrays, you will have to re-issue the command again to make it available for the current CASA execution.<br />
<br />
To start, and give an example of this process, we will create txt format files for the output of the {{listobs}} task, which will give us useful information about the observations.<br />
<br />
<source lang="python"><br />
# Array containing the uid names<br />
<br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# We create the text files for listobs for each dataset<br />
<br />
for data in rawdata:<br />
listobs(vis=data,listfile=data+'.listobs')<br />
</source><br />
<br />
Note that after cutting and pasting a for-loop you often have to press return several times to make the command execute. The output will be sent to the CASA logger. Next, we show an example of a useful part of the output that the first listobs command produces.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 11<br />
ID Code Name RA Decl Epoch SrcId nVis <br />
0 none 1924-292 19:24:51.05600 -29.14.30.1280 J2000 0 169125 <br />
1 none nrao530 ph 17:33:02.72400 -13.04.49.4860 J2000 1 289170 <br />
2 none Juno 16:25:31.63031 -05.49.08.9209 J2000 2 82890 <br />
3 none 1625-254 16:25:46.98000 -25.27.38.3300 J2000 3 276480 <br />
4 none IRAS16293-2422-a 16:32:22.99200 -24.28.36.0000 J2000 4 132450 <br />
5 none IRAS16293-2422-a 16:32:22.47925 -24.28.36.0000 J2000 4 99915 <br />
6 none IRAS16293-2422-a 16:32:22.73563 -24.28.36.0000 J2000 4 99960 <br />
7 none IRAS16293-2422-a 16:32:22.73563 -24.28.32.5000 J2000 4 99915 <br />
8 none IRAS16293-2422-a 16:32:22.47925 -24.28.29.0000 J2000 4 99945 <br />
9 none IRAS16293-2422-a 16:32:22.73563 -24.28.29.0000 J2000 4 99945 <br />
10 none IRAS16293-2422-a 16:32:22.99200 -24.28.29.0000 J2000 4 99915 <br />
(nVis = Total number of time/baseline visibilities per field) <br />
Spectral Windows: (25 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 128 TOPO 231257.813 15625 2000000 XX YY <br />
2 1 TOPO 232234.375 1796875 1796875 XX YY <br />
3 128 TOPO 229257.813 15625 2000000 XX YY <br />
4 1 TOPO 230234.375 1796875 1796875 XX YY <br />
5 128 TOPO 217242.188 15625 2000000 XX YY <br />
6 1 TOPO 216234.375 1796875 1796875 XX YY <br />
7 128 TOPO 215242.188 15625 2000000 XX YY <br />
8 1 TOPO 214234.375 1796875 1796875 XX YY <br />
9 128 TOPO 703257.813 15625 2000000 XX YY <br />
10 1 TOPO 704234.375 1796875 1796875 XX YY <br />
11 128 TOPO 692492.188 15625 2000000 XX YY <br />
12 1 TOPO 691484.375 1796875 1796875 XX YY <br />
13 128 TOPO 690492.188 15625 2000000 XX YY <br />
14 1 TOPO 689484.375 1796875 1796875 XX YY <br />
15 128 TOPO 688492.188 15625 2000000 XX YY <br />
16 1 TOPO 687484.375 1796875 1796875 XX YY <br />
17 3840 TOPO 703312.744 488.28125 1875000 XX YY <br />
18 1 TOPO 704249.756 1875000 1875000 XX YY <br />
19 3840 TOPO 692237.256 488.28125 1875000 XX YY <br />
20 1 TOPO 691299.756 1875000 1875000 XX YY <br />
21 3840 TOPO 690437.256 488.28125 1875000 XX YY <br />
22 1 TOPO 689499.756 1875000 1875000 XX YY <br />
23 3840 TOPO 688437.256 488.28125 1875000 XX YY <br />
24 1 TOPO 687499.756 1875000 1875000 XX YY <br />
<br />
Antennas: 15:<br />
ID Name Station Diam. Long. Lat. <br />
0 DA41 A003 12.0 m -067.45.16.5 -22.53.27.0 <br />
1 DA43 A075 12.0 m -067.45.17.9 -22.53.21.4 <br />
2 DA47 A026 12.0 m -067.45.18.8 -22.53.28.3 <br />
3 DV02 A077 12.0 m -067.45.10.1 -22.53.25.9 <br />
4 DV03 A137 12.0 m -067.45.15.2 -22.53.22.7 <br />
5 DV05 A082 12.0 m -067.45.08.3 -22.53.29.2 <br />
6 DV07 A076 12.0 m -067.45.20.5 -22.53.33.8 <br />
7 DV09 A046 12.0 m -067.45.17.0 -22.53.29.3 <br />
8 DV10 A071 12.0 m -067.45.19.9 -22.53.23.5 <br />
9 DV12 A011 12.0 m -067.45.14.4 -22.53.28.4 <br />
10 DV13 A072 12.0 m -067.45.12.6 -22.53.24.0 <br />
11 DV14 A025 12.0 m -067.45.18.7 -22.53.27.4 <br />
12 DV15 A074 12.0 m -067.45.12.1 -22.53.32.0 <br />
13 DV17 A138 12.0 m -067.45.17.1 -22.53.34.4 <br />
14 DV18 A053 12.0 m -067.45.17.3 -22.53.31.2 <br />
</pre><br />
<br />
In the previous output you can see the ID that is assigned to each source, starting with the number 0. 1924-292 and 3c279 are the calibrators for bandpass, Juno for amplitude (flux), 1625-254 is our phase calibrator and nrao530 ph serves as a check (phase calibrator) source. The remaining 7 fields of IRAS16293-2422-a are the seven pointings for our mosaic of the target source.<br />
<br />
Spectral windows are also marked with numbers from 0 to 24, with number 0 containing WVR information. Spws 17, 19, 21, and 23 contain the science data (FDM mode). The CO (6-5) line emission is contained in spw 19. Spw 18, 20, 22, and 24 contain channel averages of the data from spectral windows 17, 19, 21, 23, respectively. These spws will not be used for the offline data reduction. All the remaining spws that appear in the section of "Sources", and that do not appear in the "Spectral Windows" section are related to WVR measurements for each antenna, so you will not need them for the calibration either. Spws 9, 11, 13, and 15 are associated with tsys measurements, and we will apply these measurements to the science spws later.<br />
<br />
Finally before we go further we explicitly save the current flag state of the data. If you ever decide to start completely over, you should substitute 'restore' for 'save' in the command below to restore the flag state to its original value.<br />
<br />
<source lang="python"><br />
# Use flagmanager to save current flag state.<br />
<br />
for vis in rawdata:<br />
flagmanager(vis=vis,mode='save',versionname='OriginalFlagState')<br />
</source><br />
<br />
== Generation and visualization of the antenna positions, Tsys and WVR tables ==<br />
<br />
Next we will generate the tables we need to apply to the data: antenna position, system temperature and water vapor radiometer. Once the tables are generated we will produce plots of them and inspect them to make sure whether they have issues that might affect their application to the data. Whenever we see an odd behavior in the tables we need to flag the corresponding science data to prevent wrong results in the calibration steps. <br />
<br />
=== System Temperature ===<br />
We produce the Tsys tables with the next command<br />
<br />
<source lang="python"><br />
# Create Tsys<br />
os.system('rm -rf *tdm.tsys')<br />
for vis in rawdata:<br />
print "Creating TDM Tsys Table for "+vis<br />
gencal(vis=vis,caltable=vis+'.tdm.tsys',spw='9,11,13,15',caltype='tsys')<br />
</source><br />
<br />
The next command will plot the tsys in the next way: it will produce many plots, each one of them will show an antenna, with the four spws that the tsys tables cover, for all the targets, and with different colors for different times, so you can trace the behavior for tsys with time, among others.<br />
Note that in spw 19, the overlap with the tsys spw (11) is not set correctly. This is due to an error in the frequencies for the tsys when the observations were done. You do not have to worry about this, since any issue coming from that error has already been fixed. Note, however that the portions of the spectra that do not have tsys information cannot be used. This does not represent a problem, since that part corresponds to the edge of the baseband. Also note that the CO (6-5) line is not affected by this.<br />
In Figure 1 you will see the corresponding plot for one of the datasets (X90c) showing antenna 0 (DA41).<br />
<br />
[[File:uid___A002_X3d55cb_X90c.mstsys.DA41.spw0.png|200px|thumb|right|'''Fig. 1.''' Example for the output of the command that plots the tsys spws. Find a description in the text.]]<br />
<br />
<br />
<source lang="python"><br />
# Plot TDM Tsys tables with times overlayed for each antenna<br />
os.system('rm -rf Tsysplots/*time*')<br />
for vis in rawdata:<br />
plotbandpass(caltable=vis+'.tdm.tsys',vis=vis,<br />
overlay='time', xaxis='freq', showatm=True,<br />
yaxis='amp',subplot=22,interactive=False,<br />
chanrange='5~122',showfdm=True,<br />
figfile='Tsysplots/'+vis+'.time.tdm.tsys.png')<br />
</source><br />
<br />
Another useful set of plots is generated by the next command. Each resulting plot shows all the antennas in a scan, for one spectral windows. This is useful to check Tsys for all the antennas in a certain time. In Figure 2 you can see an example.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.ms.antenna.tdm.tsys.spw9.t1.png|200px|thumb|right|'''Fig. 2.''' Second sample plot for tsys plotting. The first four scans of the observations for spw 17 are shown, with all the antennas per plot.]]<br />
<br />
<source lang="python"><br />
# Plot TDM Tsys tables with antennas overlayed for each time <br />
os.system('rm -rf Tsysplots/*antenna*')<br />
for vis in rawdata:<br />
plotbandpass(caltable=vis+'.tdm.tsys',vis=vis,<br />
overlay='antenna', xaxis='freq', showatm=True,<br />
yaxis='amp',subplot=22,interactive=False,<br />
chanrange='5~122',showfdm=True,<br />
figfile='Tsysplots/'+vis+'.antenna.tdm.tsys.png')<br />
</source><br />
<br />
Go through all the plots and make sure you notice all the next issues, since we will need to flag the corresponding science data.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
X90c<br />
DV05 ripples all spw <br />
Otherwise 600 to 1200 47 to 57% transmission<br />
<br />
X575<br />
Otherwise 1300 to 3000 28 to 39% transmission<br />
DV05 ripples all spw <br />
<br />
Xb50<br />
800 to 2500 37 to 47% transmission<br />
DV05 ripples all spw <br />
<br />
X39b<br />
500 to 800 56 to 65%<br />
DA43 Tsys extremely high for spw=23<br />
DV05 ripples all spw and one time with bad YY <br />
DV18 extremely high for spw=23<br />
</pre><br />
<br />
=== Water Vapor Radiometer ===<br />
We now generate the WVR tables by executing <br />
<br />
<source lang="python"><br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# Other values can be left at defaults<br />
os.system('rm -rf *.wvrgcal')<br />
for vis in rawdata:<br />
wvrgcal(vis=vis,caltable=vis+'.wvr',toffset=-1)<br />
</source><br />
<br />
The integration time for the science spectral windows is 6.048 seconds. So we need to average the WVR 1 second solutions to match.<br />
<br />
<source lang="python"><br />
# Smoothing the data<br />
for vis in rawdata:<br />
print "Smoothing wvr table for "+vis<br />
smoothcal(vis=vis,tablein=vis+'.wvr',caltable=vis+'.wvr.smooth',<br />
smoothtype='mean',smoothtime=6.048)<br />
</source><br />
<br />
Now, for the plotting of the wvr tables, we will employ the Analysis utils package. This command will create a directory with all the plots inside, each one of them corresponding to different datasets, baselines and targets, using different colors. In Figure 3 you can see an example of the output for spectral window 1. Note that the command below only creates the plots for that spw, since the others are the same except for a scale factor that is the ratio of frequencies.<br />
Note that in all datasets, DV15 has bad wvr behavior.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.ms.wvr.smooth.2.png|200px|thumb|right|'''Fig. 3.''' Phase corrections as function of time for the dataset X90c, where you can see an example of the odd behavior of DV15-related baselines.]]<br />
<br />
<source lang="python"><br />
# Plotting wvr tables for spw 1<br />
os.system('rm -rf WVRplots')<br />
for vis in rawdata:<br />
au.plotWVRSolutions(caltable=vis+'.wvr.smooth',<br />
yrange=[-180,180],figfile='WVRplots/'+vis+'.wvr.smooth.png',<br />
ms=vis,spw='1',interactive=False)<br />
</source><br />
<br />
=== Antenna position ===<br />
Finally, we need to create the tables to correct for the antenna positions. For that, execute<br />
<br />
<source lang="python"><br />
# Generate the tables for antenna positions<br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# For the data taken on April 16<br />
antennas='DV18,DV12,DV09,DV10,DV13,DV05,DA41,DV14,DA43,DV17,DV07,DV15'<br />
parameter=[0.00684754783288,-0.0188271608204,-0.00732900947332,<br />
0.000481227821554,-2.48519197708e-05,-0.00048066949752,<br />
0.000741523189806,-0.000843518709779,-0.000409113120338,<br />
0.00111751207514,-0.000891124202747,-0.000492116263895,<br />
0.00100313175518,-0.00084909900337,-0.000594194887412,<br />
0.00105206234994,-0.000857719516042,-0.00059565765641,<br />
0.00060776527971,-0.000525096431375,-0.000386487226933,<br />
0.000521688542419,-0.000144920371688,-0.000258341151538,<br />
0.00104740676978,-0.000899314162014,-0.000483014592547,<br />
0.000920921096116,-0.00106288533016,-0.000546355296173,<br />
0.000867350985729,-0.000990079062422,-0.00038123971161,<br />
0.000567245762795,-0.000422531738877,-0.000741700641811]<br />
gencal(vis = 'uid___A002_X3d4118_X39b.ms',<br />
caltable = 'uid___A002_X3d4118_X39b.ms.antpos',<br />
caltype = 'antpos',antenna=antennas,parameter=parameter)<br />
<br />
# and for April 17<br />
antennas='DV05,DV09,DV10,DV13,DV12,DA41,DV14,DA43,DV17,DV07,DV15'<br />
parameter=[0.00105206234994,-0.000857719516042,-0.00059565765641,<br />
0.000741523189806,-0.000843518709779,-0.000409113120338,<br />
0.00111751207514,-0.000891124202747,-0.000492116263895,<br />
0.00100313175518,-0.00084909900337,-0.000594194887412,<br />
0.000481227821554,-2.48519197708e-05,-0.00048066949752,<br />
0.00060776527971,-0.000525096431375,-0.000386487226933,<br />
0.000521688542419,-0.000144920371688,-0.000258341151538,<br />
0.00104740676978,-0.000899314162014,-0.000483014592547,<br />
0.000920921096116,-0.00106288533016,-0.000546355296173,<br />
0.000867350985729,-0.000990079062422,-0.00038123971161,<br />
0.000567245762795,-0.000422531738877,-0.000741700641811]<br />
for vis in range(1,4):<br />
gencal(vis=rawdata[vis],<br />
caltable=rawdata[vis]+'.antpos',<br />
caltype ='antpos',antenna=antennas,parameter=parameter)<br />
</source><br />
<br />
Now, based on the behavior of the tsys and wvr tables, we will flag the corresponding data, using the next commands. You can employ similar executions to flag other data you might want to remove.<br />
<br />
<source lang="python"><br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
<br />
# Flagging corresponding science data for tsys and wvr showing problems<br />
for vis in rawdata:<br />
flagdata(vis=vis,autocorr = True,flagbackup = False)<br />
flagdata(vis=vis,mode='shadow',flagbackup=False)<br />
flagdata(vis=vis,antenna='DV05,DV15',flagbackup=False)<br />
<br />
vis='uid___A002_X3d4118_X39b.ms'<br />
flagdata(vis=vis,antenna='DA43,DV18',spw='23',flagbackup=False)<br />
<br />
</source><br />
<br />
== Applying antpos, tsys, and wvr tables and splitting the data ==<br />
<br />
To apply the Tsys tables we need to separate sources that have Tsys measurements of their own from those that do not. Since only one IRAS16293 field (id=4) has Tsys, it goes into<br />
the "not" category. As you probably noted from the messages from<br />
plotbandpass, the Tsys measurements on Juno did not yield usable<br />
values, causing them to be flagged, so we will apply the nearest<br />
source in elevation to it: IRAS16293 field id=4. This can be checked <br />
with the plots generated by the following {{plotms}} commands. <br />
In Figure 4 you can see the output of this command for Xb50.<br />
<br />
[[File:uid___A002_X3d55cb_Xb50.antwvrtsys.mselevation.png|200px|thumb|right|'''Fig. 4.''' Elevation for all the sources versus time for Xb50. Note that this dataset has very low elevations.]]<br />
<br />
<source lang="python"><br />
# Re-entering our array<br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
# Elevation plots to understand what the elevation range for each dataset is.<br />
for vis in rawdata:<br />
plotms(vis=vis, <br />
field='',xaxis='time', yaxis='elevation',antenna='',<br />
spw='17', avgchannel='3840',coloraxis='field',<br />
ydatacolumn='data',plotfile=vis+'elevation.png',title=vis)<br />
</source><br />
<br />
To apply the Tsys we need to explicitly tell {{applycal}} which TDM (128<br />
channels) spws go with which FDM spw (3840 channels). An entry is needed<br />
for every spw, because the position in the list corresponds to the<br />
spw id to be corrected.<br />
There is a helper function to assist you in figuring this out. <br />
<br />
<source lang="python"><br />
from recipes.almahelpers import tsysspwmap<br />
tsysspwmap(vis='uid___A002_X3d4118_X39b.ms',<br />
tsystable='uid___A002_X3d4118_X39b.ms.tdm.tsys')<br />
<br />
# This will print:<br />
# [0,1,2,3,4,5,6,7,8,9,9,11,11,13,13,15,15,9,9,19,20,13,13,15,15]<br />
</source><br />
<br />
The helper gets a little confused in this case with spws 19 and 20<br />
because the FDM was not perfectly positioned within the TDM window<br />
as you can see from the Tsys plots. In a case like this, we need to<br />
put in by hand the TDM window that should match the FDM window.<br />
<br />
As you could see from the first run of listobs, 1924-292 is the bandpass calibrator for three of the datasets, and 3c279 is for one of them. For this reason, the application of the tables is split into two parts.<br />
<br />
For the {{applycal}} task, note that the first value in the interp parameter for each gaintable gives the desired time interpolation type. The second parameter indicates the<br />
desired frequency axis interpolation. If the second value is not set<br />
it is assumed to be linear, but only if the input table has a<br />
frequency axis (like Tsys and Bandpass). Spline seems to work best<br />
for the Tsys TDM to FDM frequency interpolation.<br />
<br />
<source lang="python"><br />
rawdata=['uid___A002_X3d4118_X39b.ms','uid___A002_X3d55cb_X575.ms',<br />
'uid___A002_X3d55cb_Xb50.ms','uid___A002_X3d55cb_X90c.ms']<br />
<br />
tsysspw=[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 />
<br />
# Datasets with 1924-292 as the bandpass calibrator<br />
for vis in [rawdata[0],rawdata[2],rawdata[3]]:<br />
print "Applying calibration for "+vis<br />
field_Tsys=['1924-292','nrao530 ph']<br />
for field in field_Tsys:<br />
print "For Field= "+field<br />
applycal(vis=vis,field=field,<br />
spw = '17,19,21,23',<br />
gaintable = [vis+'.tdm.tsys', <br />
vis+'.wvr.smooth', <br />
vis+'.antpos'],<br />
gainfield = [field,field,''],<br />
spwmap=[tsysspw,[],[]],<br />
interp = ['linear,spline','nearest',''],calwt = True,<br />
flagbackup = False)<br />
<br />
<br />
# This next applycal takes care of the fact that one dataset has 3C279<br />
# instead of 1924-292 as the bandpass calibrator <br />
<br />
for vis in [rawdata[1]]:<br />
print "Applying calibration for "+vis<br />
field_Tsys=['3c279','nrao530 ph']<br />
for field in field_Tsys:<br />
print "For Field= "+field<br />
applycal(vis=vis,field=field,<br />
spw = '17,19,21,23',<br />
gaintable = [vis+'.tdm.tsys', <br />
vis+'.wvr.smooth', <br />
vis+'.antpos'],<br />
gainfield = [field,field,''],<br />
spwmap=[tsysspw,[],[]],<br />
interp = ['linear,spline','nearest',''],calwt = True,<br />
flagbackup = False)<br />
<br />
# Next we do the "noTsys" sources for all datasets<br />
<br />
for vis in rawdata:<br />
print "Applying calibration for "+vis<br />
field_noTsys=['Juno','1625-254','IRAS16293*']<br />
for field in field_noTsys:<br />
print "For Field= "+field<br />
applycal(vis =vis,field=field,<br />
spw = '17,19,21,23',<br />
gaintable = [vis+'.tdm.tsys', <br />
vis+'.wvr.smooth', <br />
vis+'.antpos'],<br />
gainfield = ['4',field,''],<br />
spwmap=[tsysspw,[],[]],<br />
interp = ['linear,spline','nearest',''],calwt = True,<br />
flagbackup = False)<br />
<br />
# Splitting the science spws<br />
<br />
for vis in rawdata:<br />
split(vis=vis,outputvis=('%s.antwvrtsys.ms'%(vis.split('.')[0])),<br />
datacolumn='corrected',spw='17,19,21,23',keepflags=False)<br />
</source><br />
<br />
== Fix Phase Calibrator Position ==<br />
<br />
The position used for the phase calibrator (1625-254) in these observations is offset by about 1.2"<br />
toward postive R.A from its correct position. Below we correct the data for this offset. It is best to do this step before doing any of the gain calibration. It is notable that simply shifting the images for this offset will not give as correct a result due to phase delays caused by sky rotation during the course of each observation.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms']<br />
</source><br />
<br />
List the data to see current position of 1625-254<br />
<br />
<source lang="python"><br />
for vis in data:<br />
listobs(vis=vis,listfile=vis+'.listobs',verbose=True)<br />
</source><br />
<br />
Incorrect position from listobs: 1625-254 16h25m46.98000s -25d27m38.3300s J2000<br />
<br />
From the [http://www.vla.nrao.edu/astro/calib/manual/csource.html<br />
EVLA calibrator manual] we find that the correct position is: 16h25m46.891639s -25d27m38.326880s J2000<br />
<br />
Next use the task fixvis to correct the position of the calibrator in<br />
the data and the header. It will also recalculate UVWs, but this<br />
correction is very small for a 1.2" shift.<br />
<br />
<source lang="python"><br />
for vis in data:<br />
fixvis(vis=vis,outputvis=vis+'.fixed',field='1625-254',reuse=False,<br />
phasecenter='J2000 16h25m46.891639s -25d27m38.326880s',<br />
datacolumn='DATA')<br />
</source><br />
<br />
== Data inspection ==<br />
<br />
We now need to check for any bad behavior in the data through several plots. Once problems are identified, data can be flagged. But before that, we need to run again {{listobs}} to check that the split and calibrator position correction worked as expected. We will define our new array of split and corrected datasets.<br />
<br />
<source lang="python"><br />
# New array of datasets <br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
<br />
for vis in data:<br />
listobs(vis=vis,listfile=vis+'.listobs',verbose=True)<br />
</source><br />
<br />
You can explore any of the output files by doing <tt>cat file.listobs</tt> or using any other text reader from a terminal not running CASA. Next you can see the output for X90c, and you will see the change in the spw naming, among others.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Fields: 11<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 1924-292 19:24:51.05600 -29.14.30.1280 J2000 0 11000 <br />
1 none nrao530 ph 17:33:02.72400 -13.04.49.4860 J2000 1 19800 <br />
2 none Juno 16:25:05.61170 -05.43.27.9210 J2000 2 8800 <br />
3 none 1625-254 16:25:46.89164 -25.27.38.3269 J2000 3 22000 <br />
4 none IRAS16293-2422-a 16:32:22.99200 -24.28.36.0000 J2000 4 9900 <br />
5 none IRAS16293-2422-a 16:32:22.47925 -24.28.36.0000 J2000 4 9900 <br />
6 none IRAS16293-2422-a 16:32:22.73563 -24.28.36.0000 J2000 4 9900 <br />
7 none IRAS16293-2422-a 16:32:22.73563 -24.28.32.5000 J2000 4 9900 <br />
8 none IRAS16293-2422-a 16:32:22.47925 -24.28.29.0000 J2000 4 8800 <br />
9 none IRAS16293-2422-a 16:32:22.73563 -24.28.29.0000 J2000 4 8800 <br />
10 none IRAS16293-2422-a 16:32:22.99200 -24.28.29.0000 J2000 4 8800 <br />
Spectral Windows: (4 unique spectral windows and 1 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 3840 TOPO 703312.744 488.28125 1875000 XX YY <br />
1 3840 TOPO 692237.256 -488.28125 1875000 XX YY <br />
2 3840 TOPO 690437.256 -488.28125 1875000 XX YY <br />
3 3840 TOPO 688437.256 -488.28125 1875000 XX YY <br />
Sources: 20<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 1924-292 0 - - <br />
0 1924-292 1 - - <br />
0 1924-292 2 - - <br />
0 1924-292 3 - - <br />
1 Juno 0 - - <br />
1 Juno 1 - - <br />
1 Juno 2 - - <br />
1 Juno 3 - - <br />
2 1625-254 0 - - <br />
2 1625-254 1 - - <br />
2 1625-254 2 - - <br />
2 1625-254 3 - - <br />
3 nrao530 ph 0 - - <br />
3 nrao530 ph 1 - - <br />
3 nrao530 ph 2 - - <br />
3 nrao530 ph 3 - - <br />
4 IRAS16293-2422-a 0 - - <br />
4 IRAS16293-2422-a 1 - - <br />
4 IRAS16293-2422-a 2 - - <br />
4 IRAS16293-2422-a 3 - - <br />
Antennas: 11:<br />
ID Name Station Diam. Long. Lat. <br />
0 DA41 A003 12.0 m -067.45.16.5 -22.53.27.0 <br />
1 DA43 A075 12.0 m -067.45.17.9 -22.53.21.4 <br />
2 DV02 A077 12.0 m -067.45.10.1 -22.53.25.9 <br />
3 DV03 A137 12.0 m -067.45.15.2 -22.53.22.7 <br />
5 DV07 A076 12.0 m -067.45.20.5 -22.53.33.8 <br />
6 DV09 A046 12.0 m -067.45.17.0 -22.53.29.3 <br />
7 DV10 A071 12.0 m -067.45.19.9 -22.53.23.5 <br />
8 DV12 A011 12.0 m -067.45.14.4 -22.53.28.4 <br />
9 DV13 A072 12.0 m -067.45.12.6 -22.53.24.0 <br />
10 DV14 A025 12.0 m -067.45.18.7 -22.53.27.4 <br />
12 DV17 A138 12.0 m -067.45.17.1 -22.53.34.4 <br />
</pre><br />
<br />
Next, we give you a set of useful {{plotms}} commands which will help you to analyze all the data in several ways. You can save a copy of the output, so you do not have to run them again every time you want to check them. This is especially useful for the plots that take a lot of time to generate. To save time we only plot data from the 1st of our 4 measurement sets. In a real data reduction process you would want to inspect plots for all your measurement sets.<br />
<br />
In Figure 5 you can see the output of the following plotms command for data set X39b. By clicking the green arrows in the plotms window you can access all the spws.<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.time.spw0.png|200px|thumb|right|'''Fig. 5.''' {{plotms}} result for amplitude vs time for all the sources, which are displayed with different colors. The plot shows spw 0 for the dataset X39b.]]<br />
<br />
<source lang="python"><br />
# Check overall behavior with time<br />
vis=data[0]<br />
plotms(vis=vis, <br />
field='',xaxis='time', yaxis='amp',antenna='',<br />
spw='', avgchannel='3840',coloraxis='field',<br />
iteraxis='spw',ydatacolumn='data',yselfscale=True)<br />
</source><br />
For the next set of plotms commands, inspect each dataset, noting any problems that you notice.<br />
<br />
<source lang="python"><br />
# For at least one spw go antenna by antenna to look for dropouts not<br />
# obvious in previous plot<br />
vis=data[0]<br />
plotms(vis=vis, <br />
field='',xaxis='time', yaxis='amp',antenna='',<br />
spw='2', avgchannel='3840',coloraxis='field',<br />
iteraxis='antenna',ydatacolumn='data')<br />
<br />
# Check out spectral properties of each source for problems<br />
vis=data[0]<br />
plotms(vis=vis, <br />
field='',xaxis='freq', yaxis='amp',antenna='',<br />
spw='', avgtime='1e8',avgscan=True,coloraxis='spw',<br />
iteraxis='field',ydatacolumn='data',yselfscale=True)<br />
<br />
# Examine phase of the bandpass calibrator for any problems<br />
vis=data[0]<br />
bp='1924-292'<br />
plotms(vis=vis, <br />
field=bp,xaxis='freq', yaxis='phase',antenna='',<br />
spw='', avgtime='1e8',avgscan=True,avgchannel='10',coloraxis='spw',<br />
iteraxis='baseline',ydatacolumn='data',yselfscale=True)<br />
</source><br />
<br />
== Flagging ==<br />
<br />
Next, based on our inspection we will proceed with the corresponding flagging. But before that, we will save the current flags state, so we can recover it later, if needed.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
<br />
# Back up flag state in case you want to start over.<br />
for vis in data:<br />
flagmanager(vis=vis,mode='save',versionname='Original')<br />
<br />
# If you do start over run this first<br />
for vis in data:<br />
flagmanager(vis=vis,mode='restore',versionname='Original')<br />
</source><br />
<br />
During the procedure of calibration, below, some problems in the data will show up. Those data need to be flagged and then the calibration should be repeated. In order to save you time, we will flag those data now.<br />
<br />
<source lang="python"><br />
# PROBLEMS DISCOVERED AFTER INITIAL CALIBRATION INSPECTION<br />
<br />
# flag low elevation scans on 1625-254 and IRAS16293<br />
flagdata(vis='uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed',<br />
timerange='>11:54:00', field='',flagbackup=False)<br />
<br />
# flag low gains on DV02 on Juno<br />
flagdata(vis='uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed',<br />
antenna='DV02', field='Juno',flagbackup=False)<br />
<br />
flagdata(vis='uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
antenna='DV02', field='Juno',flagbackup=False)<br />
</source><br />
<br />
== Calibration ==<br />
<br />
Now we can start with the calibration itself. First, we will perform the bandpass calibration using 1924-292 and 3c279. As before, we define our list of data and match the sources with intents. Also, we will set our reference antenna (one close to the center of the array and without problems, like delays). As you can see, two different intervals for channels are used, which will make sense in a bit.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
calfields=['1924-292,Juno,1625-254,nrao530*',<br />
'3c279,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*']<br />
<br />
# Setup calibration parameters<br />
prebpchan='0~3:1200~1500'<br />
calchan='0~3:20~3820'<br />
refant='DV14'<br />
gaps=5<br />
os.system('rm -rf *cal')<br />
</source><br />
Note that if at some point during the calibration process you need to start over, then you will need to clear all the columns for solutions in the data, as shown next.<br />
<br />
<source lang="python"><br />
for vis in range(len(data)):<br />
delmod(vis=data[vis])<br />
setjy(vis=data[vis],field=fluxcal,standard='Butler-JPL-Horizons 2010',<br />
scalebychan=True,usescratch=False)<br />
</source><br />
<br />
[[File:Horizons2010JunoCASA4.0.png|200px|thumb|right|'''Fig. 6.''' Plot of Juno model for each of the 4 spws. We used the Butler-JPL-Horizons 2010 standard to compute this model.]]<br />
<br />
[[File:Horizons2012JunoCASA4.0.png|200px|thumb|right|'''Fig. 7.''' Juno model produced by 'Butler-JPL-Horizons 2012'.]]<br />
<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation, above, uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. Figure 7 shows the Juno model produced using the updated standard. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
<br />
Now we proceed with the bandpass calibration, which will be done in two steps. In the first one, we will use a small block of channels in the center of the spws, 1200~1500, to calculate gains in phase, using a solution interval of 30 seconds. This will give us the variation of the phase throughout the observation. We will use this table later to execute the {{bandpass}} itself. Note that we are using a minimum signal to noise ratio of 2 to accept the solutions. This is low but necessary since the calibrators are not very strong in band 9.<br />
<br />
<source lang="python"><br />
# Calculating phase variation with time<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.bpphase.gcal',<br />
field=bpcal[vis],spw=prebpchan,refant=refant,<br />
calmode='p',solint='30s',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
Next, we set our bandpass command to use our previously generated gain tables. Since we do not have a high signal to noise ratio per channel, we use a polynomial option to calculate the solutions for the bandpass. In the {{bandpass}} task, the options degamp and degphase will set the maximum degree of the polynomial that the task can use to calculate solutions. In the work log you can note what is the actual degree that the task is using. Note that the combination of solint='inf' and combine='scan' will result in one solution per scan for the calibrator.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.bandpass_bpoly.DV09.spw0.t1_34.png|200px|thumb|right|'''Fig. 8.''' Bandpass solutions for the dataset X90c (all 4 spws) showing antenna DV09. Both amplitude and phases solutions are plotted. These data use the weaker bandpass calibrator J1924-224.]]<br />
<br />
[[File:uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.bandpass_bpoly.DV09.spw0.t1.png|200px|thumb|right|'''Fig. 9.''' Bandpass solutions for the dataset X575 (all 4 spws) showing antenna DV09. Both amplitude and phases solutions are plotted. These data use the stronger bandpass calibrator 3C279.]]<br />
<br />
<br />
<source lang="python"><br />
# Bandpass calibration using previous tables as input<br />
for vis in range(len(data)):<br />
bandpass(vis=data[vis],caltable=data[vis]+'.bandpass.bcal',<br />
field=bpcal[vis],spw='',combine='scan',refant=refant,<br />
solint='inf',solnorm=True,minblperant=4,fillgaps=gaps,<br />
gaintable=[data[vis]+'.bpphase.gcal'])<br />
<br />
for vis in range(len(data)):<br />
bandpass(vis=data[vis],caltable=data[vis]+'.bandpass_bpoly.bcal',<br />
field=bpcal[vis],spw='',combine='scan',refant=refant,<br />
solint='inf',solnorm=True,minblperant=4,fillgaps=gaps,<br />
bandtype='BPOLY',degamp=7,degphase=7,<br />
gaintable=[data[vis]+'.bpphase.gcal'])<br />
</source><br />
<br />
To plot all our tables we will use plotbandpass and {{plotcal}}. The plotbandpass command will create plot files for each combination of dataset and antenna, for both amplitude and phase. Inspect all these plots to make sure that the bandpass solutions look good.<br />
In Figures 8 and 9 we show an output sample for this command for the two bandpass calibrators used -- note how noisy the weaker bandpass calibrator (J1924) is without BPOLY.<br />
<br />
<source lang="python"><br />
# Set some plotting things<br />
SPW=['0','1','2','3']<br />
numants=15 # max for any of the input datasets<br />
os.system('rm -rf cal_plots')<br />
os.system('mkdir cal_plots')<br />
<br />
os.system('rm -rf cal_plots/*bandpass_bpoly.bcal.*png')<br />
for vis in range(len(data)):<br />
plotbandpass(caltable=data[vis]+'.bandpass.bcal',<br />
caltable2=data[vis]+'.bandpass_bpoly.bcal',<br />
field=bpcal[vis],xaxis='freq',yaxis='both',<br />
figfile='cal_plots/'+data[vis]+'.bandpass_bpoly.png',<br />
interactive=False,subplot=42)<br />
</source><br />
<br />
The next step in the calibration is to calculate amplitude and phase gains vs time for our calibrators. The ideal case here is to have a solution per integration of the data, but in this case we will need to use a solution interval of 30 seconds to avoid having many failed solutions, especially in the weak phase calibrator. First, we will calculate gains for phase and later using that information, we will solve for amplitude and phase. In all the next three executions we are using the bandpass calibration table, as it provides the gains for phase and amplitude vs frequency.<br />
<br />
<source lang="python"><br />
#Using 30s (5 integrations) per solution to avoid many failed solution of the weak calibrator.<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.intphase.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='p',solint='30s',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal'])<br />
</source><br />
To plot our *.intphase.gcal tables we use the next command, which will create files containing the phase gains vs time for all the antennas and for all the datasets.<br />
In Figure 10 we show an example of such plots. Again, you will need to check all plots to make sure the solutions are good. To speed things up, we will loop over the antenna indices and plot 5 antennas per page. Some of the antennas were completely flagged prior to running {{split}}; plots for those antennas will be empty.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.intphase.gcal.spw0.ant5_9.png|200px|thumb|right|'''Fig. 10.''' Phase gain solutions vs time for 5 antennas for all calibrators in the case of X90c.]]<br />
<br />
<source lang="python"><br />
# Plotting phase gains vs time<br />
os.system('rm -rf cal_plots/*intphase*png')<br />
for vis in data:<br />
for spw in SPW:<br />
for antenna in range(0,numants,5): <br />
plotcal(caltable=vis+'.intphase.gcal',<br />
xaxis='time',yaxis='phase',antenna='%d~%d'%(antenna,antenna+4),<br />
iteration='antenna',subplot=511,poln='',spw=spw,<br />
showgui=False,<br />
figfile='cal_plots/'+vis+'.intphase.gcal.spw%s.ant%d_%d.png'%(spw,antenna,antenna+4),<br />
fontsize=8.0,plotrange=[0,0,-180,180])<br />
</source><br />
Next we will use gaincal to solve for gain phases for all the calibrators, but this time we will get one single solution per scan.<br />
<br />
<source lang="python"><br />
# Gaincal execution as before, but to get a single solution per scan<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.scanphase.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='p',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal'])<br />
</source><br />
The next command will produce many plots, and like the previous one, you will get one for each dataset and for each antenna. See example in Figure 11.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.scanphase.gcal.spw0.ant5_9.png|200px|thumb|right|'''Fig. 11.''' Phase gain solutions vs time for all the calibrators in the case of X90c showing the same 5 antennas from previous figure. Note that there is only one solution per scan for each source.]]<br />
<br />
<source lang="python"><br />
# Phase vs time plotting for our calibrators<br />
os.system('rm -rf cal_plots/*scanphase*png')<br />
for vis in data:<br />
for spw in SPW:<br />
for antenna in range(0,numants,5):<br />
plotcal(caltable=vis+'.scanphase.gcal',<br />
xaxis='time',yaxis='phase',antenna='%d~%d'%(antenna,antenna+4),<br />
iteration='antenna',subplot=511,poln='',spw=spw,<br />
showgui=False,<br />
figfile='cal_plots/'+vis+'.scanphase.gcal.spw%s.ant%d_%d.png'%(spw,antenna,antenna+4),<br />
fontsize=8.0,plotrange=[0,0,-180,180])<br />
</source><br />
<br />
Finally, in the next {{gaincal}} we will solve for amplitude and phase. We will use the gain phase calibration table produced before. We will get one solution per scan for all our calibrators.<br />
<br />
<source lang="python"><br />
# Gaincal solving for amplitude and phase vs time.<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.amp.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal'])<br />
</source><br />
<br />
We now can check the resulting plots with the next plotcal executions. In Figure 12 we show an example of these plots.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.amp.gcal.spw0.ant5_9.png|200px|thumb|right|'''Fig. 12.''' Gain amplitudes for all the calibrators, as function of time. A plot for X90c is shown with 5 antennas in it. As in the previous plot, there is only one solution per scan for each source.]]<br />
<br />
<source lang="python"><br />
# Plotting gain amplitudes as function of time.<br />
os.system('rm -rf cal_plots/*amp*png')<br />
for vis in data: <br />
for spw in SPW:<br />
for antenna in range(0,numants,5):<br />
plotcal(caltable=vis+'.amp.gcal',<br />
xaxis='time',yaxis='amp',antenna='%d~%d'%(antenna,antenna+4),<br />
iteration='antenna',subplot=511,poln='',spw=spw,<br />
figfile='cal_plots/'+vis+'.amp.gcal.spw%s.ant%d_%d.png'%(spw,antenna,antenna+4),<br />
fontsize=8.0)<br />
</source><br />
<br />
We can plot the same tables but in a different way that will allow us to look for higher abnormal gains in the solutions. With the next command we will get only four plots for each spw. Each of those plots shows all the gains for all the antennas for all the sources (See Figure 13 for an example). Below in the box, there are some comments to focus you on some data, so you can double check. Before continuing, make sure you check all the calibration tables.<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.amp.png|200px|thumb|right|'''Fig. 13.''' Gain amplitudes for all the calibrators, as function of time (X90c), all antennas for each spw. Check for higher gains that deviate from the average.]]<br />
<br />
<source lang="python"><br />
# Look for low or high gains compared to other data<br />
os.system('rm -rf *amp.png')<br />
for vis in data:<br />
plotcal(caltable=vis+'.amp.gcal',<br />
xaxis='time',yaxis='amp',antenna='',field='',<br />
iteration='spw',subplot=411,poln='',spw='',<br />
showgui=False,figfile=vis+'.amp.png')<br />
# X90c good<br />
# X575 one antenna spw=0<br />
# Xb50 end times bad all spws (low el), spw=0 more; low DV02 on Juno<br />
# X39b low DV02 on Juno<br />
</source><br />
<br />
==== Set Absolute Flux Scale ====<br />
<br />
Now that the gain calibration is done, we need to set the flux for our calibrators. For this we will use Juno, our primary flux calibrator. We will do this by using {{fluxscale}}. <br />
We then will transfer the flux information from our phase calibrator to our science target.<br />
For these datasets, we note the following for this step:<br />
The derived flux densities for X39b, X90c, and Xb50 are quite<br />
reasonable. The results for X575 are a little high, probably because<br />
Juno was at low elevation for these observations.<br />
<br />
<source lang="python"><br />
# Setting fluxes<br />
<br />
for vis in range(len(data)):<br />
fluxscale(vis=data[vis],caltable=data[vis]+'.amp.gcal',<br />
fluxtable=data[vis]+'.flux.cal',reference=fluxcal)<br />
</source><br />
<br />
Below we copy the fluxscale numbers from the logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed",caltable="uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.flux.cal",reference="Juno", transfer=[''],listfile="",<br />
append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 1924-292 nrao530 ph 1625-254<br />
Flux density for 1924-292 in SpW=0 is: 2.26282 +/- 0.0615171 (SNR = 36.7836, N = 24)<br />
Flux density for 1924-292 in SpW=1 is: 2.34321 +/- 0.0706187 (SNR = 33.1811, N = 24)<br />
Flux density for 1924-292 in SpW=2 is: 2.20448 +/- 0.056128 (SNR = 39.2759, N = 24)<br />
Flux density for 1924-292 in SpW=3 is: 2.27766 +/- 0.0682751 (SNR = 33.3601, N = 20)<br />
Flux density for nrao530 ph in SpW=0 is: 0.621106 +/- 0.0366187 (SNR = 16.9615, N = 24)<br />
Flux density for nrao530 ph in SpW=1 is: 0.621617 +/- 0.0406897 (SNR = 15.277, N = 24)<br />
Flux density for nrao530 ph in SpW=2 is: 0.60858 +/- 0.0324375 (SNR = 18.7616, N = 24)<br />
Flux density for nrao530 ph in SpW=3 is: 0.61897 +/- 0.0407009 (SNR = 15.2078, N = 20)<br />
Flux density for 1625-254 in SpW=0 is: 0.375472 +/- 0.0270986 (SNR = 13.8558, N = 24)<br />
Flux density for 1625-254 in SpW=1 is: 0.386889 +/- 0.0274299 (SNR = 14.1047, N = 24)<br />
Flux density for 1625-254 in SpW=2 is: 0.409608 +/- 0.0213044 (SNR = 19.2264, N = 24)<br />
Flux density for 1625-254 in SpW=3 is: 0.377672 +/- 0.030287 (SNR = 12.4698, N = 20)<br />
Fitted spectrum for 1924-292 with fitorder=1: Flux density = 2.26513 +/- 0.0349352 (freq=693.582 GHz) spidx=0.146731 +/- 1.8366<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.61668 +/- 0.00356153 (freq=693.582 GHz) spidx=0.518398 +/- 0.692498<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.391202 +/- 0.00893717 (freq=693.582 GHz) spidx=-2.61617 +/- 2.96819<br />
Storing result in uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
##########################################<br />
<br />
##########################################<br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed",caltable="uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.flux.cal",reference="Juno",transfer=[''],listfile="",append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 3c279 nrao530 ph 1625-254<br />
Flux density for 3c279 in SpW=0 is: 10.0473 +/- 0.170083 (SNR = 59.0728, N = 22)<br />
Flux density for 3c279 in SpW=1 is: 10.6211 +/- 0.204771 (SNR = 51.8683, N = 22)<br />
Flux density for 3c279 in SpW=2 is: 10.439 +/- 0.190577 (SNR = 54.7761, N = 22)<br />
Flux density for 3c279 in SpW=3 is: 9.8948 +/- 0.213262 (SNR = 46.3974, N = 22)<br />
Flux density for nrao530 ph in SpW=0 is: 0.900648 +/- 0.0469511 (SNR = 19.1827, N = 22)<br />
Flux density for nrao530 ph in SpW=1 is: 0.954835 +/- 0.0576885 (SNR = 16.5516, N = 22)<br />
Flux density for nrao530 ph in SpW=2 is: 0.868769 +/- 0.0634537 (SNR = 13.6914, N = 22)<br />
Flux density for nrao530 ph in SpW=3 is: 0.898756 +/- 0.0667589 (SNR = 13.4627, N = 22)<br />
Flux density for 1625-254 in SpW=0 is: 0.608887 +/- 0.0545965 (SNR = 11.1525, N = 22)<br />
Flux density for 1625-254 in SpW=1 is: 0.600939 +/- 0.0564496 (SNR = 10.6456, N = 22)<br />
Flux density for 1625-254 in SpW=2 is: 0.564227 +/- 0.0523831 (SNR = 10.7712, N = 22)<br />
Flux density for 1625-254 in SpW=3 is: 0.56677 +/- 0.0646495 (SNR = 8.76681, N = 22)<br />
Fitted spectrum for 3c279 with fitorder=1: Flux density = 10.2668 +/- 0.190218 (freq=693.582 GHz) spidx=-0.993535 +/- 2.11611<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.909081 +/- 0.0219124 (freq=693.582 GHz) spidx=-0.229624 +/- 2.6073<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.585089 +/- 0.00864407 (freq=693.582 GHz) spidx=3.22022 +/- 1.73489<br />
Storing result in uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
##########################################<br />
<br />
##########################################<br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed",caltable="uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.flux.cal",reference="Juno",transfer=[''],listfile="",append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 1924-292 nrao530 ph 1625-254<br />
Flux density for 1924-292 in SpW=0 is: 2.03239 +/- 0.0804821 (SNR = 25.2527, N = 22)<br />
Flux density for 1924-292 in SpW=1 is: 2.14333 +/- 0.0688452 (SNR = 31.1326, N = 22)<br />
Flux density for 1924-292 in SpW=2 is: 2.27019 +/- 0.0630149 (SNR = 36.0262, N = 22)<br />
Flux density for 1924-292 in SpW=3 is: 2.29756 +/- 0.0628644 (SNR = 36.5479, N = 22)<br />
Flux density for nrao530 ph in SpW=0 is: 0.615295 +/- 0.0392509 (SNR = 15.6759, N = 22)<br />
Flux density for nrao530 ph in SpW=1 is: 0.616158 +/- 0.0358843 (SNR = 17.1707, N = 22)<br />
Flux density for nrao530 ph in SpW=2 is: 0.673485 +/- 0.0318436 (SNR = 21.1498, N = 22)<br />
Flux density for nrao530 ph in SpW=3 is: 0.657576 +/- 0.0347543 (SNR = 18.9207, N = 22)<br />
Flux density for 1625-254 in SpW=0 is: 0.414261 +/- 0.0339788 (SNR = 12.1917, N = 22)<br />
Flux density for 1625-254 in SpW=1 is: 0.407031 +/- 0.0278748 (SNR = 14.6021, N = 22)<br />
Flux density for 1625-254 in SpW=2 is: 0.421672 +/- 0.0308659 (SNR = 13.6614, N = 22)<br />
Flux density for 1625-254 in SpW=3 is: 0.408483 +/- 0.0285555 (SNR = 14.3049, N = 22)<br />
Fitted spectrum for 1924-292 with fitorder=1: Flux density = 2.18517 +/- 0.0270747 (freq=693.582 GHz) spidx=-5.83258 +/- 1.68869<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.642359 +/- 0.0134547 (freq=693.582 GHz) spidx=-3.62214 +/- 2.75328<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.412532 +/- 0.00412088 (freq=693.582 GHz) spidx=0.237612 +/- 1.29441<br />
Storing result in uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
##########################################<br />
<br />
##########################################<br />
##### Begin Task: fluxscale #####<br />
fluxscale(vis="uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed",caltable="uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.amp.gcal",<br />
fluxtable="uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.flux.cal",reference="Juno",transfer=[''],listfile="",append=False,refspwmap=[-1],incremental=False,fitorder=1)<br />
Opening MS: uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Beginning fluxscale--(MSSelection version)-------<br />
Assuming all non-reference fields are transfer fields.<br />
Found reference field(s): Juno<br />
Found transfer field(s): 1924-292 nrao530 ph 1625-254<br />
Flux density for 1924-292 in SpW=0 is: 2.43493 +/- 0.0655999 (SNR = 37.118, N = 22)<br />
Flux density for 1924-292 in SpW=1 is: 2.44094 +/- 0.0478862 (SNR = 50.9739, N = 22)<br />
Flux density for 1924-292 in SpW=2 is: 2.27421 +/- 0.0538595 (SNR = 42.2248, N = 22)<br />
Flux density for 1924-292 in SpW=3 is: 2.32056 +/- 0.0551078 (SNR = 42.1094, N = 22)<br />
Flux density for nrao530 ph in SpW=0 is: 0.702695 +/- 0.0511122 (SNR = 13.7481, N = 22)<br />
Flux density for nrao530 ph in SpW=1 is: 0.677135 +/- 0.0392508 (SNR = 17.2515, N = 22)<br />
Flux density for nrao530 ph in SpW=2 is: 0.675852 +/- 0.0422636 (SNR = 15.9913, N = 22)<br />
Flux density for nrao530 ph in SpW=3 is: 0.672319 +/- 0.0403538 (SNR = 16.6606, N = 22)<br />
Flux density for 1625-254 in SpW=0 is: 0.506353 +/- 0.0507682 (SNR = 9.97382, N = 22)<br />
Flux density for 1625-254 in SpW=1 is: 0.479865 +/- 0.0293747 (SNR = 16.336, N = 22)<br />
Flux density for 1625-254 in SpW=2 is: 0.439463 +/- 0.0365189 (SNR = 12.0339, N = 22)<br />
Flux density for 1625-254 in SpW=3 is: 0.444093 +/- 0.0326742 (SNR = 13.5916, N = 22)<br />
Fitted spectrum for 1924-292 with fitorder=1: Flux density = 2.3764 +/- 0.0422989 (freq=693.582 GHz) spidx=2.43015 +/- 2.40572<br />
Fitted spectrum for nrao530 ph with fitorder=1: Flux density = 0.681796 +/- 0.000887152 (freq=693.582 GHz) spidx=2.09606 +/- 0.171843<br />
Fitted spectrum for 1625-254 with fitorder=1: Flux density = 0.470153 +/- 0.00954831 (freq=693.582 GHz) spidx=6.41113 +/- 2.92508<br />
Storing result in uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.flux.cal<br />
Writing solutions to table: uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed.flux.cal<br />
##### End Task: fluxscale #####<br />
</pre><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated (Butler-JPL-Horizons 2012) flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for the calibrators will be slightly different. For example, in the case of measurement set X575, 3c279 in spectral window 2 has a flux of 10.8 Jy using the 2010 standard and 9.7 Jy using the 2012 standard; as a second example, for measurement set X39b, 1924-292 in SPW 0 has a flux of 2.3 Jy (2010 standard) and 2.1 Jy (2012 standard). <br />
</div><br />
<br />
When derived fluxes are too high and nothing else appears wrong with<br />
the data, the cause (especially at Band 9) is likely to be decorrelation. So<br />
we will favor the average of the lower values to explicitly set the<br />
flux densities based on the {{fluxscale}} results. We set the flux of the two<br />
bandpass calibrators for the convenience of having a fully calibrated<br />
dataset. The only ones that really matter are 1625 as the gain<br />
calibrator and the check source nrao530.<br />
Based on this, we proceed as follows to make the changes that are needed:<br />
<br />
<source lang="python"><br />
# Fixing the fluxes<br />
flux1924=[2.3,0,0,0]<br />
flux1625=[0.43,0,0,0]<br />
fluxnrao530=[0.66,0,0,0]<br />
flux3c279=[10.5,0,0,0]<br />
<br />
datawith1924=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
for vis in datawith1924:<br />
setjy(vis=vis,field='1924-292',fluxdensity=flux1924,usescratch=False)<br />
setjy(vis=vis,field='1625-254',fluxdensity=flux1625,usescratch=False)<br />
setjy(vis=vis,field='nrao530*',fluxdensity=fluxnrao530,usescratch=False)<br />
<br />
datawith3c279=['uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed']<br />
for vis in datawith3c279:<br />
setjy(vis=vis,field='3c279',fluxdensity=flux3c279,usescratch=False)<br />
setjy(vis=vis,field='1625-254',fluxdensity=flux1625,usescratch=False)<br />
setjy(vis=vis,field='nrao530*',fluxdensity=fluxnrao530,usescratch=False)<br />
</source><br />
<br />
We now need to re-run the amplitude calibration step.<br />
<br />
<source lang="python"><br />
#This new amplitude calibration will be used in the applycal.<br />
<br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
calfields=['1924-292,Juno,1625-254,nrao530*',<br />
'3c279,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*']<br />
<br />
calchan='0~3:20~3820'<br />
refant='DV14'<br />
<br />
for vis in range(len(data)):<br />
gaincal(vis=data[vis],caltable=data[vis]+'.amp.final.gcal',<br />
field=calfields[vis],spw=calchan,refant=refant,<br />
calmode='ap',solint='inf',minsnr=2.0,minblperant=4,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal'])<br />
</source><br />
<br />
== Application of calibration tables ==<br />
<br />
Now that we have all the calibration tables with the results, both for gains and flux, we need to apply all the tables to the data. First, we save the state of the flags.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
<br />
for vis in range(len(data)):<br />
flagmanager(vis=data[vis],mode='save',versionname='beforeapplycal')<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=bpcal[vis],<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=[bpcal[vis],bpcal[vis],bpcal[vis]],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=pcal,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=[bpcal[vis],pcal,pcal],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=fluxcal,<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.intphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=[bpcal[vis],fluxcal,fluxcal],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=science,<br />
interp=['nearest','linear','linear'],<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.scanphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
gainfield=[bpcal[vis],pcal,pcal],flagbackup=False,calwt=False)<br />
<br />
for vis in range(len(data)):<br />
applycal(vis=data[vis],field=check,<br />
interp=['nearest','linear','linear'],<br />
gaintable=[data[vis]+'.bandpass_bpoly.bcal',data[vis]+'.scanphase.gcal',<br />
data[vis]+'.amp.final.gcal'],<br />
gainfield=[bpcal[vis],pcal,pcal],flagbackup=False,calwt=False)<br />
</source><br />
<br />
<br />
== Plot corrected data ==<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.cal.time.spw1.png|200px|thumb|right|'''Fig. 14.''' This plot shows amplitude (flux) versus time for the dataset X90c in spw 1.]]<br />
<br />
[[File:uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed.cal.time.phase.spw1.png|200px|thumb|right|'''Fig. 15.''' Phase vs time for all the sources in X90c (spw 1).]]<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.cal.freq.amp.1625-254.png|200px|thumb|right|'''Fig. 16.''' Amplitude (flux) vs frequency for 1625-254 in X39b.]]<br />
<br />
[[File:uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed.cal.freq.phase.3c279.png|200px|thumb|right|'''Fig. 17.''' Phase vs frequency for 3c279 in X575.]]<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.science.freq.amp1.png|200px|thumb|right|'''Fig. 18.''' Amplitude vs frequency for the science target, colored by fields for X39b and spw 1, showing CO (6-5).]]<br />
<br />
[[File:uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed.science.freq.amp3.png|200px|thumb|right|'''Fig. 19.''' Amplitude vs frequency as for Figure 15, but for spw 3.]]<br />
<br />
The next commands will help you visualize the result of the application of the calibration tables to the data. You can check if the amplitudes and phases vs time and frequency look reasonable for all the sources, in particular for the science target fields.<br />
<br />
The next command will produce four plots, as the one we showed in Figure 5, but the amplitude in this new plots corresponds to flux because we now have calibrated data.<br />
See Figure 14 for an example of it. It is important to check that all the sources have similar amplitude (flux) in the different spws and datasets.<br />
<br />
<source lang="python"><br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
# Match up intents with source names<br />
pcal='1625-254'<br />
fluxcal='Juno' <br />
science='IRAS16293*'<br />
check='nrao530*'<br />
bpcal=['1924-292','3c279','1924-292','1924-292']<br />
calfields=['1924-292,Juno,1625-254,nrao530*',<br />
'3c279,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*',<br />
'1924-292,Juno,1625-254,nrao530*']<br />
# Set some plotting things<br />
SPW=['0','1','2','3']<br />
<br />
os.system('rm -rf aftercal_plots')<br />
os.system('mkdir aftercal_plots')<br />
<br />
os.system('rm -rf aftercal_plots/*cal.time*.png')<br />
for vis in range(len(data)):<br />
for spw in SPW:<br />
plotms(vis=data[vis],spw=spw,xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.time.spw%s.png'%(spw))<br />
print('When you are done with the graphics window,')<br />
print('quit that window, and')<br />
user_check=raw_input('press enter to continue script\n')<br />
</source><br />
<br />
It is also important to check the phases vs time for all the sources. The next command will get you the corresponding plots, four for each dataset. You can see that while the bandpass and amplitude calibrator have very concentrated phases around 0 degrees, the phase calibrator and the science target do not.<br />
In Figure 15 we show an example of these plots for spw 1 in the dataset X90c.<br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*cal.time.phase*.png')<br />
for vis in range(len(data)):<br />
for spw in SPW:<br />
plotms(vis=data[vis],spw=spw,xaxis='time',yaxis='phase',field='',avgchannel='3840',<br />
coloraxis='field',ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.time.phase.spw%s.png'%(spw))<br />
</source><br />
<br />
We now check the amplitude of the sources vs frequency. This is important since we expect that all the spw have very similar behavior. You will have one plot for each field for each dataset. In Figure 16 we show the case for 1625-254, our phase calibrator, for X39b.<br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*cal.freq.amp*.png')<br />
for vis in range(len(data)):<br />
for field in calfields[vis].split(','):<br />
plotms(vis=data[vis],field='%s'%field,xaxis='freq', yaxis='amp',<br />
spw='',avgtime='1e8',avgscan=True,<br />
coloraxis='spw',xselfscale=True,ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.freq.amp.'+field+'.png')<br />
</source><br />
The next command will produce similar plots but this time of phase vs frequency (see Figure 17 for an example).<br />
You will notice that only strong sources, like 3c279, will show clearly phases concentrated around 0 degrees.<br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*cal.freq.phase*.png')<br />
for vis in range(len(data)):<br />
for field in calfields[vis].split(','):<br />
plotms(vis=data[vis],field='%s'%field,xaxis='freq', yaxis='phase',<br />
spw='',avgtime='1e8',avgscan=True,<br />
coloraxis='spw',xselfscale=True,ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.cal.freq.phase.'+field+'.png')<br />
</source><br />
<br />
Finally, for our science target, we plot amplitude (flux) vs frequency for all the spectral windows. See an example of this is Figure 18 and 19. If you look carefully at these plots, you will notice that the datasets at low elevation show much more line emission - this is due to the <br />
shorter projected baselines present for these datasets (X39b and Xb50). In contrast, you start to see some weak absorption for the dataset at high elevation: X90c. <br />
<br />
<source lang="python"><br />
os.system('rm -rf aftercal_plots/*science.freq.amp*.png')<br />
for vis in range(len(data)):<br />
for spw in SPW: <br />
plotms(vis=data[vis],field=science,xaxis='freq', yaxis='amp',<br />
spw=spw,avgtime='1e8',avgscan=True,<br />
coloraxis='field',xselfscale=True,ydatacolumn='corrected',<br />
plotfile='aftercal_plots/'+data[vis]+'.science.freq.amp'+spw+'.png',<br />
title=data[vis].split('_')[-1].split('.')[0]+'.IRAS16293_spw'+spw)<br />
</source><br />
<br />
Next, we put a list of additional plotms commands that do not produce .png files, but that you can explore and save a copy of the output file if you are interested.<br />
<br />
<source lang="python"><br />
# Additional manual plots<br />
vis=data[0]<br />
plotms(vis=vis,spw='',xaxis='time',yaxis='amp',field='',avgchannel='3840',<br />
coloraxis='field',ydatacolumn='corrected',iteraxis='spw')<br />
<br />
vis=data[1]<br />
plotms(vis=vis,field=bpcal[1],xaxis='freq', yaxis='amp',<br />
spw='2',avgtime='1e8',avgscan=True,iteraxis='antenna',<br />
coloraxis='field',xselfscale=True,ydatacolumn='corrected')<br />
<br />
vis=data[1]<br />
plotms(vis=vis,field=calfields[1],xaxis='freq', yaxis='amp',<br />
spw='',avgtime='1e8',avgscan=True,<br />
coloraxis='field',xselfscale=True,ydatacolumn='corrected')<br />
</source><br />
<br />
== Split and concatenate the calibrated data ==<br />
<br />
You are ready now to extract the final calibrated data for the science target. Of course, you can do something similar for the calibrators if you are interested.<br />
<br />
<source lang="python"><br />
# Splitting final calibrated datasets<br />
data=['uid___A002_X3d4118_X39b.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X575.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.antwvrtsys.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.antwvrtsys.ms.fixed']<br />
<br />
for vis in data:<br />
split(vis=vis,outputvis='%s.cal.IRAS16293.ms.fixed'%(vis.split('.')[0]),<br />
datacolumn='corrected',field='IRAS16293*',keepflags=False)<br />
</source><br />
<br />
There are now four datasets fully calibrated. We finally will merge these datasets into a single one, in order to proceed with the analysis and imaging in both continuum and spectral line.<br />
<br />
<source lang="python"><br />
# Concatenating the final split files<br />
concatdata=['uid___A002_X3d4118_X39b.cal.IRAS16293.ms.fixed',<br />
'uid___A002_X3d55cb_X575.cal.IRAS16293.ms.fixed',<br />
'uid___A002_X3d55cb_X90c.cal.IRAS16293.ms.fixed',<br />
'uid___A002_X3d55cb_Xb50.cal.IRAS16293.ms.fixed']<br />
<br />
concat(vis=concatdata,concatvis='IRAS16293_Band9.fixed.ms')<br />
</source><br />
<br />
To speed up imaging we apply 60 second time averaging to the concatenated dataset.<br />
<br />
<source lang="python"><br />
# 60s time averaging<br />
split(vis='IRAS16293_Band9.fixed.ms', datacolumn='data', timebin='60s', <br />
outputvis='IRAS16293_Band9.fixed.rebin.ms')<br />
</source><br />
<br />
As a final step, we zero the rows of the pointing table because it is<br />
quite large and is not currently needed by the imaging software for<br />
mosaics -indeed its presence will cause an error during imaging if you<br />
skip this step.<br />
<br />
<source lang="python"><br />
# Remove rows of pointing table<br />
tb.open('IRAS16293_Band9.fixed.rebin.ms/POINTING', nomodify = False)<br />
a = tb.rownumbers()<br />
tb.removerows(a)<br />
tb.close() <br />
</source><br />
<br />
Now you have completed the calibration and have everything you need to carry out the imaging stage. Follow [[IRAS16293 Band9 - Imaging for CASA 4.5]] to go to the imaging section of this casaguide.<br />
<br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.5&diff=21235AntennaeBand7 Imaging 4.52017-04-03T18:15:28Z<p>Jthorley: </p>
<hr />
<div>* '''This guide is designed for CASA 4.5.0. If you are using an older version of CASA please see [[AntennaeBand7_Imaging_4.3]].<br />
* '''This tutorial picks up where [[AntennaeBand7_Calibration_4.5]] leaves off: with fully calibrated, split science target measurement sets. If you wish to skip the Calibration guide: obtain the calibrated data from [[AntennaeBand7#Obtaining_the_Data]]; extract it using <tt>tar -xzvf FILENAME</tt>; and <tt>cd</tt> into the extracted directory.'''<br />
* '''Details of the ALMA data are provided at [[AntennaeBand7]]'''.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
== Imaging Mosaics ==<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the basic concepts of deconvolution and clean, pause here and <br />
review for example http://www.aoc.nrao.edu/events/synthesis/2010/lectures/wilner_synthesis10.pdf<br />
</pre><br />
<br />
Mosaics like other kinds of images are created in the CASA task {{clean}}. To invoke mosaic mode, you simply set the parameter '''imagermode='mosaic''''. The default subparameter '''ftmachine='mosaic'''' is then automatically set. This is a joint deconvolution algorithm that works in the uv-plane. A convolution of the primary beam patterns for each pointing in the mosaic is created: the primary beam response function. The corresponding image of the mosaic response function will be called ''<imagename>.flux.pbcoverage'' and ''<imagename>.flux'' (where the latter differs from the former only if the sensitivity of each field in the mosaic varies).<br />
<br />
Well-sampled mosaics like the patterns observed for the Northern and Southern Antennae mosaics shown on the [[AntennaeBand7#ALMA_Data_Overview | Overview]] page are well-suited to joint deconvolution. However, if you have a poorly-sampled, or very irregular mosaic you may need to use the slower '''ftmachine='ft'''' which combines data in the image plane, similar to what is done in other packages like ''MIRIAD''. <br />
<br />
Additionally, for mosaics it is essential to pick the center of the region to be imaged explicitly using the '''phasecenter''' parameter. Otherwise it will default to the first pointing included in the '''field''' parameter -- since this is often at one corner of the mosaic, the image will not be centered. For the Northern mosaic, the center pointing corresponds to field id 12. Note that during the final '''split''' in the calibration section that selected only the Antennae fields, the field ids were renumbered, so that the original centers (shown in the [[AntennaeBand7#ALMA_Data_Overview | Overview]]) have changed: field id 14 becomes 12 for the Northern mosaic and field 18 becomes 15 for the Southern mosaic. You can also set an explicit coordinate (see the {{clean}} help for syntax).<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
If you want to learn more about mosaicing, pause here and <br />
review for example http://www.aoc.nrao.edu/events/synthesis/2010/lectures/jott-mosaicking-school-04.pdf<br />
</pre><br />
<br />
== Continuum Imaging ==<br />
<figure id="Antennae_South-AMPvsCH.png"><br />
[[File:Antennae_South-AMPvsCH.png|200px|thumb|right|<caption>Southern mosaic: Amplitude vs. channel. The CO(3-2) line is seen from 50 to 100</caption>]]<br />
</figure><br />
<figure id="Antennae_North-AMPvsCH.png"><br />
[[File:Antennae_North-AMPvsCH.png|200px|thumb|right|<caption>Northern mosaic: Amplitude vs. channel. The CO(3-2) line is seen from 70 to 100</caption>]]<br />
</figure><br />
<br />
We will make 345 GHz continuum images for the two regions covered by the mosaics. We use the task {{clean}} over the channels that are free of the line emission; we avoid the edge channels which tend to be noisier due to bandpass rolloff effects. The line-free channels are found by plotting the average spectrum (all fields). We find the CO(3-2) line from channels 50 to 100 in the southern mosaic (<xr id="Antennae_South-AMPvsCH.png"/>), and from 70 to 100 in the northern mosaic (<xr id="Antennae_North-AMPvsCH.png"/>). <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North-AMPvsCH.png')<br />
plotms(vis='Antennae_North.cal.ms',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=True,plotfile='Antennae_North-AMPvsCH.png')<br />
</source><br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South-AMPvsCH.png')<br />
plotms(vis='Antennae_South.cal.ms',xaxis='channel',yaxis='amp',<br />
avgtime='1e8',avgscan=True,plotfile='Antennae_South-AMPvsCH.png')<br />
</source><br />
<br />
The '''avgtime''' is set to a large value so that it averages over all the integrations, and '''avgscan''' is set to allow averaging of the different scans.<br />
<br />
Next we create continuum images from the line-free channels. <br />
<br />
==== Northern Continuum Mosaic ====<br />
<br />
For illustrative purposes we first make a dirty image to see if there is emission and what the exact beam size is. It should be on the order of 1" but this will vary a bit according to the uv-coverage in the actual data. We will start with a '''cell''' size of 0.2" to oversample the beam by a factor of 5. The '''imsize''' needs to be large enough given the cell size to comfortably encompass the mosaic. From the mosaic footprints shown in the [[AntennaeBand7#ALMA_Data_Overview | overview]], we can see that the Northern mosaic '''imsize''' needs to be about 1 arcmin. With 0.2" pixels, this requires '''imsize=300'''. <br />
<br />
Other essential {{clean}} parameters for this case include:<br />
*'''vis='Antennae_North.cal.ms' ''': The calibrated dataset on the science target. {{clean}} will always use the CORRECTED DATA column (if it exists).<br />
*'''imagename='Antennae_North.Cont.Dirty' ''': The base name of the output images:<br />
** <imagename>.image # the final restored image<br />
** <imagename>.flux # the effective primary beam response (where '''pbcor=True''')<br />
** <imagename>.flux.pbcoverage # the primary beam coverage ('''ftmachine=’mosaic’ ''' only)<br />
** <imagename>.model # the model image<br />
** <imagename>.residual # the residual image<br />
** <imagename>.psf # the synthesized (dirty) beam<br />
*'''spw='0:1~50;120~164' ''': To specify only the line-free channels of spectral window 0.<br />
*'''mode='mfs' ''': Multi-Frequency Synthesis: The default mode, which produces one image from all the specified data combined. This will grid each channel independently before imaging. For wide bandwidths this will give a far superior result compared to averaging the channels and then imaging. <br />
*'''restfreq='345.79599GHz' ''': The rest frequency of CO(3-2) can be found with [http://www.splatalogue.net/ splatalogue].<br />
*'''niter=0''': Maximum number of clean iterations. ('''niter=0 will do no cleaning''')<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.Cont.Dirty*')<br />
clean(vis='Antennae_North.cal.ms',imagename='Antennae_North.Cont.Dirty',<br />
field='',phasecenter='12',<br />
mode='mfs',restfreq='345.79599GHz',<br />
spw='0:1~50;120~164',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=300,cell='0.2arcsec',<br />
interactive=False,niter=0)<br />
</source><br />
<br />
The reported beam size is about 1.27" x 0.71" P.A. 86.142 degrees. <br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_North.Cont.Dirty.image')<br />
</source><br />
<br />
<!-- COMMENT OUT VIEWER VIDEO. UNCOMMENT WHEN A MORE UP-TO-DATE VIDEO IS AVAILABLE.<br />
<pre style="background-color: #E0FFFF;"><br />
If you are unfamiliar with the CASA viewer it is a good idea to pause here and watch the demo at <br />
http://casa.nrao.edu/CasaViewerDemo/casaViewerDemo.html<br />
</pre> --><br />
<br />
<figure id="North_cont_clean.png"><br />
[[Image:North_cont_clean.png|200px|thumb|right|<caption>Residual for Northern continuum mosaic after 100 iterations; the clean mask is shown by the white contour.</caption>]]<br />
</figure><br />
<br />
Yes there is definitely a detection in the vicinity of the Northern nucleus (see <xr id="North_contstat.png"/> and <xr id="Antennae_North.Cont.Clean.image.png"/> below). Using the square region icon, and drawing a box near but not including the emission, we find the rms noise is about 0.4 mJy/beam in the dirty image.<br />
<br />
Next we switch to refined values of '''cell='0.13arcsec' ''' and '''imsize=500''' based on the observed beam size. We also switch to interactive mode so that you can create a clean mask using the polygon tool (note you need to double click inside the polygon region to activate the mask). See [[TWHydraBand7_Imaging_3.4#Image_and_Self-Calibrate_the_Continuum | TWHya casaguide]] for a more complete description of interactive clean and mask creation. <br />
<br />
*'''niter=1000''': Maximum number of clean iterations -- '''we will stop interactively'''<br />
*'''threshold='0.4mJy' ''': Stop cleaning if the maximum residual is below this value (the dirty rms noise)<br />
*'''interactive=True''': Clean will be periodically interrupted to show the residual clean image. Interactive clean mask can be made. If no mask is created, no cleaning is done.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.Cont.Clean*')<br />
clean(vis='Antennae_North.cal.ms',imagename='Antennae_North.Cont.Clean',<br />
field='',phasecenter='12',<br />
mode='mfs',restfreq='345.79599GHz',<br />
spw='0:1~50;120~164',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=500,cell='0.13arcsec',<br />
interactive=True, <br />
niter=1000, threshold='0.4mJy')<br />
</source><br />
<br />
The residuals are "noise-like" after only 100 iterations (see <xr id="North_cont_clean.png"/>), so hit the red X symbol in the interactive window to stop cleaning here. <br />
<br />
Note that if you run the {{clean}} task again with the same '''imagename''', without deleting the existing <imagename>.* files, {{clean}} assumes that you want to continue cleaning the existing images. We put an <tt>rm</tt> command before the {{clean}} command to guard against this, but sometimes this is what you want.<br />
<br />
==== Southern Continuum Mosaic ====<br />
<br />
<figure id="South_cont_clean.png"><br />
[[Image:South_cont_clean.png|200px|thumb|right|<caption>Residual for Southern continuum mosaic after 100 iterations; the clean mask is shown by the white contour.</caption>]]<br />
</figure><br />
<br />
For the southern mosaic we modify the '''phasecenter''', mosaic '''imsize''', and the line-free channels ('''spw''') to be consistent for this mosaic. We also bypass the dirty image step we did above for the Northern mosaic. As above, the mosaic size can be judged from the [[AntennaeBand7#ALMA_Data_Overview | Overview]]. We expect the beam to be about the same and use the same '''cell''' size. During {{clean}}, we repeat the process of making a clean mask. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South.Cont.Clean*')<br />
clean(vis='Antennae_South.cal.ms',imagename='Antennae_South.Cont.Clean',<br />
field='',phasecenter='15',<br />
mode='mfs',restfreq='345.79599GHz',<br />
spw='0:1~30;120~164',<br />
imagermode='mosaic',<br />
imsize=750,cell='0.13arcsec',<br />
interactive=True, usescratch=False,<br />
niter=1000, threshold='0.4mJy')<br />
</source><br />
<br />
The beam size reported in the logger for the Southern mosaic: 1.11"x 0.71", and P.A.=65 deg; which is a little better than the beam for the North owing to better uv-coverage.<br />
<br />
Stop after 100 iterations (<xr id="South_cont_clean.png"/>).<br />
<br />
==== Image Statistics ====<br />
<br />
<figure id="North_contstat.png"><br />
[[File:North_contstat.png|200px|thumb|right|<caption>Example polygon for rms determination using the viewer.</caption>]]<br />
</figure><br />
<br />
<br />
You can determine statistics for the images using the task {{imstat}}:<br />
<source lang="python"><br />
# In CASA<br />
imstat('Antennae_North.Cont.Clean.image')<br />
imstat('Antennae_South.Cont.Clean.image')<br />
</source><br />
<br />
From this we find, that for the Northern continuum image the peak is 3.66 mJy/beam and the rms is 0.47 mJy/beam. For the Southern continuum we find a peak of 4.49 mJy/beam and an rms of 0.45 mJy/beam. <br />
<br />
However, the calculation of the rms comes with a couple of caveats. First, the mosaic primary beam response rolls off toward the edges of the mosaic, as do correspondingly the flux density and rms. Thus if you don't restrict the measurement to areas of full sensitivity, the apparent rms is skewed downward. Second, since there is real emission in the image, the rms will be skewed upward (with the error increasing with brighter emission). Both can be solved by picking boxes that exclude the edges of the mosaic and the real emission. <br />
<br />
It is often easier to use either the {{viewer}} directly or {{imview}} (a task wrapper for the {{viewer}}; see '''help imview''' for more info) to display the image and then interactively use the region tools to get the statistics.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_North.Cont.Clean.image')<br />
</source><br />
<br />
Adjust colorscale using the middle mouse button (or reassign to a different mouse button by clicking on "plus" symbol icon). Next, select the polygon tool by clicking on its symbol with a mouse button. Then draw a region that avoids edges and emission (see <xr id="North_contstat.png"/>), then double click inside the polygon to have the statistic printed to the screen. You may measure an rms that differs by a few percent from the value reported by imstat.<br />
<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_South.Cont.Clean.image')<br />
</source><br />
<br />
<figure id="Antennae_North.Cont.Clean.image.png"><br />
[[File:Antennae_North.Cont.Clean.image.png|200px|thumb|right|<caption>345 GHz continuum image of the northern mosaic made with {{imview}}.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.Cont.Clean.image.png"><br />
[[File:Antennae_South.Cont.Clean.image.png|200px|thumb|right|<caption>345 GHz continuum image of the southern mosaic made with {{imview}}.</caption>]]<br />
</figure><br />
<br />
Again, you may measure an rms slightly different than what we got from using {{imstat}} with no constraints. <br />
<br />
How does this compare to theory? You can find out using the [https://almascience.nrao.edu/call-for-proposals/sensitivity-calculator ALMA sensitivity calculator]. The continuum bandwidth of the Northern mosaic is about 1 GHz and about 0.85 GHz for the Southern mosaic. The number of antennas is about 12 and the time on a single pointing is about 300s. This yields an expected rms of about 1 mJy/beam. However, this needs to be decreased by about a factor of 2.5 near the center of the mosaic due to the hexagonal Nyquist sampling of the mosaic (radial spacing~0.37*HPBW) for a theoretical rms of about 0.4 mJy/beam, in good agreement with observation. <br />
<br />
Next make hardcopy plots of the continuum images using {{imview}}. To make the contrast a bit better, set the data range from -1 x sigma to the peak determined above.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (<br />
raster={'file': 'Antennae_North.Cont.Clean.image',<br />
'colorwedge':T,'range':[-0.00048,0.00380]},<br />
zoom=1, out='Antennae_North.Cont.Clean.image.png')<br />
imview (<br />
raster={'file': 'Antennae_South.Cont.Clean.image',<br />
'colorwedge':T,'range':[-0.00050,0.00523]},<br />
zoom=1, out='Antennae_South.Cont.Clean.image.png')<br />
</source><br />
<br />
==Continuum subtraction ==<br />
<br />
In these data, the continuum emission is too weak to contaminate the line emission (i.e. the peak continuum emission is less than the rms noise in the spectral line channels). Nevertheless, for illustrative purposes we demonstrate how to subtract the continuum emission in the uv-domain using the task {{uvcontsub}}.<br />
<br />
<source lang="python"><br />
# In CASA<br />
uvcontsub(vis='Antennae_North.cal.ms',fitspw='0:1~50;120~164',fitorder = 1)<br />
# In CASA<br />
uvcontsub(vis='Antennae_South.cal.ms',fitspw='0:1~30;120~164',fitorder = 1)<br />
</source><br />
<br />
Here, '''fitspw''' gives the line-free channels for each mosaic and '''fitorder=1'''. Higher order fits are not recommended. If you do not have line-free channels on both sides of the line '''fitorder=0''' is recommended. The output MS will have ''.contsub'' appended to the name.<br />
<br />
== CO(3-2) Imaging ==<br />
<br />
<figure id="North_CO3_2_vel.png"><br />
[[Image:North_CO3_2_vel.png|thumb|<caption>Northern CO(3-2) uv-spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<figure id="South_CO3_2_vel.png"><br />
[[Image:South_CO3_2_vel.png|thumb|<caption>Southern CO(3-2) uv-spectrum in LSRK velocity space.</caption>]]<br />
</figure><br />
<br />
Now we are ready to make cubes of the line emission. The imaging parameters are similar to the continuum except for <br />
those dealing with the spectral setup: '''mode''', '''start''', '''width''', '''nchan''', '''restfreq''', and '''outframe''' parameters. When making spectral images you have three choices for the '''mode''' parameter: '''channel''', '''velocity''', and '''frequency'''. Data are taken using constant frequency channels. For spectral line analysis it's often more useful to have constant velocity channels, and this is also the best way to make images of multiple lines with the exact same channelization for later comparison. For '''mode='velocity'''', the desired '''start''' and '''width''' also need to be given in velocity units for the desired output frame. <br />
<br />
It is important to note that ALMA does not do on-line Doppler Tracking and the native frame of the data is TOPO. If you do not specify '''outframe''' the output cube will also be in TOPO, which is not very useful for scientific analysis. The Doppler Shift is taken out during the regridding to the desired outframe in {{clean}} or alternatively it can be done separately by the {{cvel}} task which would need to be run before {{clean}}. <br />
<br />
To see what velocity parameters you want to set in {{clean}}, it is useful to make a plot in {{plotms}} in the desired output frame. Note these plots take a little longer because of the frame shift. In order to compare with recent SMA data, we chose LSRK, but it should be noted that many papers of this source are in the BARY frame. <br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf North_CO3_2_vel.png')<br />
plotms(vis='Antennae_North.cal.ms.contsub/',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=True,transform=True,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotfile='North_CO3_2_vel.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf South_CO3_2_vel.png')<br />
plotms(vis='Antennae_South.cal.ms.contsub',xaxis='velocity',yaxis='amp',<br />
avgtime='1e8',avgscan=True,transform=True,freqframe='LSRK',<br />
restfreq='345.79599GHz',plotfile='South_CO3_2_vel.png') <br />
</source><br />
<br />
==== Northern Mosaic ====<br />
<br />
As before, it is very important that you make a clean mask. There are many ways to do this ranging from the complicated to simple. For this example we will make a single clean mask that encompasses the line emission in every channel and apply it to all channels. This is much better than no clean mask, though not quite as good as making an individual mask for each channel.<br />
<br />
Notable parameters included in the {{clean}} call are:<br />
*'''mode='velocity' ''','''outframe='LSRK' ''','''restfreq='345.79599GHz' '''. We use 'velocity' mode to set velocity information in the Local Standard of Rest frame (kinematic definition), and use the rest frequency of the CO(3-2) line.<br />
*'''nchan=60''','''start='1300km/s' ''','''width='10km/s' ''': To produce a data cube with 60 channels ("nchan"=60), starting at 1300km/s and with velocity widths of 10 km/s. That will include all the CO(3-2) emission in both mosaics.<br />
*'''imsize=500''','''cell='0.13arcsec' ''': An image size of 65 arcsec, with pixels of 0.13 arcsec (about one-fifth the minor axis of the synthesized beam). We make the imsize larger than the mosaic to increase the dirty beam image size, as the emission is quite extended along the mosaic. <br />
*'''weighting='briggs' ''','''robust=0.5''': Weighting to apply to visibilities. We use Briggs' weighting and robustness parameter 0.5 (in between natural and uniform weighting).<br />
*'''niter=10000''': Maximum number of clean iterations. <br />
*'''threshold='5.0mJy' ''': Stop cleaning if the maximum residual is below this value. <br />
The threshold is set to roughly the rms of a single line-free channel for each dataset. <br />
<br />
<figure id="North_interact.png"><br />
[[Image:North_interact.png|200px|thumb|right|<caption>Interactive cleaning of northern mosaic. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.CO3_2Line*')<br />
clean(vis='Antennae_North.cal.ms.contsub',<br />
imagename='Antennae_North.CO3_2Line.Clean',<br />
spw='0',field='',phasecenter='12',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',<br />
imsize=500,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,usescratch=False,<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
<xr id="North_interact.png"/> shows what the final clean box should look like. Now clean using the green circle arrow. You can watch the progress in the logger. When 100 iterations are done, the viewer will show the residual map for each channel. Cycle through the channels and see whether you are still happy with the clean box in each channel with significant signal. The "erase button" can help you fix mistakes. If necessary adjust. It is often useful to adjust the colorscale with the "plus" symbol icon. To make it go a bit faster, you can increase '''iteration''' interactively, to 200 or 300, but don't overdo it.<br />
<br />
These data are pretty severely ''dynamic range'' limited, in part due to the sparse uv coverage. In other words, the noise in bright channels is set by a maximum signal-to-noise. This effectively prevents us from stopping clean based on an rms based '''threshold''' because the effective rms changes as a function of the brightest signal in each channel. Thus, in this case we need to stop clean interactively. Below an approximate number of '''iterations''' is given to help you decide when to quit. NOTE: the '''threshold''' that is set in the CO(3-2) clean commands are about equal to the noise in a line-free channel and is only there to prevent clean running forever if you fail to stop it. You are not intended to clean to this '''threshold'''.<br />
<br />
Also, we are going to self-calibrate the data so it's best to be conservative here - it can be difficult in images like these to discern real features from artifacts. If in doubt, don't include it in the clean mask. Keep cleaning and see if the feature becomes weaker. You cannot lose real emission by not masking it, but you can create a brighter feature by masking an artifact. <br />
<br />
Stop cleaning after about 900 iterations (Red X), when the artifacts start to look as bright as the residual. <br />
<br />
Inspect the resulting data cube:<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_North.CO3_2Line.Clean.image')<br />
</source><br />
<br />
==== Southern Mosaic ====<br />
<figure id="South_interact.png"><br />
[[Image:South_interact.png|200px|thumb|right|<caption>Interactive cleaning of southern mosaic. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
Repeat process for Southern mosaic.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South.CO3_2Line*')<br />
clean(vis='Antennae_South.cal.ms.contsub',<br />
imagename='Antennae_South.CO3_2Line.Clean',<br />
spw='0',field='',phasecenter='15',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',<br />
imsize=750,cell='0.13arcsec',minpb=0.2,<br />
interactive=Tru,usescratch=False,<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
Clean about 1200 iterations before stopping.<br />
<br />
Inspect the resulting data cube:<br />
<source lang="python"><br />
# In CASA<br />
viewer('Antennae_South.CO3_2Line.Clean.image')<br />
</source><br />
<br />
For each mosaic use the '''viewer''' polygon tool as described above for the continuum, to find the image statistics in both a line-free channel and the channel with the strongest emission. <br />
<br />
The line-free channel rms for the northern and southern mosaics are about 4.0 mJy/beam and 3.5 mJy/beam, respectively.<br />
However in a bright channel this degrades to about 18 mJy/beam and 9 mJy/beam, respectively. This is the aforementioned dynamic range limit. <br />
<br />
Using the [https://almascience.nrao.edu/call-for-proposals/sensitivity-calculator ALMA sensitivity calculator], a bandwidth of 10 km/s, dual polarization, 12 antennas, and the time on a single pointing of about 300s yields an rms of about 9.0 mJy/beam. As described above the Nyquist sampled hexagonal mosaic improves this by a factor of about 2.5 for an expected rms noise of about 3.6 mJy. So in line-free channels we are doing close to theoretical.<br />
<br />
== Self Calibration == <br />
<br />
Next we attempt to self-calibrate the uv-data. The process of self-calibration tries to adjust the data to better match the model image that you give it. When {{clean}} is run, it automatically saves a uv-model of the resulting image in the header of the measurement set. This model can be used to self-calibrate the data using {{gaincal}}. That is why it is important to make the model as good as you can by making clean masks. <br />
<br />
Mosaics can be tricky to self-calibrate. The reason is that typically only a few of the pointings may have strong emission. The stronger the signal, the stronger the signal-to-noise will be for a given self-calibration solution interval ('''solint'''). This means that typically only a few fields are strong enough for self-calibration, though it can still bring about overall improvement to apply these solutions to all fields. The fine tuning of each field in the mosaic over small solutions intervals is often impossible. Indeed fine-tuning only a few fields in the mosaic on small time scales can result in a mosaic with dramatically different noise levels as a function of position. Below, we will simply attempt to self-calibrate on the strongest field in the mosaic, obtaining one average solution per original input dataset. <br />
<br />
Here, the continuum is far too weak so we will use the CO(3-2) line emission. To increase signal-to-noise it is often helpful to limit solutions to the range of channels containing the strongest line emission. <br />
<br />
We will also use '''gaintype='T'''' to tell CASA to average the polarizations before deriving solutions which gains us a sqrt(2) in sensitivity.<br />
<br />
==== Northern Mosaic ====<br />
<br />
<figure id="north_selfchan_data.png"><br />
[[Image:north_selfchan.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the data column of field 12 of the Northern mosaic.</caption>]]<br />
</figure><br />
<br />
The strongest emission in the Northern mosaic comes from the center pointing, already identified above as '''field='12' '''. Below we make a uv-plot of the spectral line emission from this field to chose only the strongest channels to include in the self-calibration. ''It is essential that the self-calibration channel range be chosen based on the UV data and not on the image cube.'' This is because the channels in the image cube were modified by the velocity/channel specifications in the first invocation of clean. This plot shows the channel range of the uv data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_North.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',field='12',<br />
avgtime='1e8',avgscan=True,ydatacolumn='data',plotfile='North_selfchan_data.png')<br />
</source><br />
<br />
We also want to check the channel amplitudes in the model column of the measurement set. The depth of the initial clean will determine what model channels have emission. (A very shallow clean could potentially produce a model with emission over a small range of channels.) Self calibration will attempt to make the data look like the model. Therefore, it is important that we select a channel range where the model is realistic. <br />
<br />
<figure id="North_selfchan_model.png"><br />
[[Image:North_selfchan_model.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the model column of field 12 of the northern mosaic.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_North.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',field='12',<br />
avgtime='1e8',avgscan=True,ydatacolumn='model',plotfile='North_selfchan_model.png')<br />
</source><br />
<br />
Next remind ourselves of the timing of the various observations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_North.cal.ms.contsub',spw='',xaxis='time',yaxis='amp',field='12',<br />
avgchannel='167',coloraxis='scan',ydatacolumn='data')<br />
</source><br />
<br />
Zooming in on each dataset we see that they are about 1 hour long (you can also check the {{listobs}} output), and that each dataset has 2 or 3 observations of field 12. Each time, it's observed for about 25 seconds. We set '''solint='3600s'''' to get one solution per dataset.<br />
<br />
<figure id="north_pcal1_phase.png"><br />
[[Image:north_pcal1_phase.png|200px|thumb|right|<caption>Phase-only self-calibration solutions for the Northern mosaic.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='Antennae_North.cal.ms.contsub',caltable='north_self_1.pcal',<br />
solint='3600s',combine='scan',gaintype='T',field='12',<br />
refant='DV09',spw='0:82~89',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
Plot the calibration solutions.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='north_self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='',<br />
iteration='antenna',subplot=531,plotrange=[0,0,-80,80],<br />
figfile='north_pcal1_phase.png')<br />
</source><br />
<br />
Apply the solutions to all fields and channels with {{applycal}}, which will overwrite the corrected data column:<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='Antennae_North.cal.ms.contsub',field='',<br />
gaintable=['north_self_1.pcal'],calwt=False)<br />
</source><br />
<br />
Re-image the data with the selfcal applied. Remember that {{clean}} always uses the corrected data column if it exists:<br />
<br />
<figure id="North_interact2.png"><br />
[[Image:North_interact2.png|200px|thumb|right|<caption>Interactive cleaning of Northern mosaic after self-cal. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_North.CO3_2Line.Clean.pcal1*')<br />
clean(vis='Antennae_North.cal.ms.contsub',<br />
imagename='Antennae_North.CO3_2Line.Clean.pcal1',<br />
spw='0',field='',phasecenter='12',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=500,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,mask='Antennae_North.CO3_2Line.Clean.mask',<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
After 600 iterations or so, inspect each channel to see if there is more emission that needs to be included in the mask. Remember to select the "all channels" toggle. Stop after 1200 or so iterations.<br />
<br />
Compare the un-selfcal'ed and selfcal'ed data to determine if there has been improvement.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (raster=[{'file': 'Antennae_North.CO3_2Line.Clean.image',<br />
'range': [-0.07,0.4]},<br />
{'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.07,0.4]}],<br />
zoom={'channel': 43})<br />
</source><br />
<br />
Then in the viewer, activate the Animator Images sub-panel by clicking the check box next to "Images". Then use the tape deck controls to cycle between the two images. To change the channel use the Channels sub-panel in the Animator. <br />
To make the figure shown in <xr id="north_ch43compare.png"/>, you can select the "p wrench" icon and change the number of panels in x to 2. You will need to drag your viewer window rather wide to get both panels to fit well. If you want to compare other channels, you need to toggle blink off, then use the tapedeck to move to the new channel of interest, and then turn blink back on to see both cubes again.<br />
<br />
Note: When the Images sub-panel is active (the check box next to Images is checked), statistics will be reported for the image currently displayed. When the Images sub-panel is not active, all open raster images will have their statistics reported.<br />
<br />
What you should notice is that the peak flux density has increased substantially while the rms noise is about the same. This is reasonable for this self-calibration case because we have mostly adjusted relative position offsets between the datasets and not taken out any short-term phase variations which would reduce the rms. <br />
<br />
Note that attempts to push the selfcal to shorter solint (for example to each scan of field=12) did not yield additional improvement. <br />
<br />
<figure id="north_ch43compare.png"><br />
[[Image:north_ch43compare.png|600px|thumb|center|<caption>Comparison of channel 43 before selfcal (left) and after selfcal (right).</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used '''standard='Butler-JPL-Horizons 2012' ''' when running {{setjy}} during the calibration process, you will see an increase of approximately 4% in the peak flux density (in channel 43).<br />
</div><br />
<br />
==== Southern Mosaic ====<br />
<br />
<figure id="south_selfchan.png"><br />
[[Image:south_selfchan.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the data column for Field 7 of the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
<figure id="South_selfchan_model.png"><br />
[[Image:South_selfchan_model.png|200px|thumb|right|<caption>Plot of the CO(3-2) emission from the model column for Field 7 of the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
Now repeat the self-calibration process for the Southern mosaic. It is a bit tougher in this case to pick the best field. The most compact bright emission is toward field id 11 in the [[AntennaeBand7#Science_Target_Overview | Overview]]. Adjusting for the renumbering of field ids after the final calibration split, this becomes field='7'. <br />
<br />
From the following plots we can assess the brightest channels to pick and see that the timing in the 6 Southern datasets is similar to the North, with each lasting about 1 hour. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_South.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',<br />
field='7',avgtime='1e8',avgscan=True,ydatacolumn='data',<br />
plotfile='South_selfchan_data.png')<br />
</source><br />
<br />
<source lang="python"><br />
plotms(vis='Antennae_South.cal.ms.contsub',spw='',xaxis='channel',yaxis='amp',<br />
field='7',avgtime='1e8',avgscan=True,ydatacolumn='model',<br />
plotfile='South_selfchan_model.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='Antennae_South.cal.ms.contsub',spw='',xaxis='time',yaxis='amp',field='7',<br />
avgchannel='167',avgscan=True,coloraxis='scan',ydatacolumn='data')<br />
</source><br />
<br />
<figure id="south_pcal1_phase.png"><br />
[[Image:south_pcal1_phase.png|200px|thumb|right|<caption>Phase-only self-calibration solutions for the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='Antennae_South.cal.ms.contsub',caltable='south_self_1.pcal',<br />
solint='3600s',combine='scan',gaintype='T',field='7',<br />
refant='DV09',spw='0:70~85',minblperant=4,<br />
calmode='p',minsnr=2)<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='south_self_1.pcal',xaxis='time',yaxis='phase',<br />
spw='',field='',antenna='',<br />
iteration='antenna',subplot=531,plotrange=[0,0,-80,80],<br />
figfile='south_pcal1_phase.png')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='Antennae_South.cal.ms.contsub',field='',<br />
gaintable=['south_self_1.pcal'],calwt=False)<br />
</source><br />
<br />
<figure id="South_interact2.png"><br />
[[Image:South_interact2.png|200px|thumb|right|<caption>Interactive cleaning of Southern mosaic after self-cal. The clean mask is shown in white. In this example we used the same mask for all channels by selecting "all channels" before drawing mask.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -rf Antennae_South.CO3_2Line.Clean.pcal1*')<br />
clean(vis='Antennae_South.cal.ms.contsub',<br />
imagename='Antennae_South.CO3_2Line.Clean.pcal1',<br />
spw='0',field='',phasecenter='15',<br />
mode='velocity',outframe='LSRK',restfreq='345.79599GHz',<br />
nchan=70,start='1200km/s',width='10km/s',<br />
imagermode='mosaic',usescratch=False,<br />
imsize=750,cell='0.13arcsec',minpb=0.2,<br />
interactive=True,mask='Antennae_South.CO3_2Line.Clean.mask',<br />
weighting='briggs',robust=0.5,<br />
niter=10000, threshold='5.0mJy')<br />
</source><br />
<br />
After 600 iterations or so, inspect each channel to see if there is more emission that needs to be included in the mask. Remember to select the "all channels" toggle. Stop after 2200 or so iterations.<br />
<br />
As for the Northern mosaic, you can compare the before and after self-cal images:<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview (raster=[{'file': 'Antennae_South.CO3_2Line.Clean.image',<br />
'range': [-0.05,0.2]},<br />
{'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.05,0.2]}],<br />
zoom={'channel': 31})<br />
</source><br />
<br />
<figure id="South_ch31compare.png"><br />
[[Image:South_ch31compare.png|600px|thumb|center|<caption>Comparison of channel 31 before selfcal (left) and after selfcal (right).</caption>]]<br />
</figure><br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used '''standard='Butler-JPL-Horizons 2012' ''' when running {{setjy}} during the calibration process, you will see an increase of approximately 4% in the peak flux density (in channel 31).<br />
</div><br />
<br />
== Image Analysis ==<br />
<br />
==== Moment Maps ====<br />
<br />
<figure id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png"><br />
[[Image:Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png|200px|thumb|right|<caption>The CO(3-2) integrated intensity map (moment 0) of the Northern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"><br />
[[Image:Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity field (moment 1) of the Northern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"><br />
[[Image:Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity dispersion (moment 2) of the Northern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png"><br />
[[Image:Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png|200px|thumb|right|<caption>The CO(3-2) integrated intensity map (moment 0) of the Southern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"><br />
[[Image:Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity field (moment 1) of the Southern mosaic.</caption>]]<br />
</figure><br />
<figure id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"><br />
[[Image:Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png|200px|thumb|right|<caption>The CO(3-2) velocity dispersion (moment 2) of the Southern mosaic.</caption>]]<br />
</figure><br />
<br />
Next we will make moment maps for the CO(3-2) emission: Moment 0 is the integrated intensity; Moment 1 is the intensity weighted velocity field; and Moment 2 is the intensity weighted velocity dispersion. <br />
<br />
Above we determined the rms noise levels for both the North and South mosaics in both a line-free and a line-bright channel. We want to limit the channel range of the moment calculations to those channels with significant emission. One good way to do this is to open the cube in the viewer overlaid with 3-sigma contours, with sigma corresponding to the line-free rms. <br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.04,0.4]},<br />
contour={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
'levels': [0.004],'unit': 5})<br />
</source><br />
<br />
We find a channel range for significant emission of 33~63.<br />
<br />
<source lang="python"><br />
# In CASA<br />
imview(raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
'range': [-0.04,0.4]},<br />
contour={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
'levels': [0.0035],'unit': 5})<br />
</source><br />
<br />
We find a channel range for significant emission of 12~64.<br />
<br />
For moment 0 (integrated intensity) maps you do not typically want to set a flux threshold because this will tend to noise bias your integrated intensity.<br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_North.CO3_2Line.Clean.pcal1.image', <br />
moments=[0],chans='33~63',<br />
outfile='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
moments=[0], chans='12~64', <br />
outfile='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0')<br />
</source><br />
<br />
For higher order moments it is very important to set a conservative flux threshold. Typically something like 3sigma, using sigma from a bright line channel works well. We do this with the '''mask''' parameter in the commands below. When making multiple moments, {{immoments}} appends the appropriate file name suffix to the value of '''outfile'''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_North.CO3_2Line.Clean.pcal1.image', <br />
moments=[1,2], chans='33~63', <br />
mask='Antennae_North.CO3_2Line.Clean.pcal1.image>0.018*3',<br />
outfile='Antennae_North.CO3_2Line.Clean.pcal1.image.mom')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
immoments('Antennae_South.CO3_2Line.Clean.pcal1.image', <br />
moments=[1,2], chans='12~64',<br />
mask=' Antennae_South.CO3_2Line.Clean.pcal1.image>0.009*3',<br />
outfile='Antennae_South.CO3_2Line.Clean.pcal1.image.mom')<br />
</source><br />
<br />
Next we can create the six moment maps<br />
(<xr id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png"/>,<br />
<xr id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"/>,<br />
<xr id="Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"/>,<br />
<xr id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png"/>,<br />
<xr id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png"/>,<br />
<xr id="Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png"/>)<br />
from these images using '''imview'''.<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('rm -f Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
imview (raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image.mom0',<br />
'colorwedge':T,'scaling': -0.5},<br />
zoom=1,out='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
<br />
os.system('rm -f Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
imview (raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
<br />
os.system('rm -f Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png')<br />
imview (raster={'file': 'Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png') <br />
<br />
os.system('rm -f Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
imview (raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image.mom0',<br />
'colorwedge':T,'scaling': -0.5},<br />
zoom=1,out='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.png')<br />
<br />
os.system('rm -f Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
imview (raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.png')<br />
<br />
os.system('rm -f Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png')<br />
imview (raster={'file': 'Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
'colorwedge':T},<br />
zoom=1,out='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.png') <br />
</source><br />
<br />
==== Exporting Images to Fits ====<br />
<br />
If you want to analyze the data using another software package it is easy to convert from CASA format to FITS. <br />
<br />
<source lang="python"><br />
# In CASA<br />
exportfits(imagename='Antennae_North.Cont.Clean.image',<br />
fitsimage='Antennae_North.Cont.Clean.image.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.mom0.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.fits')<br />
exportfits(imagename='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
fitsimage='Antennae_North.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
exportfits(imagename='Antennae_South.Cont.Clean.image',<br />
fitsimage='Antennae_South.Cont.Clean.image.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.mom0.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_coord.fits')<br />
exportfits(imagename='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord',<br />
fitsimage='Antennae_South.CO3_2Line.Clean.pcal1.image.mom.weighted_dispersion_coord.fits')<br />
</source><br />
<br />
Although "FITS format" is supposed to be a standard, in fact most packages expect slightly different things from a FITS image. If you are having difficulty, try setting '''velocity=True''' and/or '''dropstokes=True'''.<br />
<br />
==Comparison with previous SMA CO(3-2) data==<br />
<br />
We compare with SMA CO(3-2) data (Ueda, Iono, Petitpas et al. 2012, ApJ, 745, 65). <xr id="alma_sma_compare.png"/> shows a comparison plot between the moment 0 maps of ALMA and SMA data using the {{viewer}}. The fluxes, peak locations, and large scale structure are consistent. Both southern and northern components have been combined.<br />
<br />
<figure id="alma_sma_compare.png"><br />
[[Image: alma_sma_compare.png|500px|thumb|center|<caption>The CO(3-2) total intensity map (moment 0) comparison with SMA data. Colour image is ALMA data, combining southern and northern mosaics. Contours show SMA data (Ueda, Iono, Petitpas et al. 2012, ApJ, 745, 65).</caption>]]<br />
</figure><br />
{{Checked 4.5.0}}</div>Jthorleyhttps://casaguides.nrao.edu/index.php?title=AntennaeBand7_Calibration_4.5&diff=21234AntennaeBand7 Calibration 4.52017-04-03T17:51:45Z<p>Jthorley: </p>
<hr />
<div>[[Category:ALMA]][[Category:Calibration]][[Category:Spectral Line]]<br />
*'''This guide requires CASA 4.5.0 and assumes that you have downloaded Antennae_Band7_UnCalibratedMSAndTablesForReduction.tgz from [[AntennaeBand7#Obtaining_the_Data]]'''<br />
<br />
*'''Details of the ALMA observations are provided at [[AntennaeBand7]]<br />
<br />
*'''This portion of the guide covers calibration of the raw visibility data. To skip to the imaging portion of the guide, see: [[AntennaeBand7 Imaging 4.5]]'''.<br />
<br />
==Overview==<br />
<br />
This part of the Antennae Band 7 CASA guide will step you through the calibration of the visibility data. We will begin by flagging (marking as bad) data known to be useless before any inspection, for example data where one telescope blocks the line of sight of another. Then we will apply telescope-generated calibration tables to partially correct for atmospheric effects. After inspecting the data, we will flag some additional data that exhibit pathologies. Then we will use observations of the calibrators Titan and 3c279 to derive the phase and amplitude response of individual antennas as a function of time and frequency ("phase", "amplitude", and "bandpass" calibrations). We will apply these to the data and then extract the calibrated source data into a file appropriate for imaging.<br />
<br />
The general procedure in this guide follows the other ALMA CASA guides: [[NGC3256Band3]] and [[TWHydraBand7]].<br />
<br />
==Unpack the Data==<br />
<br />
Once you have downloaded the Antennae_Band7_UnCalibratedMSandTablesForReduction.tgz, unpack the file in a terminal outside CASA using<br />
<br />
<source lang="bash"><br />
<br />
tar -xvzf Antennae_Band7_UnCalibratedMSandTablesForReduction.tgz<br />
<br />
</source><br />
<br />
then change directory to the new directory <br />
<br />
<source lang="bash"><br />
<br />
cd Antennae_Band7_UnCalibratedMSandTablesForReduction<br />
<br />
</source><br />
<br />
You may wish to type<br />
<br />
<source lang="bash"><br />
<br />
ls<br />
<br />
</source><br />
<br />
to look at the files present. You should see a set of files with extension ".ms". These are CASA measurement set (MS) files. The data have already been converted to MS format from the native ALMA format using the CASA task {{importasdm}}. In addition to the data, we provide you with calibration tables containing system temperature (Tsys), water vapor radiometer (WVR), and antenna position information. For Early Science, these tables will either be pre-applied or supplied with the data.<br />
<br />
To begin, start CASA by typing<br />
<br />
<source lang="bash"><br />
<br />
casapy<br />
<br />
</source><br />
<br />
Be sure that you are using the version indicated at the top of this page.<br />
<br />
==Confirm your version of CASA==<br />
<br />
This guide has been written for CASA release 4.5.0. 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.5.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 />
==Initial Inspection==<br />
<br />
First we will take stock of what we have. If you have not already done so, begin by reviewing the description of the observations here: [[AntennaeBand7]]. The 10 data sets each target either the Northern or the Southern Mosaic, as follows:<br />
<br />
Northern Mosaic:<br />
*uid___A002_X1ff7b0_Xb.ms<br />
*uid___A002_X207fe4_X3a.ms<br />
*uid___A002_X207fe4_X3b9.ms<br />
*uid___A002_X2181fb_X49.ms<br />
<br />
Southern Mosaic:<br />
*uid___A002_X1ff7b0_X1c8.ms<br />
*uid___A002_X207fe4_X1f7.ms<br />
*uid___A002_X207fe4_X4d7.ms<br />
*uid___A002_X215db8_X18.ms<br />
*uid___A002_X215db8_X1d5.ms<br />
*uid___A002_X215db8_X392.ms<br />
<br />
The first step is to get basic information about the data: targets observed, time range, spectral setup, and so on. We do this using the task {{listobs}}, which will output a detailed summary of each dataset. Enter the following commands into CASA:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Define a python list holding the names of all of our data sets<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
# Initialize user-input string. (for Python testing)<br />
dummy_string = ''<br />
<br />
# Loop over each element in the list and create summary file using listobs<br />
for asdm in basename_all:<br />
os.system('rm '+asdm+'.listobs.txt')<br />
listobs(vis=asdm+'.ms', listfile=asdm+'.listobs.txt', verbose=True)<br />
</source><br />
<br />
Note that after cutting and pasting a 'for' loop like this you often have to press return twice to execute. You may also want to take care to paste a line at a time if you are having trouble copy and pasting. Even better, you can use "cpaste" to paste blocks of code. To do so type "cpaste" at the CASA prompt, paste your commands, and then type "--" and hit return on the final (otherwise empty) line. This should look something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
CASA <8>: cpaste<br />
Pasting code; enter '--' alone on the line to stop.<br />
:basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
: "uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
: "uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
: "uid___A002_X215db8_X392"]<br />
:<br />
:for asdm in basename_all:<br />
: print asdm<br />
:--<br />
uid___A002_X1ff7b0_Xb<br />
uid___A002_X207fe4_X3a<br />
uid___A002_X207fe4_X3b9<br />
uid___A002_X2181fb_X49<br />
uid___A002_X1ff7b0_X1c8<br />
uid___A002_X207fe4_X1f7<br />
uid___A002_X207fe4_X4d7<br />
uid___A002_X215db8_X18<br />
uid___A002_X215db8_X1d5<br />
uid___A002_X215db8_X392<br />
<br />
CASA <9>: <br />
<br />
</pre><br />
<br />
cpaste should be ''much'' more robust than copying-and-pasting directly into the shell but if you have trouble, just carefully paste one line at a time directly into CASA and hit return until the desired command executes.<br />
<br />
These commands define a python list called "basename_all", which contains the name of all 10 MS files. The "for" loop executes for each element in basename_all, calling listobs and directing the output to a file called, e.g., "uid___A002_X1ff7b0_Xb.listobs.txt" for the first measurement set. You can browse through the listobs output as you would normally look at a text file (use emacs, vi, or another editor). You can also send the output to the terminal from inside of CASA. To do so type:<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('cat uid___A002_X1ff7b0_Xb.listobs.txt')<br />
</source><br />
<br />
or<br />
<br />
<source lang="python"><br />
# In CASA<br />
os.system('more uid___A002_X1ff7b0_Xb.listobs.txt')<br />
</source><br />
<br />
CASA knows a few basic shell commands like 'cat', 'ls', and 'rm' but for more complex commands you will need to run them inside 'os.system("command")'. For more information see http://casa.nrao.edu/ .<br />
<br />
Here is an example of the (abridged) output from {{listobs}} for the first dataset in the list, uid___A002_X1ff7b0_Xb.ms, which targets the Northern Mosaic. You would see this if you had specified '''verbose''' to be False in the listobs call:<br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: /lustre/naasc/almauser/AntennaeBand7/uid___A002_X1ff7b0_Xb.ms MS Version 2<br />
================================================================================<br />
Observer: Unknown Project: T.B.D. <br />
Observation: ALMA(11 antennas)<br />
Data records: 181357 Total integration time = 4931.71 seconds<br />
Observed from 28-May-2011/01:25:27.6 to 28-May-2011/02:47:39.3 (UTC)<br />
<br />
Fields: 26<br />
ID Code Name RA Decl Epoch SrcId nRows <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 39116 <br />
1 none Titan 12:42:43.94813 -01.43.38.3190 J2000 1 10626 <br />
2 none NGC4038 - Antennae *12:01:53.17008 -18.52.37.9200 J2000 2 4818 <br />
3 none NGC4038 - Antennae *12:01:51.90301 -18.51.49.9437 J2000 2 6435 <br />
4 none NGC4038 - Antennae *12:01:52.43086 -18.51.49.9437 J2000 2 6424 <br />
5 none NGC4038 - Antennae *12:01:52.95871 -18.51.49.9437 J2000 2 5478 <br />
6 none NGC4038 - Antennae *12:01:53.48656 -18.51.49.9436 J2000 2 6435 <br />
7 none NGC4038 - Antennae *12:01:54.01441 -18.51.49.9436 J2000 2 6446 <br />
8 none NGC4038 - Antennae *12:01:52.16693 -18.51.56.4319 J2000 2 6435 <br />
9 none NGC4038 - Antennae *12:01:52.69478 -18.51.56.4318 J2000 2 6424 <br />
10 none NGC4038 - Antennae *12:01:53.22263 -18.51.56.4318 J2000 2 6446 <br />
11 none NGC4038 - Antennae *12:01:53.75049 -18.51.56.4318 J2000 2 6446 <br />
12 none NGC4038 - Antennae *12:01:51.90301 -18.52.02.9201 J2000 2 6435 <br />
13 none NGC4038 - Antennae *12:01:52.43086 -18.52.02.9200 J2000 2 6424 <br />
14 none NGC4038 - Antennae *12:01:52.95871 -18.52.02.9200 J2000 2 4818 <br />
15 none NGC4038 - Antennae *12:01:53.48656 -18.52.02.9200 J2000 2 4829 <br />
16 none NGC4038 - Antennae *12:01:54.01441 -18.52.02.9199 J2000 2 4829 <br />
17 none NGC4038 - Antennae *12:01:52.16694 -18.52.09.4082 J2000 2 4829 <br />
18 none NGC4038 - Antennae *12:01:52.69479 -18.52.09.4082 J2000 2 4829 <br />
19 none NGC4038 - Antennae *12:01:53.22264 -18.52.09.4082 J2000 2 3872 <br />
20 none NGC4038 - Antennae *12:01:53.75049 -18.52.09.4081 J2000 2 4829 <br />
21 none NGC4038 - Antennae *12:01:51.90301 -18.52.15.8964 J2000 2 4829 <br />
22 none NGC4038 - Antennae *12:01:52.43087 -18.52.15.8964 J2000 2 4829 <br />
23 none NGC4038 - Antennae *12:01:52.95872 -18.52.15.8963 J2000 2 4818 <br />
24 none NGC4038 - Antennae *12:01:53.48657 -18.52.15.8963 J2000 2 4818 <br />
25 none NGC4038 - Antennae *12:01:54.01442 -18.52.15.8963 J2000 2 4840 <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 3840 TOPO 344845.586 488.28125 1875000 XX YY <br />
2 1 TOPO 343908.086 1875000 1875000 XX YY <br />
3 3840 TOPO 354971.074 488.28125 1875000 XX YY <br />
4 1 TOPO 343908.086 1875000 1875000 XX YY <br />
5 128 TOPO 344900.518 15625 2000000 XX YY <br />
6 1 TOPO 343892.705 1796875 1796875 XX YY <br />
7 128 TOPO 354916.143 15625 2000000 XX YY <br />
8 1 TOPO 343892.705 1796875 1796875 XX YY <br />
Antennas: 11 'name'='station' <br />
ID= 0-3: 'DV02'='A015', 'DV04'='J505', 'DV06'='T704', 'DV07'='A004', <br />
ID= 4-7: 'DV08'='A072', 'DV09'='A008', 'DV10'='A009', 'DV11'='A016', <br />
ID= 8-10: 'PM01'='T702', 'PM02'='A017', 'PM03'='J504'<br />
================================================================================<br />
<br />
</pre><br />
<br />
And here is an extract from the full '''verbose''' {{listobs}} for uid___A002_X1ff7b0_X1c8.ms, which targets the Southern Mosaic (note that we have snipped out the record of individual scans):<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
================================================================================<br />
MeasurementSet Name: /lustre/naasc/almauser/AntennaeBand7/uid___A002_X1ff7b0_X1c8.ms MS Version 2<br />
================================================================================<br />
Observer: Unknown Project: T.B.D. <br />
Observation: ALMA<br />
Data records: 175615 Total integration time = 4927.1 seconds<br />
Observed from 28-May-2011/02:50:18.2 to 28-May-2011/04:12:25.3 (UTC)<br />
<br />
<snip><br />
<br />
Fields: 33<br />
ID Code Name RA Decl Epoch SrcId nVis <br />
0 none 3c279 12:56:11.16657 -05.47.21.5247 J2000 0 12232 <br />
1 none Titan 12:42:44.82765 -01.43.41.4224 J2000 1 10615 <br />
2 none 3c279 12:56:11.16600 -05.47.21.5250 J2000 2 27764 <br />
3 none Antennae 12:01:53.17008 -18.52.37.9200 J2000 3 4829 <br />
4 none Antennae 12:01:52.18699 -18.53.30.3952 J2000 3 3883 <br />
5 none Antennae 12:01:52.64413 -18.53.26.6494 J2000 3 3883 <br />
6 none Antennae 12:01:53.10127 -18.53.22.9035 J2000 3 3872 <br />
7 none Antennae 12:01:53.55841 -18.53.19.1577 J2000 3 4818 <br />
8 none Antennae 12:01:54.01554 -18.53.15.4119 J2000 3 4829 <br />
9 none Antennae 12:01:54.47268 -18.53.11.6661 J2000 3 4829 <br />
10 none Antennae 12:01:54.92982 -18.53.07.9203 J2000 3 3872 <br />
11 none Antennae 12:01:55.38696 -18.53.04.1744 J2000 3 3883 <br />
12 none Antennae 12:01:55.84409 -18.53.00.4286 J2000 3 4840 <br />
13 none Antennae 12:01:56.30123 -18.52.56.6828 J2000 3 4818 <br />
14 none Antennae 12:01:52.18700 -18.53.22.9033 J2000 3 4829 <br />
15 none Antennae 12:01:52.64414 -18.53.19.1575 J2000 3 4818 <br />
16 none Antennae 12:01:53.10128 -18.53.15.4116 J2000 3 4818 <br />
17 none Antennae 12:01:53.55842 -18.53.11.6658 J2000 3 4840 <br />
18 none Antennae 12:01:54.01555 -18.53.07.9200 J2000 3 3872 <br />
19 none Antennae 12:01:54.47269 -18.53.04.1742 J2000 3 4829 <br />
20 none Antennae 12:01:54.92983 -18.53.00.4284 J2000 3 4829 <br />
21 none Antennae 12:01:55.38697 -18.52.56.6825 J2000 3 4829 <br />
22 none Antennae 12:01:55.84410 -18.52.52.9367 J2000 3 4829 <br />
23 none Antennae 12:01:51.72988 -18.53.19.1572 J2000 3 4818 <br />
24 none Antennae 12:01:52.18702 -18.53.15.4114 J2000 3 4829 <br />
25 none Antennae 12:01:52.64415 -18.53.11.6656 J2000 3 4829 <br />
26 none Antennae 12:01:53.10129 -18.53.07.9197 J2000 3 2266 <br />
27 none Antennae 12:01:53.55843 -18.53.04.1739 J2000 3 2266 <br />
28 none Antennae 12:01:54.01557 -18.53.00.4281 J2000 3 3212 <br />
29 none Antennae 12:01:54.47270 -18.52.56.6823 J2000 3 3234 <br />
30 none Antennae 12:01:54.92984 -18.52.52.9365 J2000 3 3212 <br />
31 none Antennae 12:01:55.38698 -18.52.49.1906 J2000 3 2266 <br />
32 none Antennae 12:01:55.84411 -18.52.45.4448 J2000 3 3223 <br />
(nVis = Total number of time/baseline visibilities per field) <br />
Spectral Windows: (9 unique spectral windows and 2 unique polarization setups)<br />
SpwID #Chans Frame Ch1(MHz) ChanWid(kHz) TotBW(kHz) Corrs <br />
0 4 TOPO 184550 1500000 7500000 I <br />
1 3840 TOPO 344845.586 488.28125 1875000 XX YY <br />
2 1 TOPO 343908.086 1875000 1875000 XX YY <br />
3 3840 TOPO 356845.586 488.28125 1875000 XX YY <br />
4 1 TOPO 343908.086 1875000 1875000 XX YY <br />
5 128 TOPO 344900.518 15625 2000000 XX YY <br />
6 1 TOPO 343892.705 1796875 1796875 XX YY <br />
7 128 TOPO 356900.518 15625 2000000 XX YY <br />
8 1 TOPO 343892.705 1796875 1796875 XX YY <br />
Antennas: 11:<br />
ID Name Station Diam. Long. Lat. <br />
0 DV02 A015 12.0 m -067.45.15.3 -22.53.26.0 <br />
1 DV04 J505 12.0 m -067.45.18.0 -22.53.22.8 <br />
2 DV06 T704 12.0 m -067.45.16.2 -22.53.22.1 <br />
3 DV07 A004 12.0 m -067.45.15.9 -22.53.28.0 <br />
4 DV08 A072 12.0 m -067.45.12.6 -22.53.24.0 <br />
5 DV09 A008 12.0 m -067.45.15.4 -22.53.26.8 <br />
6 DV10 A009 12.0 m -067.45.16.1 -22.53.26.1 <br />
7 DV11 A016 12.0 m -067.45.16.4 -22.53.25.1 <br />
8 PM01 T702 12.0 m -067.45.18.6 -22.53.24.1 <br />
9 PM02 A017 12.0 m -067.45.15.9 -22.53.26.8 <br />
10 PM03 J504 12.0 m -067.45.17.0 -22.53.23.0 <br />
</pre><br />
<br />
This output shows that three sources were observed in each data set: 3c279, Titan, and the Antennae.<br />
<br />
* The '''Antennae''' are our science target. Note that the source name changes between the Northern Mosaic, where it is "NGC4038 - Antennae", and the Southern Mosaic, where it is just "Antennae". Also note that the source corresponds to a number of individual fields (see the Field ID column). These are the individual mosaic pointings. There are 23 for the Northern Mosaic and 29 for the Southern Mosaic.<br />
* '''Titan''' is observed once and will be used to set the absolute flux scale of the data.<br />
* '''3c279''' plays two roles: it will serve as our bandpass calibrator, to characterize the frequency response of the antennas, and because it is fairly close on the sky to the Antennae (18.6 degrees away) it will serve as our secondary calibrator (also referred to as the "phase calibrator" or "gain calibrator"), to track changes in the phase and amplitude response of the telescopes over time. Observations of 3c279 are interleaved with observations of the Antennae.<br />
<br />
The output also shows that the data contain many spectral windows. Using the labeling scheme in the listobs above these are:<br />
<br />
* '''spw 0''' targets ~185 GHz and holds water vapor radiometer data<br />
* '''spw 1''' and '''spw 3''' hold our science data. These are "Frequency Domain Mode" (FDM) data with small (0.49 MHz) channel width and wide (1.875 GHz) total bandwidth. As a result these have a lot of channels (3840). spw 1 holds the lower sideband (LSB) data and includes the CO(3-2) line. We will focus on these data. For the CO(3-2) line the channel width corresponds to 0.426 km/s and the bandwidth of spw 1 to 1634 km/s.<br />
* '''spw 2''' and '''spw 4''' hold frequency-averaged versions of spw 1 and 3 ("Channel 0" for those familiar with AIPS). These are used for some quick automated inspection. We will not use them here but we will carry out an equivalent inspection using spw 1.<br />
* '''spw 5''' and '''spw 7''' hold lower a resolution processing ("Time Domain Mode", TDM) of the data from the same part of the spectrum (baseband) as spws 1 and 3. These data have only 128 channels across 2 GHz bandwidth and so have a much coarser channel spacing than the FDM data. These were used to generate the calibration tables that we include in the tarball but will not otherwise appear in this guide.<br />
<br />
The final column of the listobs output in the logger (not shown above) gives the scan intent. Later we will use this information to flag the pointing scans and the hot and ambient load calibration scans.<br />
<br />
We'll now have a look at the configuration of the antennas used to take the data using the task {{plotants}} (<xr id="Uid_A002_X1ff7b0_Xb.ANT.png"/>).<br />
<br />
<figure id="Uid_A002_X1ff7b0_Xb.ANT.png"><br />
[[File:Uid_A002_X1ff7b0_Xb.ANT.png|200px|thumb|right|<caption> Position of antennas in dataset uid_A002_X1ff7b0_Xb obtained using task {{plotants}}</caption>]]<br />
</figure><br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
<br />
for asdm in basename_all:<br />
print "Antenna configuration for : "+asdm<br />
plotants(vis=asdm+'.ms', figfile=asdm+'.plotants.png')<br />
clearstat()<br />
dummy_string = raw_input("Hit <Enter> to see the antenna configuration for the next data set.")<br />
</source> <br />
<br />
This will loop through all 10 data sets, show you the antenna position for each, and save that as a file named, e.g., "uid___A002_X1ff7b0_Xb.plotants.png" for the first data set. The "raw_input" command asks CASA to wait for your input before proceeding. If you would prefer to just browse the .png files after the fact you can remove this. Notice that the antenna setup changes, but only slightly, over the course of the 10 data sets.<br />
<br />
==How to Deal With 10 Measurement Sets==<br />
<br />
It should already be clear from the initial inspection that dealing with 10 data sets at the same time can be a bit problematic. This is especially tricky in our case because the Antennae data contain two distinct sets of observations: the Northern and Southern Mosaics. The source name changes between these two scripts and there are different numbers of fields in the mosaic.<br />
<br />
''As a general rule one would reduce each individual observation separately or at the very least only group data observed in a uniform way and very close in time.'' <br />
<br />
Unfortunately, a CASA Guide stepping through the reduction for each of 10 data sets would quickly become unwieldy. Therefore we will use a few tricks to reduce the Antennae data in a kind of batch mode. You have already seen the first trick: we can define a python list holding the names of each data set and then loop over this list to execute the same command on each data set. For example:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print asdm<br />
</source><br />
<br />
You only need to define your list of MS files once per CASA session. Then "basename_all" will be a variable in the casapy shell. You can check if it exists by typing "print basename_all". In the interests of allowing you to easily exit and restart CASA and pick this guide up at any point we will redefine "basename_all" in each section of the guide. Feel free to skip this step if you've already defined it in your session.<br />
<br />
This page will step you through the reduction of the whole Antennae Band 7 SV data set using these 'for' loops. We will not be able to show every diagnostic plot but we give an example of each and the syntax to generate the rest. Also please be aware that even on a very fast machine this whole process can take a while, we are simply dealing with a lot of data.<br />
<br />
One potential "gotcha" is that the source name changes between the two data sets. Therefore at several points we will break apart our loop to iterate separately over the Northern and Southern Mosaics, where the source can be referred unambiguously. Another subtle point is that 3c279 appears with two distinct field IDs in the Southern Mosaic, but only one in the Northern Mosaic. We will largely avoid this by referring to the source by its name but if you tried to use field ID numbers and mingled the two data sets this could cause confusion.<br />
<br />
==''A Priori'' Flagging==<br />
<br />
Even before we look in detail, we know that there are some data that we wish to exclude. We will start by flagging "shadowed" data where one antenna blocks the line of sight of another. We will also flag scans that were used to carry out pointing and atmospheric calibration, identified by their scan intent. Finally, we'll flag the autocorrelation data (the correlation of the signal from an antenna with itself) as we are only interested in cross-correlation data to make an interferometric image.<br />
<br />
Start by defining our list of MS files:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
</source><br />
<br />
You may want to reset the flagging if you have tried this step before and are starting over though this is not necessary on your first time through. Do so using {{flagdata}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Resetting flags for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='unflag', flagbackup=False)<br />
</source><br />
<br />
Then flag shadowed data using the command {{flagdata}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Flagging shadowed data for "+asdm<br />
flagdata(vis=asdm+'.ms',mode = 'shadow', flagbackup = False)<br />
</source><br />
<br />
In the {{flagdata}} task we choose:<br />
<br />
* '''vis''' = asdm+'.ms' : each measurement set<br />
* '''mode''' = 'shadow': flag shadowed data<br />
* '''flagbackup''' = F: Do not automatically back up the flag files. We will save all of the ''a priori'' flags together using {{flagmanager}} at the end of this subsection and save some space and time.<br />
<br />
The relevant calibration information has already been extracted from the pointing and atmospheric scans and we will not need them below. Now flag the pointing scans using {{flagdata}} in 'manualflag' mode and selecting on 'intent':<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Flagging calibration scans for "+asdm<br />
flagdata(vis=asdm+'.ms', mode='manual', intent='*POINTING*', flagbackup = False)<br />
</source><br />
<br />
Note that because the atmospheric calibration scans contain only TDM spectral windows, they will be removed automatically when we separate out the FDM data below.<br />
<br />
Now flag the autocorrelation data:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Flagging autocorrelation data for "+asdm<br />
flagdata(vis=asdm+'.ms',autocorr=True,flagbackup=False)<br />
</source><br />
<br />
Finally store the current flags information using {{flagmanager}}: <br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Backing up 'a priori' flags for "+asdm<br />
flagmanager(vis = asdm+'.ms', mode = 'save', versionname = 'Apriori')<br />
</source><br />
<br />
Where '''versionname''' is just the name we assign to the current flagging state in the data. We can now roll back the flags to match the current version, called 'Apriori', whenever we want. There is no reason to do this now, but the syntax would be:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
print "Restoring up 'a priori' flags for "+asdm<br />
flagmanager(vis = asdm+'.ms', mode = 'restore', versionname = 'Apriori')<br />
</source><br />
<br />
<br />
It would have been possible to set {{flagdata}} to '''flagbackup'''=True so that it stores the flags at each of the flagging step automatically, but this way it is a bit more efficient with regard to time and disk space. More important, lumping all the ''a priori'' flagging together gives us a natural point to roll back to if we get in trouble.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
The flagmanager task will also allow you to view the saved flagging versions,<br />
including those created by running flagdata with flagbackup=True.<br />
<br />
For example try <br />
<br />
flagmanager(vis='uid___A002_X2181fb_X49.ms', mode='list')<br />
<br />
The output in the logger should list the Apriori flagging that we have applied.<br />
It will also indicate versions associated with any flagdata command where you<br />
did not set flagbackup=False. Other tasks, for example applycal, will also create<br />
flag version tables.<br />
</pre><br />
<br />
==Create and Apply Tsys, WVR, and Antenna Position Calibration Tables==<br />
<br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
</source><br />
<br />
===Tsys===<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 persists through imaging.<br />
<br />
Use gencal to create the Tsys calibration tables from the spectral windows with CALIBRATE_ATMOSPHERE intents in listobs (i.e. the TDM spectral windows with 128 channels), these are spectral windows 5 and 7.<br />
<br />
<source lang="python"><br />
#In CASA<br />
#Removing existing Tsys information<br />
os.system('rm -rf *tdm.tsys')<br />
for asdm in basename_all:<br />
print "Creating TDM Tsys Table for "+asdm<br />
gencal(vis=asdm+'.ms',caltable=asdm+'.tdm.tsys',spw='5,7',caltype='tsys')<br />
</source><br />
<br />
Later in the applycal stage this TDM Tsys table will be interpolated to the FDM (3840 channels per spw) science spectral windows 1 and 3.<br />
<br />
Next we inspect the Tsys tables for the spectral window spw=5 with the task {{plotcal}}. We want to check that Tsys data have reasonable values and identify any unexpected features as a function of either time or frequency. To get an idea of sensible Tsys under average atmospheric observations consult the ALMA sensitivity calculator, accessible from http://www.almascience.org (via the "Documents & Tools" link).<br />
<br />
We start by plotting the Tsys for all the antennas and polarizations (XX and YY) as a function of time for each. Here and throughout we focus on spw 1, which contains CO(3-2):<br />
<figure id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page1.png"><br />
[[File:uid___A002_X1ff7b0_X1c8.tsys_vs_time.page1.png|200px|thumb|right|<caption> Tsys vs. time plot for uid_A002_X1ff7b0_Xb (northern mosaic). First 8 antennas. Note the high y-axis values for DV04. The two different colors indicate the two polarizations (XX and YY).</caption>]]<br />
</figure><br />
<figure id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page2.png"><br />
[[File:uid___A002_X1ff7b0_X1c8.tsys_vs_time.page2.png|200px|thumb|right|<caption> Tsys vs. time plot for uid_A002_X1ff7b0_Xb (northern mosaic). Remaining antennas.</caption>]]<br />
</figure><br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Plotting Tsys vs. time for "+asdm<br />
plotcal(caltable=asdm+'.tdm.tsys', <br />
xaxis="time",yaxis="tsys",<br />
spw='5:50~50',plotsymbol=".", subplot=421,<br />
antenna='0~7',<br />
iteration='antenna', figfile=asdm+'.tsys_vs_time.page1.png',<br />
fontsize=7.0) <br />
#dummy_string = raw_input("First eight antennas for "+asdm+" . Hit <Enter> to continue.")<br />
plotcal(caltable=asdm+'.tdm.tsys', <br />
xaxis="time",yaxis="tsys",<br />
antenna='8~15',<br />
spw='5:50~50',plotsymbol=".", subplot=421,<br />
iteration='antenna', figfile=asdm+'.tsys_vs_time.page2.png',<br />
fontsize=7.0) <br />
#dummy_string = raw_input("Remaining antennas for "+asdm+" . Hit <Enter> to continue.")<br />
</source><br />
<br />
This sequence loops over all of our files and plots Tsys as a function of time for channel 50 in spectral window 5. In the call to {{plotcal}}:<br />
<br />
* '''subplot'''=421 parameter sets up a 4 x 2 panel grid. <br />
* '''iteration''' tells {{plotcal}} to make a separate plot for each antenna.<br />
* '''spw''' '5:50~50' selects spw '5' channel 50-50. This allows us to cleanly separate time variations from frequency variations.<br />
<br />
Because 8 panels (2 panels for each antenna - LSB and USB) is not enough to show all antennas on one page, there are two plotcal calls: one for the first 8 antennas ('''antenna'''=0~7), and then for the remaining antennas ('''antenna'''=8~15). The '''fontsize''' needs to be set to a small value or the text overlaps.<br />
<br />
The 'raw_input' commands will wait for you to hit Enter before issuing the next plot command. In the example above these are commented out (the leading "#" means that CASA will ignore them). If you would like to interactively cycle through the plots, uncomment them by removing the "#". Otherwise, the '''figfile''' parameter directs the output to .png files for later inspection. The easiest way to look at the 20 plots produced here is to simply inspect the .png files using your favorite viewer.<br />
<br />
The Tsys values in <xr id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page1.png"/> and <xr id="uid___A002_X1ff7b0_X1c8.tsys_vs_time.page2.png"/> look reliable, with typical values ~150 K except for some large values of Tsys at ~400 and 500 K for DV04. We will flag the data for that antenna later. <br />
<br />
We will also want to look at Tsys as a function of frequency. <br />
<br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
os.system('rm -rf cal_plots/Tsys_plots/'+asdm+'.tdm.tsys*')<br />
tsysfields=['3c279','Titan','*Antennae*']<br />
caltable=asdm+'.tdm.tsys'<br />
for field in tsysfields:<br />
plotbandpass(caltable=caltable,yaxis='amp',field=field,xaxis='freq',<br />
showatm=True,overlay='time',<br />
figfile='cal_plots/Tsys_plots/'+caltable+'.'+field,<br />
buildpdf=False,interactive=False,chanrange='8~120',subplot=42)<br />
</source><br />
<br />
<figure id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid_A002_X1ff7b0_Xb (northern mosaic). First 4 antennas. Note the high y-axis values for DV04 and the mesospheric line near 343.2 GHz.</caption>]]<br />
</figure><br />
<figure id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV08.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV08.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid_A002_X1ff7b0_Xb (northern mosaic). Next 4 antennas.</caption>]]<br />
</figure><br />
<figure id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid_A002_X1ff7b0_Xb (northern mosaic). Remaining antennas.</caption>]]<br />
</figure><br />
<br />
<figure id="Uid___A002_X215db8_X392.tdm.tsys.3c279.DV11.spw5.CASA3_4.png"><br />
[[File:Uid___A002_X215db8_X392.tdm.tsys.3c279.DV11.spw5.CASA3_4.png|200px|thumb|right|<caption> Tsys vs. frequency plot for uid___A002_X215db8_X392. Note the pathological behavior for DV12.</caption>]]<br />
</figure><br />
<br />
Now have a look at the Tsys vs. frequency plots or see <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png"/>, <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV08.spw5.CASA3_4.png"/>, and <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png"/> for examples on the first data set. You can see the effect of a close pair of atmospheric ozone absorption lines at about 343.2 GHz that makes Tsys larger near that frequency in all antennas. Applying the Tsys calibration tables will minimize the contribution of these atmospheric lines. Again DV04 stands out with its very high Tsys. Although not present in the first data sets, Antenna DV12 exhibits periodic spikes in Tsys vs. frequency for one polarization (see <xr id="Uid___A002_X215db8_X392.tdm.tsys.3c279.DV11.spw5.CASA3_4.png"/> for an example from a later data set). It may or may not be possible to calibrate that behavior out. We will make a note to look carefully at DV12 further on in the calibration process.<br />
<br />
===WVR===<br />
The WVR calibration uses observations of the wings of the 183 GHz atmospheric water line to correct for phase variations as a function of time. As noted in the tsys section, this run of gencal will append to existing WVR produced tables. To avoid this, preexisting wvrgcal data is removed. <br />
<source lang="python"><br />
#In CASA<br />
#Removing existing WVR information<br />
os.system('rm -rf *.wvrgcal')<br />
for asdm in basename_all:<br />
wvrgcal(vis=asdm+'.ms',caltable=asdm+'.wvrgcal',toffset=-1)<br />
</source><br />
<br />
===Antenna Positions===<br />
The antenna position table reflects refinements in the measured positions of the antennas from those stored in the data. gencal will now be used put antenna position data into each observation. Again, gencal will merely append to existing antenna position data, ruining any subsequent results. We start by removing any existing antenna position refinements, followed by defining the antenna names, then their refinements (both as arrays), finally running gencal to create the information CASA can refer to for antenna positions.<br />
<source lang="python"><br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X1ff7b0_Xb.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:21]+'.antpos')<br />
antenna='DV02,DV04,DV06,DV07,DV08,DV09,DV10,DV11,PM01,PM02,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00034, 0.00092, 0.00027, #PM02-A017 Before July 1<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X3a.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:22]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X3b9.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X2181fb_X49.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:22]+'.antpos')<br />
antenna='DV01,DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
-0.00004, 0.00026, 0.00019, #DV01-A137<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X1ff7b0_X1c8.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV06,DV07,DV08,DV09,DV10,DV11,PM01,PM02,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00034, 0.00092, 0.00027, #PM02-A017 Before July 1<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X1f7.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X207fe4_X4d7.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV11,DV12,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X215db8_X18.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:22]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X215db8_X1d5.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
<br />
#In CASA<br />
#The measurement set we are refining the antenna positions for<br />
data='uid___A002_X215db8_X392.ms'<br />
#Removing existing antenna refinements<br />
os.system('rm -rf '+data[0:23]+'.antpos')<br />
antenna='DV02,DV04,DV05,DV06,DV07,DV08,DV09,DV10,DV11,DV12,DV13,PM01,PM03'<br />
parameter = [<br />
0.00000, 0.00000, 0.00000, #DV02-A015<br />
-0.00004, 0.00059, 0.00024, #DV04-J505<br />
-0.00019,-0.00003, 0.00035, #DV05-A067<br />
-0.00027, 0.00033, 0.00022, #DV06-T704<br />
0.00006, 0.00057, 0.00032, #DV07-A004<br />
-0.00027, 0.00025,-0.00003, #DV08-A072<br />
-0.00037, 0.00025, 0.00003, #DV09-A008<br />
-0.00056, 0.00028, 0.00026, #DV10-A009<br />
-0.00028, 0.00024, 0.00011, #DV11-A016<br />
-0.00018, 0.00010,-0.00014, #DV12-A011<br />
0.00009, 0.00033, 0.00023, #DV13-A075<br />
-0.00017, 0.00013, 0.00030, #PM01-T702<br />
-0.00007, 0.00034, -0.00004] #PM03-J504 <br />
gencal(vis=data,caltable='%s.antpos'%(data.split('.')[0]),caltype='antpos',<br />
antenna=antenna,parameter=parameter)<br />
</source><br />
<br />
===Applycal===<br />
<br />
We are now ready to apply the Tsys and the WVR calibration tables to the data with {{applycal}}, which reads the specified gain calibration tables, applies them to the (raw) data column, and writes the calibrated results into the corrected column. Again, we loop through all the datasets. It is important to only apply Tsys and WVR corrections obtained close in time to the data being corrected, so in addition to looping over data sets we define the list of unique source names and loop over these. Then by setting '''gainfield''' and '''field''' to the same value we ensure that Tsys and WVR calibrations are only applied to the source for which they are measured. Because the source has a different name in the Northern Mosaic and the Southern Mosaic, we will carry out two loops. We will only correct '''spw''' 1 and 3, our science windows, because we will drop the other data in a moment.<br />
<br />
The applycal task now has much more flexibility for interpolating and applying calibrations derived in one spectral window to another, even if they do not share the same spectral shape (number of channels and channel width). This new functionality is used below to interpolate the TDM (128 channel) Tsys measurements to the FDM (3840 channel) spectral windows. This is controlled through the spectral window mapping parameter *spwmap*. Because this can be a bit confusing, we've written a "helper" function that will tell you what you should put for the Tsys calibration table part of spwmap. We only need to run it on one of the datasets because they are all the same in this regard<br />
<br />
<source lang="python"><br />
# In CASA<br />
from recipes.almahelpers import tsysspwmap<br />
tsysspwmap(vis='uid___A002_X207fe4_X3a.ms',tsystable='uid___A002_X207fe4_X3a.tdm.tsys')<br />
</source><br />
<br />
This will print to your screen: [0, 5, 5, 7, 5, 5, 5, 7]. Recall that the TDM spectral windows are spw=5 and 7 and the FDM spectral windows are 1 and 3. This spwmap tells applycal to use the Tsys information in spectral window 5 for spectral window 1; and to use the information in spectral window 7 for spectral window 3. Beyond that, it is only important that there are placeholders for the other spectral windows, its also useful to note that you need not give placeholders for spectral window ids larger than the largest spectral window you need to use, in this case 7.<br />
<br />
You will also need to put in placeholders for other tables that you give the gaintables. So if the Tsys table is 2nd in the list, spwmap=[[],[0,5,5,7,5,5,5,7],[]]<br />
<br />
Now run the applycal commands.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# A new list of file names that contain only data from the Northern Mosaic<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
field_names_north = ['Titan','3c279','NGC*']<br />
<br />
for asdm in basename_north:<br />
print "Apply Tsys, WVR, and Antenna Position calibrations to "+asdm<br />
for field in field_names_north:<br />
applycal(vis=asdm+".ms", spw='1,3', <br />
field=field, gainfield=['',field,field],<br />
interp=['','linear,spline','nearest'], <br />
gaintable=[asdm+'.antpos',asdm+'.tdm.tsys',asdm+'.wvrgcal'],<br />
spwmap=[[],[0, 5, 5, 7, 5, 5, 5, 7],[]],<br />
flagbackup=False, calwt=True)<br />
<br />
# A new list of file names that contain only data from the Southern Mosaic<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
field_names_south = ['Titan','3c279','Ant*']<br />
<br />
for asdm in basename_south:<br />
print "Apply Tsys, WVR, and Antenna Position calibrations to "+asdm<br />
for field in field_names_south:<br />
applycal(vis=asdm+".ms", spw='1,3', <br />
field=field, gainfield=["",field,field],<br />
interp=['','linear,spline','nearest'],<br />
gaintable=[asdm+".antpos",asdm+'.tdm.tsys',asdm+'.wvrgcal'],<br />
spwmap=[[],[0, 5, 5, 7, 5, 5, 5, 7],[]], <br />
flagbackup=False, calwt=True)<br />
</source><br />
<br />
where:<br />
<br />
*'''field''': the field ''to'' which we will apply the calibration, <br />
*'''gainfield''': the field ''from'' which we wish to take the calibration table<br />
*'''interp''' = 'nearest' : apply the nearest solution from the calibration table rather than interpolating.<br />
<br />
As you browse through the whole data set, you will probably note some problems along the same lines as the DV04 issue we saw above. We'll apply these as additional data flagging in just a moment.<br />
<br />
==Inspect Data==<br />
We are not quite done with the original ".ms" data sets yet. Before going further it will be useful to use {{plotms}} to show the effects of applying the calibration. In the process we'll take a quick look at each antenna and search for pathologies in the data.<br />
<br />
For this basic inspection, we want to compare the phase and amplitude as a function of frequency and time in the DATA and CORRECTED columns of each measurement set. The CORRECTED column has had the Tsys and WVR calibrations applied and so we expect lower phase scatter and flatter amplitude response as a function of time and frequency. We are looking for antenna-based issues, so cycling through a set of baselines that includes each antenna once will be a good start. We'll focus these plots on the phase+bandpass calibrator, 3c279, and on baselines that include antenna DV11, which we will make our reference antenna in just a bit.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
<br />
Each CASA Measurement Set has up to three "columns" of data: DATA, CORRECTED, and MODEL (though it is possible<br />
for a MS to hold only a DATA column if it has not been processed at all). <br />
<br />
A column entry exists for each data point (baseline, frequency, time). <br />
<br />
The DATA column holds the current raw data, though using split as we just did we can change the definition of<br />
"raw" data. <br />
<br />
The CORRECTED column holds the result of applying one or more calibration tables (e.g., via applycal) to the<br />
DATA column and so represents a corrected version of the DATA column. <br />
<br />
The MODEL column is now deprecated (though it is still possible to use it by explicitly setting usescratch=True).<br />
Instead, the model is stored in the header of the ms. This is a great step forward in terms of saving space and time <br />
to create scratch columns <br />
<br />
To get an intuitive feel for the columns you may wish to explore using plotms (which can plot different data <br />
columns, as seen below) or the browsetable task.<br />
<br />
</pre><br />
<br />
<figure id="plotms_amp_vs_freq_example-data.png"><br />
[[File:plotms_amp_vs_freq_example-data.png|200px|thumb|right|<caption> Example of Amplitude vs. Frequency before correction for the first Northern Mosaic data set.</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_freq_example-corr.png"><br />
[[File:plotms_amp_vs_freq_example-corr.png|200px|thumb|right|<caption> Same baseline as <xr id="plotms_amp_vs_freq_example-data.png"/> but now after correction using WVR and Tsys calibrations.</caption>]]<br />
</figure><br />
<br />
First, we plot amplitude as a function of frequency for 3c279. We start by plotting the DATA column, set color to indicate the two correlations (i.e., the XX and YY polarizations), and ask plotms to iterate over baseline. By setting '''antenna''' to 'DV11&*' we select only baselines that include DV11. We ask plotms to average all data over a very long timescale, '''avgtime''' = 1e8 seconds ~ 3 years or much longer than the time spanned by the whole data set. By setting '''avgscan''' = True we allow {{plotms}} to average across scan boundaries. The result is a plot of average amplitude per channel vs. frequency.<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
asdm=basename_all[0]<br />
<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='frequency', yaxis='amp',<br />
selectdata=True, spw='1', <br />
avgtime='1e8',avgscan=True,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data')<br />
</source><br />
<br />
Notice the green arrows along the bottom of the {{plotms}} window. We asked {{plotms}} to iterate over baseline. As you click the arrows, the plot will rotate from baseline to baseline, always with DV11 so that each antenna shows up once. To see the effect of the calibration, go to the "Axes" tab along the left of the {{plotms}} window and pull down the Data Column menu under the Y Axis. Set this from DATA to CORRECTED and you should see the effects of the calibration. You may need to ensure that the "Force Reload" box is checked before clicking "Plot" (both buttons lie at the bottom of the panel). For the most part things get better (flatter), but as we noted before DV04 is problematic.<br />
<br />
<figure id="plotms_amp_vs_time_north.png"><br />
[[File:plotms_amp_vs_time_north.png|200px|thumb|right|<caption> Example of amplitude vs. time for a northern mosaic data set.</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_time_south.png"><br />
[[File:plotms_amp_vs_time_south.png|200px|thumb|right|<caption> Example of amplitude vs. time for a southern mosaic data set.</caption>]]<br />
</figure><br />
<br />
You can now make analogous calls to examine the phase vs. frequency, amplitude vs. time, and phase vs. time.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='frequency', yaxis='phase',<br />
selectdata=True, spw='1', <br />
avgtime='1e8',avgscan=True,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data')<br />
<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='time', yaxis='amp',<br />
selectdata=True, spw='1:1200~1300', <br />
avgchannel='1000',avgscan=False,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data')<br />
<br />
plotms(vis=asdm+'.ms', <br />
field='3c279',<br />
xaxis='time', yaxis='phase',<br />
selectdata=True, spw='1:1200~1300', <br />
avgchannel='1000',avgscan=False,<br />
coloraxis='corr',<br />
iteraxis='baseline',<br />
antenna='DV11&*',<br />
ydatacolumn='data')<br />
</source><br />
<br />
Where:<br />
<br />
* '''spw''' is set to cover only channels 1200~1300 for the time plots in order to isolate time dependent variations from frequency-dependent behavior. Those 101 channels represent only a small part of the total spw 1 bandpass.<br />
* '''avgchannel''' set to a large number causes the plots of phase and amplitude vs. time to average data at all frequencies into a single point for each measurement.<br />
* '''coloraxis''' corr sets the colors to correspond to the two polarizations of the data.<br />
<br />
In each case, you will want to examine each baseline, alternating between the DATA and CORRECTED columns.<br />
<br />
This is a lot of data inspection and that's only for one of 10 data sets! You can iterate across the data by hand, updating "asdm" to refer to each data set in order and cycling between baselines and DATA/CORRECTED. It is also possible to script CASA to show you the key plots in succession (see the next block down). However you approach the infrastructure, you are looking for:<br />
<br />
* Improved scatter and lower variability in phase and amplitude vs. frequency and time. This indicates that the WVR and Tsys calibrations helped. <br />
* Sudden jumps in phase or amplitude as a function of either time or frequency. These may indicate problems with the antenna during that observation.<br />
* Large gradients, especially full wraps, in phase as a function of frequency. This may indicate a problem in the delays, the signal path length to the telescopes.<br />
* Unusual magnitude, scatter, or patterns in any plot - though this may be better explored using plots that show all data together, which we'll make in a moment.<br />
* Missing data. For example, if the phase calibrator drops out for a period of time we will not be able to calibrate and will need to flag the data.<br />
<br />
As you look through, note individual potentially problematic antennas. If ''all'' antennas in a data set appear problematic it may be that your "reference" antenna, DV11 in the example above, is the source of the problem. In this case swap this reference antenna for another and see whether the problem is isolated to your original reference antenna.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
<br />
A brief aside on structure:<br />
<br />
This section (Data Inspection) and the next (Apply Flags) are closely linked. We will present them as two<br />
separate steps. The idea here is that you look through your data, note problems, and then write commands to<br />
flag problematic data. This mimics one approach to writing data reduction scripts for CASA, where you will<br />
group all flagging together into one convenient place. Other CASA guides take a different approach, interleaving <br />
flagging and plotting. There is no "right" answer here. Find an approach to data inspection that works for you.<br />
<br />
</pre><br />
<br />
If you do wish to semi-automate the plot generation, the following sequence will cycle between data and corrected plots for each data set in turn. Type "stop" at any input call to break out.<br />
<br />
'''Note:''' In loops like this involving {{plotms}}, hitting enter before the last dataset completes loading may cause {{plotms}} to stop refreshing the plot window at each step, or cause the window to disappear altogether. This will be fixed in an upcoming CASA release. Right now, you may need to exit CASA and restart to bring up the {{plotms}} window again, but you should be able to continue in the script where you left off.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
user_input = ""<br />
for asdm in basename_all:<br />
# check if a stop has been requested<br />
if user_input == "stop":<br />
break<br />
# Extract antenna list for this data set.<br />
tb.open(asdm+'.ms/ANTENNA', nomodify=True)<br />
ants = tb.getcol('NAME')<br />
tb.close<br />
# Define the reference antenna to make baselines with<br />
ref_ant = 'DV11'<br />
# Loop over antennas<br />
for ant in ants:<br />
# Check if the user wants to stop<br />
if user_input == "stop":<br />
break<br />
# Skip correlation of reference antenna with itself (autocorrelations are flagged anyhow) <br />
if ant == ref_ant:<br />
continue<br />
# Define the baseline with the reference antenna for current antenna<br />
ant_str = ref_ant+'&'+ant<br />
print "Showing baseline "+ant_str+" for data set "+asdm<br />
print "Use this to inspect effect of applying wvrcal and Tsys calibrations."<br />
# Loop over phase and amplitude as axes<br />
for y_axis in ["amp", "phase"]:<br />
# Make 'before' plot for frequency x-axis<br />
print "... "+y_axis+" vs. frequency for DATA:" <br />
plotms(vis=asdm+'.ms', spw='1', field='3c279',<br />
antenna=ant_str, xaxis="frequency", yaxis=y_axis,<br />
avgtime="1e8", avgscan=True, coloraxis="corr",<br />
ydatacolumn="data")<br />
user_input = raw_input("Hit <ENTER> to see CORRECTED data [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
# Make 'after' plot for frequency x-axis<br />
print "... "+y_axis+" vs. frequency for CORRECTED:"<br />
plotms(vis=asdm+'.ms', spw='1', field='3c279',<br />
antenna=ant_str, xaxis="frequency", yaxis=y_axis,<br />
avgtime="1e8", avgscan=True, coloraxis="corr",<br />
ydatacolumn="corrected")<br />
user_input = raw_input("Hit <ENTER> to proceed to next plot [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
# Make 'before' plot for time x-axis<br />
print "... "+y_axis+" vs. time for DATA:" <br />
plotms(vis=asdm+'.ms', spw='1:1200~1300', field='3c279',<br />
antenna=ant_str, xaxis="time", yaxis=y_axis,<br />
avgchannel="1000", coloraxis="corr",<br />
ydatacolumn="data")<br />
user_input = raw_input("Hit <ENTER> to see CORRECTED data [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
# Make 'after' plot for time y-axis<br />
print "... "+y_axis+" vs. time for CORRECTED:"<br />
plotms(vis=asdm+'.ms', spw='1:1200~1300', field='3c279',<br />
antenna=ant_str, xaxis="time", yaxis=y_axis,<br />
avgchannel="1000", coloraxis="corr",<br />
ydatacolumn="corrected")<br />
user_input = raw_input("Hit <ENTER> to proceed to next plot [type 'stop'+<Enter> to break out].")<br />
if user_input == "stop":<br />
break<br />
</source><br />
<figure id="plotms_amp_vs_uvdist_north.png"><br />
[[File:plotms_amp_vs_uvdist_north.png|200px|thumb|right|<caption> Example of amplitude vs. uv-distance for 3c279 in the first northern mosaic data set.</caption>]]<br />
</figure><br />
<br />
<figure id="plotms_amp_vs_freq_3c279.png"><br />
[[File:plotms_amp_vs_freq_3c279.png|200px|thumb|right|<caption> Example of amplitude vs. frequency for 3c279 in the second northern mosaic data set.</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_freq_Titan.png"><br />
[[File:plotms_amp_vs_freq_Titan.png|200px|thumb|right|<caption> Example of amplitude vs. frequency for Titan in the second northern mosaic data set. Note the strong line (this is CO 3-2)!</caption>]]<br />
</figure><br />
<figure id="plotms_amp_vs_freq_Antennae.png"><br />
[[File:plotms_amp_vs_freq_Antennae.png|200px|thumb|right|<caption> Example of amplitude vs. frequency for the Antennae in the second northern mosaic data set. The CO(3-2) line is visible.</caption>]]<br />
</figure><br />
<br />
A detailed explanation of the procedure is a bit outside the scope of this guide (for more on python see http://www.python.org/ and for more on the CASA toolkit see http://casa.nrao.edu/), but the basic process is to loop over each data set, baseline with the reference antenna (here DV11), and y-axis of interest (phase or amplitude) then plot the effect of the calibration vs. frequency and time for each combination. Running this to step through the data will give you about 200 "before and after" plots from which you could note a subset of problematic cases to be followed up by hand. Many other strategies to inspect the data are also viable.<br />
<br />
With the Tsys and WVR calibrations applied successfully and the ''a priori'' flagging taken care of we will now {{split}} out the corrected data. We will keep only the corrected data, specified via '''datacolumn''', and only spectral window 1, which contains the FDM (high spectral resolution) observations of the CO(3-2) line. Setting '''keepflags'''=False tells {{split}} not to carry over any fully flagged rows from the original data set to the new MS. We give the new MS files the extension ".wvrtsys.ms" to indicate that they have been corrected for WVR and Tsys effects. Because split will not overwrite existing files, we remove any previous versions of the new MS before beginning.<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
os.system('rm -rf '+asdm+'.wvrtsys.ms')<br />
print "Splitting out corrected data for "+asdm<br />
split(vis=asdm+'.ms', outputvis=asdm+'.wvrtsys.ms', <br />
datacolumn='corrected', spw='1', keepflags=False)<br />
</source><br />
<br />
Be patient, {{split}} may take awhile. The WVR and Tsys-corrected data now sit in the DATA column of the new measurement sets, which have only one spectral window (now labeled spectral window 0 though it was spectral window 1 in the original data). You may wish to run {{listobs}} to illustrate the changes:<br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
os.system('rm '+asdm+'.wvrtsys.listobs.txt')<br />
listobs(vis=asdm+'.wvrtsys.ms', listfile=asdm+'.wvrtsys.listobs.txt', verbose=True)<br />
</source><br />
<br />
Note the new spectral window information:<br />
<br />
<pre style="background-color: #fffacd;"><br />
<br />
2011-08-05 01:07:08 INFO listobs Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
2011-08-05 01:07:08 INFO listobs SpwID #Chans Frame Ch1(MHz) ChanWid(kHz)TotBW(kHz) Ref(MHz) Corrs <br />
2011-08-05 01:07:08 INFO listobs 0 3840 TOPO 344845.586 488.28125 1875000 344908.33 XX YY <br />
<br />
</pre><br />
<br />
<br />
Next we will do a bit more inspection using {{plotms}} to look at whole data sets. This will help us identify missing data or look for egregious outliers.<br />
<br />
First we plot amplitude versus time (see <xr id="plotms_amp_vs_time_north.png"/> and <xr id="plotms_amp_vs_time_south.png"/>), averaging over all channels (by setting '''avgchannel''' to the very large value 10,000). We colorize by field so that scans on Titan are red, the bandpass and phase calibrator 3c279 is black (and orange in the Southern Mosaic where it has two field IDs), and the Antennae mosaic appears as a range of colors (one per pointing).<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
xaxis='time', yaxis='amp', <br />
avgchannel='3840',coloraxis='field')<br />
dummy_string = raw_input("Examining amplitude vs. time for "+asdm+" . Hit <Enter> to proceed.")<br />
</source><br />
<br />
Here look for:<br />
<br />
* Missing data. The source needs to be flanked by phase calibrator scans, if those are missing for any reason we need to flag the appropriate time range.<br />
* Dramatic outliers. Does the source suddenly get very bright or the otherwise bright calibrator appear anomalously faint for a brief time? This likely indicates problematic data that should be identified and flagged. You can use the "select" (box with green plus along the bottom row in plotms) and "locate" (magnifying glass) buttons in {{plotms}} to isolate and identify problem data (it will print to the log).<br />
* Smooth variation with time. A sudden jump may indicate a problem and often the safest approach is to flag data near a discontinuity.<br />
<br />
Look through the amplitudes vs. time for each data set (remember that we've already examined the phases vs. time and amplitude vs. time for individual baselines above).<br />
<br />
There are two other very useful "averaging" plots worth making. First, we plot amplitude as a function of u-v distance (projected antenna separation). Discontinuities and spikes in this plot are often from non-astrophysical sources. In the phase analog to the plot, the effects of atmospheric decorrelation can be assessed from increased scatter at longer u-v distances. While using the moon Titan as our flux calibrator, we may want to watch for flaring amplitudes at short u-v distances. These may indicate that Saturn is contaminating our beam. For a perfect, bright point source, we expect flat amplitudes as a function of u-v distance at the source amplitudes. <xr id="plotms_amp_vs_uvdist_north.png"/> shows an example of this plot, generated via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field='3c279',<br />
xaxis='uvdist', yaxis='amp', <br />
avgchannel='3840',coloraxis='corr')<br />
dummy_string = raw_input("Examining amplitude vs. UV Distance for 3c279 for "+asdm+" . Hit <Enter> to proceed.")<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field='Titan',<br />
xaxis='uvdist', yaxis='amp', <br />
avgchannel='3840',coloraxis='corr')<br />
dummy_string = raw_input("Examining amplitude vs. UV Distance for Titan for "+asdm+" . Hit <Enter> to proceed [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
<br />
<br />
It can also be useful to examine the average amplitude as a function of frequency for each target. This allows one to check for lingering atmospheric effects, unexpected line emission or absorption in the calibrators, or decreased sensitivity due to "roll-off" of the telescope sensitivity at the band edges. These plots are created by the sequence of commands below, where we have broken up the script to loop separately over the Northern and Southern Mosaics to reflect the different source names.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
field_names = ["3c279","Titan","NGC*"]<br />
<br />
for asdm in basename_north:<br />
for field in field_names:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field=field,<br />
xaxis='frequency', yaxis='amp', <br />
avgtime='1e8',avgscan=True, coloraxis='corr')<br />
dummy_string = raw_input("Examining amplitude vs. frequency for "+field+" in "+asdm+" . Hit <Enter> to proceed.")<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
field_names = ["3c279","Titan","Ant*"]<br />
<br />
for asdm in basename_south:<br />
for field in field_names:<br />
plotms(vis=asdm+'.wvrtsys.ms', <br />
field=field,<br />
xaxis='frequency', yaxis='amp', <br />
avgtime='1e8',avgscan=True, coloraxis='corr')<br />
dummy_string = raw_input("Examining amplitude vs. frequency for "+field+" in "+asdm+" . Hit <Enter> to proceed.")<br />
</source><br />
<br />
<br />
For this command notice that we can see the CO(3-2) line in the Antennae even before calibration (see <xr id="plotms_amp_vs_freq_Antennae.png"/>) and that Titan also shows evidence of a strong line (also <xr id="plotms_amp_vs_freq_Titan.png"/>)! This will need to be flagged before we can use Titan to calibrate the flux scale of our data.<br />
<br />
This suite of plots (along with the earlier inspection of the Tsys tables) gives us the tools we need to identify problematic data through the data sets. We use this to generate a set of inspection-driven {{flagdata}} commands for each data set. We apply these before the bandpass and gain calibration.<br />
<br />
==Apply Flagging==<br />
Based on this inspection and the other plots we have made, we now flag problematic portions of the data. We break up the flags by reason for flagging in order to illustrate the process. As you reduce your own data it may be more efficient to group flags by data set and make use of the flagcmd command. Except for the "post-calibration" flagging, the inspection plots that we just looked through have already revealed all of the problems that we flag. We structure the guide so that the flagging is grouped in one place.<br />
<br />
As before, we may wish to reset our flags before beginning (particularly if one iterates this process) via:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
for asdm in basename_all:<br />
flagdata(vis = asdm+'.wvrtsys.ms',mode='unflag', flagbackup = False)<br />
</source><br />
<br />
Remember that we dropped the flagged data when splitting out after the WVR and Tsys calibration, so this should not undo your "A Priori" flagging of shadowed data, autocorrelations, etc.. In any case this unflagging step is not necessary during the first iteration.<br />
<br />
* '''Edge Channels'''<br />
<br />
ALMA's sensitivity decreases near the edge of the baseband and it is often useful to check for a 'roll-off' in sensitivity near the edge of the band. This will appear as a downturn in amplitude as a function of channel near the edge of the window in the uncalibrated data, as a flaring due to increased noise at the spw edges in the calibrated data. It will also be visible in the amplitude part of the bandpass calibration table. Because our FDM spw does not cover the full baseband, we do not see a strong roll off in our data (see <xr id="amp_vs_channel_example.png"/>), where there is only a mild hint of a roll-off at the high end) but we do flag a (very) few channels at the high and low-frequency edge of the data set to be safe.<br />
<br />
<figure id="amp_vs_channel_example.png"><br />
[[File:amp_vs_channel_example.png|200px|thumb|right|<caption> Amplitude vs. channel for one uncalibrated antenna pair. This kind of plot can be inspected to get an idea of the presence or magnitude of any roll-off in sensitivity near the edges of the spectral window.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
for asdm in basename_all:<br />
flagdata(vis = asdm+'.wvrtsys.ms', mode='manual', spw = '0:0~7,0:3831~3839', flagbackup = False)<br />
<br />
for asdm in basename_all:<br />
flagdata(vis = asdm+'.wvrtsys.ms', mode='manual', spw = '0:3260~3320', flagbackup = False)<br />
</source><br />
<br />
* '''Problematic Tsys measurements'''<br />
<br />
Above we noted issues with the Tsys measurements for both DV04 and DV12. We flag the affected data. Each of these issues should be visible in the Tsys plots you made above (e.g., see <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.DV02.spw5.CASA3_4.png"/> and <xr id="Uid___A002_X1ff7b0_Xb.tdm.tsys.3c279.PM01.spw5.CASA3_4.png"/>).<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X1ff7b0_Xb"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV04', flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X3b9"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X2181fb_X49"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X1ff7b0_X1c8"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV04',flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X1f7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X207fe4_X4d7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X215db8_X18"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X215db8_X1d5"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
<br />
asdm="uid___A002_X215db8_X392"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV12',correlation='YY', flagbackup=False)<br />
</source><br />
<br />
* '''Unreliable Short-Spacing Measurements on Titan'''<br />
<br />
<figure id="amp_vs_uv_titan_obs.png"><br />
[[File:amp_vs_uv_titan_obs.png|200px|thumb|right|<caption> Observed amplitude vs. uv-distance for observations of Titan in the first data set. Note the scatter for low projected antenna separations. We will flag these short-spacing data, which may reflect contamination by Saturn, and use only the more extended baselines for flux calibration.</caption>]]<br />
</figure><br />
<br />
Saturn may contaminate the short u-v spacings from Titan. In any case these often show significant scatter (<xr id="amp_vs_uv_titan_obs.png"/>), so we flag them. There are still enough baselines to determine a good amplitude calibration for each antenna.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X1ff7b0_Xb"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~50', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~40', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X3b9"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~50', flagbackup = False)<br />
<br />
asdm="uid___A002_X2181fb_X49"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~30', flagbackup = False)<br />
<br />
asdm="uid___A002_X1ff7b0_X1c8"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~50', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X1f7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~30', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X4d7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', field='Titan', uvrange='0~30', flagbackup = False)<br />
</source><br />
<br />
* '''Delay Issues''' <br />
<br />
<figure id="phase_vs_freq_DV13.png"><br />
[[File:phase_vs_freq_DV13.png|200px|thumb|right|<caption> Phase vs. frequency for DV13 in a data set where this antenna shows evidence of imperfect delay calibration.</caption>]]<br />
</figure><br />
<br />
DV13 and a few other antennas show signatures of an imperfect delay calibration. This is most easily identified via strong "wrapping" of phase as a function of frequency (see <xr id="phase_vs_freq_DV13.png"/>). Such effects can be calibrated out with mild delay issues largely accounted for by the bandpass solution. The phase wrapping in DV13 seems weak enough that we will trust the calibrations to remove it. For a more extreme example see the CASA guide describing the calibration of [[NGC3256Band3]].<br />
<br />
* '''Missing Phase Calibrator Observations'''<br />
<br />
<figure id="amp_vs_time_missing_scans.png"><br />
[[File:amp_vs_time_missing_scans.png|200px|thumb|right|<caption> Amplitude vs. time colored by field for a data set where the final visit to the phase calibrator is missing. We will flag the last set of source data to ensure that each visit to the source is flanked in time by visits to the phase calibrator.</caption>]]<br />
</figure><br />
<br />
As a general rule, we want to be sure that observations of the phase calibrator (3c279) bracket each source observation. Two of the data sets do not include a final phase calibrator observation (see <xr id="amp_vs_time_missing_scans.png"/>) and for those two cases we flag the affected source observations.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X207fe4_X3b9"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', timerange='00:53:47~01:08:00',flagbackup = False)<br />
<br />
asdm="uid___A002_X215db8_X18"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV10',timerange='19:46:20~20:34:40',flagbackup=False)<br />
</source><br />
<br />
* '''Unexpected Scatter or Discontinuity in the Data'''<br />
<br />
For several antennas we find sudden jumps in the phase of the phase calibrator as a function of time. These are visible in the plots of uncalibrated phase vs. time for single baselines above, and we show an example in <xr id="phase_vs_time_DV09.png"/>. It will not be possible to effectively interpolate the phase between measurements when we see these discontinuities. The safest approach is to flag the source data across these jumps. We do so here (though note that the last two flaggings are borderline cases).<br />
<br />
<figure id="phase_vs_time_DV09.png"><br />
[[File:phase_vs_time_DV09.png|200px|thumb|right|<caption> Phase vs. time for DV09 on a problematic day. It may prove problematic to calibrate the data near this discontinuity so we flag data near this time.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV09', timerange='21:24:09~21:35:35', flagbackup = False)<br />
<br />
asdm="uid___A002_X207fe4_X1f7" <br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV09',timerange='23:30:52~24:10:00',flagbackup=False)<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='PM01',timerange='23:16:50~24:10:00',flagbackup=False)<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='PM03',timerange='23:16:50~24:10:00',flagbackup=False)<br />
</source><br />
<br />
* '''Outliers Visible After Calibration'''<br />
<br />
<figure id="amp_vs_uvdist_outliers.png"><br />
[[File:amp_vs_uvdist_outliers.png|200px|thumb|right|<caption> Amplitude vs. u-v distance ''after'' calibration. Note the outlying data. We track these down using the select (box with green "+") and locate (magnifying glass) features inside plotms and identify several problematic baselines across our data. ''Note that you cannot make this plot at this point in the guide, these pathologies become evident after calibration, requiring an iterative approach to reduction.''</caption>]]<br />
</figure><br />
<br />
Often issues with the data may become evident after calibration (i.e., after the next few steps that we apply). These data can appear as outliers in diagnostic plots for the calibrated data or even show up in the imaging stages. Once these are identified, best practice is to apply this new flagging then redo the calibration (if the issue is very minor, then re-calibrating may not be necessary).<br />
<br />
<source lang="python"><br />
# In CASA<br />
asdm="uid___A002_X207fe4_X3a"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', timerange='21:18:00~21:22:15', flagbackup=False)<br />
<br />
asdm="uid___A002_X2181fb_X49"<br />
flagdata(vis=asdm+'.wvrtsys.ms', mode='manual', antenna='DV01&DV04', flagbackup=False)<br />
</source><br />
<br />
Now that we've applied our flagging, back up the flags as version "User" using {{flagmanager}}:<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
flagmanager(vis=asdm+'.wvrtsys.ms',mode='save',versionname ='User')<br />
</source><br />
<br />
Applying this flagging will remove the most egregious pathologies from the data. We are now ready to calibrate the data.<br />
<br />
==Bandpass Calibration==<br />
<br />
We begin by calibrating the phase and amplitude response of each antenna as a function of frequency, called "bandpass calibration." We have already seen that the data contain smooth but systematic variations in both phase and amplitude as a function of frequency. We can see this again in a more compact form by plotting phase as a function of frequency for all baselines associated with each antenna (<xr id="plotms_phase_vs_freq_example.png"/>).<br />
<br />
<figure id="plotms_phase_vs_freq_example.png"><br />
[[File:plotms_phase_vs_freq_example.png|200px|thumb|right|<caption> Phase vs. frequency for the bandpass calibrator, 3c279 in the first data set. We plot all baselines with DV02, averaged over time, and show only the 'XX' correlation.</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
plotms(vis= asdm+'.wvrtsys.ms', <br />
xaxis='freq', yaxis='phase', <br />
selectdata=True, field='3c279', correlation='XX',<br />
avgtime='1e8', avgscan=True, antenna='*&*',<br />
coloraxis='baseline', iteraxis='antenna')<br />
dummy_string = raw_input("Plotting phase vs. frequency for "+asdm+". Hit <Enter> for next data set or cycle through antennas [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
Each plot shows phase as a function of frequency for all baselines with one antenna for 3c279. We plot only the 'XX' correlation, colorizing by baseline. With '''iteraxis''' set to antenna the green arrows at the bottom of {{plotms}} will cycle through antennas. By using '''avgscan''' and a large '''avgtime''' we average all scans and integrations. <br />
<br />
The phase (and amplitude) also varies as a function of time, as we saw before. Here are the similar plots for phase vs. time (see <xr id="Uid_A002_X1ff7b0_Xb-phasecont.png"/>).<br />
<br />
<figure id="Uid_A002_X1ff7b0_Xb-phasecont.png"><br />
[[File:Uid_A002_X1ff7b0_Xb-phasecont.png|200px|thumb|right|<caption> Phase vs. time for the bandpass calibrator, 3c279. Averaged over channel. Only baselines with antenna DV02, and corr='XX'</caption>]]<br />
</figure><br />
<br />
<source lang="python"><br />
# In CASA<br />
for asdm in basename_all:<br />
plotms(vis= asdm+'.wvrtsys.ms', <br />
xaxis='time', yaxis='phase', <br />
selectdata=True, field='3c279', <br />
spw='0:1200~1300', antenna='*&*',correlation='XX',<br />
avgchannel='1000', avgscan=True, <br />
coloraxis='baseline', iteraxis='antenna')<br />
dummy_string = raw_input("Plotting phase vs. time for "+asdm+". Hit <Enter> for next data set or cycle through antennas [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
<xr id="Uid_A002_X1ff7b0_Xb-phasecont.png"/> shows that the phase varies with time. We need to take this temporal variation into account when we solve for the frequency variations. Therefore we carry out the bandpass calibration in two steps. First, we use {{gaincal}} to solve for the variation of phase as a function of time for 3c279 on very short timescales. We set {{gaincal}} to derive a separate phase solution for each antenna every integration by setting '''solint''' to 'int'. We solve, averaging together only a small fraction of the total bandpass (channels 1100-1300) to avoid the effects of the phase vs. frequency behavior. We will then apply this solution to remove time-dependent behavior when we solve for the frequency response of the antennas with {{bandpass}}.<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
An integration is the smallest time quantum of observation in the data, usually a few seconds. <br />
You can check the integration length for each scan in listobs. <br />
</pre><br />
<br />
<source lang="python"><br />
#In CASA<br />
<br />
for asdm in basename_all:<br />
print "Running a short solution interval phase calibration for "+asdm<br />
os.system('rm -rf '+asdm+'.bpphase.gcal')<br />
gaincal(vis = asdm+'.wvrtsys.ms',<br />
selectdata=True,field = '3c279',spw = '0:1100~1300',<br />
caltable = asdm+'.bpphase.gcal',<br />
solint = 'int',refant = 'DV11',calmode='p')<br />
</source><br />
<br />
Now we use {{bandpass}} to solve for the frequency response of each antenna. To do this, we average all data in time by setting '''solint''' to 'inf' (that is, 'infinite'). We allow combination across scans and the different field IDs found for 3c279 by setting '''combine''' to "scan,field". We apply the phase vs. time calibration that we just derived on-the-fly using the parameter "gaintable".<br />
<br />
<source lang="python"><br />
for asdm in basename_all:<br />
print "Running a bandpass calibration for "+asdm<br />
os.system('rm -rf '+asdm+'.bandpass.bcal')<br />
bandpass(vis = asdm+'.wvrtsys.ms',<br />
field = '3c279',<br />
gaintable = asdm+'.bpphase.gcal',<br />
caltable = asdm+'.bandpass.bcal',<br />
bandtype='B',<br />
solint = 'inf',combine = 'scan,field', solnorm=True,refant = 'DV11',<br />
minblperant=3,minsnr=2,fillgaps=62)<br />
</source><br />
<br />
in these calls:<br />
<br />
*'''caltable''' specifies the output calibration table<br />
*'''gaintable''' specifies any calibration tables to be applied "on the fly" to the data before solving.<br />
*'''solint''' sets the time interval for which solutions are derived for each antenna.<br />
*'''refant''' set the reference antenna, here DV11, which is defined to have zero correction by construction.<br />
*'''calmode''' 'p' sets {{gaincal}} to calibrate the phase only, other options are 'a'mplitude or 'ap' - amplitude and phase.<br />
*'''minblperant''' sets the minimum baselines required per antenna for a successful solution.<br />
*'''minsnr''' sets the minimum signal-to-noise ratio required for a successful solution.<br />
*'''bandtype''' here 'B' tells {{bandpass}} to solve for the phase and frequency response of each antenna in each channel, averaging data in time across the solution interval.<br />
*'''fillgaps''' tells {{bandpass}} to interpolate across channel gaps 1 channel wide.<br />
*'''solnorm''' tells {{bandpass}} to normalize the bandpass amplitude and phase corrections to have magnitude unity. The absolute scale of the calibration will come from our later {{gaincal}} solutions.<br />
<br />
Do not worry about the message "Insufficient unflagged antennas" when running the {{bandpass}} task. This indicates that {{bandpass}} is failing on the flagged edge channels, which is expected.<br />
<br />
It is now a good idea to plot both sets of solutions to look for irregularities, especially:<br />
<br />
* discontinuities in the phase vs. time solution<br />
* rapid wrapping of phase in either phase vs. time or bandpass solution<br />
* large roll-off in the amplitude response near the band edge in the bandpass solution<br />
* large scatter in any solution.<br />
<br />
We loop through and using analysis utils, again generating .png files of each calibration. As the bandpass plots take a while you may want to go have a cup of coffee and inspect them using your favorite image viewer. Otherwise, switch the '''interactive''' parameter to True to see them in real time instead.<br />
<br />
<figure id="uid___A002_X1ff7b0_X1c8.bpphase.page1.png"><br />
[[File:uid___A002_X1ff7b0_X1c8.bpphase.page1.png|200px|thumb|right|<caption> Short interval phase vs. time solution carried out and applied during bandpass calibration, here for the first set of antennas for the first data set. This solution removes any systematic variations in phase vs. time.</caption>]]<br />
</figure><br />
<figure id="Uid___A002_X1ff7b0_X1c8.bandpass.DV02.spw0.t1.CASA3.4.png"><br />
[[File:Uid___A002_X1ff7b0_X1c8.bandpass.DV02.spw0.t1.CASA3.4.png|200px|thumb|right|<caption> Bandpass amplitude solution for the first set of antennas and the first data set.</caption>]]<br />
</figure><br />
<figure id="uid___A002_X1ff7b0_Xb.bcal_phase.page1.png"><br />
[[File:uid___A002_X1ff7b0_Xb.bcal_phase.page1.png|200px|thumb|right|<caption> Phase vs. frequency calibration from the bandpass calibration for the first set of antennas and the first data set.</caption>]]<br />
</figure><br />
<source lang="python"><br />
#In CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
os.system('rm -rf cal_plots/*bandpass*.png')<br />
for asdm in basename_all:<br />
plotbandpass(caltable=asdm+'.bandpass.bcal',<br />
field='',xaxis='freq',yaxis='both',<br />
figfile='cal_plots/'+asdm+'.bandpass.png',<br />
showatm=True,interactive=False,subplot=42)<br />
</source><br />
<br />
==Absolute Flux Calibration==<br />
<br />
The bandpass calibration will account for the phase and amplitude response of our antennas as a function of frequency. We now solve for the absolute flux scale of the data by referencing to Titan and in the next section we will calibrate the phase and amplitude behavior of the antennas as a function of time.<br />
<br />
Before using Titan to set the flux, there is an important systematic to account for. When we looked at the integrated spectra of our targets above, remember that Titan showed a whopping spectral line, in fact the same CO(3-2) line that we wish to observe in the Antennae. We will set the flux of Titan (and thus all of our data) by referencing to a model in casa that does not account for this line. Therefore we need to flag the part of the Titan observations contaminated by the line before we calibrate (you can see the affected channel range in <xr id="Antennae-TitanLine.png"/>). We run the following additional flagging step:<br />
<br />
<figure id="Antennae-TitanLine.png"><br />
[[File:Antennae-TitanLine.png|200px|thumb|right|<caption> Uncalibrated amplitude vs. channel plot for the flux calibrator, Titan (uid___A002_X1ff7b0_Xb dataset). Averaged over time, corr='XX', and colorized by baseline.</caption>]]<br />
</figure><br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Flagging CO(3-2) in Titan for "+asdm<br />
flagdata(vis=asdm+'.wvrtsys.ms',flagbackup=False, <br />
field='Titan', spw='0:1100~1700')<br />
<br />
for asdm in basename_all:<br />
flagmanager(vis =asdm+'.wvrtsys.ms',mode = 'save',versionname = 'Calibration')<br />
</source><br />
<br />
Next, we will use the {{setjy}} task to read the predicted complex visibilities for Titan into the MODEL column of each data set.<br />
<br />
<source lang="python"><br />
# in CASA<br />
for asdm in basename_all:<br />
print "Reading model for Titan into "+asdm<br />
setjy(vis = asdm+'.wvrtsys.ms',field = 'Titan',<br />
usescratch=False,scalebychan=True,<br />
standard = 'Butler-JPL-Horizons 2010')<br />
</source><br />
<br />
{{setjy}} will output the flux of Titan to the CASA logger and it is worth recording this information. The flux of Titan at these frequencies is about 2.9 Jy. For example, for dataset uid___A002_X1ff7b0_Xb.wvrtsys.ms:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Titan (fld ind 1) spw 0 [I=2.8614, Q=0, U=0, V=0] Jy, (JPL-Butler Solar System Object)<br />
</pre><br />
<br />
Now we are going to take a look at the titan model for one dataset<br />
<br />
<source lang="python"><br />
# in CASA<br />
plotms(vis ='uid___A002_X1ff7b0_X1c8.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='model', field='Titan',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr')<br />
<br />
plotms(vis ='uid___A002_X1ff7b0_X1c8.wvrtsys.ms', xaxis='uvdist', yaxis='phase',<br />
ydatacolumn='model', field='Titan',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr')<br />
</source><br />
<br />
<figure id="2010_titan_model.png">[[File:2010_titan_model.png|thumb|right|200px|<caption>Titan model prodcued by 'Butler-JPL-Horizons 2010'.</caption>]]</figure><br />
<figure id="2012_titan_model.png">[[File:2012_titan_model.png|thumb|right|200px|<caption>Titan model prodcued by 'Butler-JPL-Horizons 2012'.</caption>]]</figure><br />
<br />
<br/><br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
The setjy invocation made in this section uses the flux density standard '''standard='Butler-JPL-Horizons 2010' '''. A more updated standard is also available: '''standard='Butler-JPL-Horizons 2012' '''. <xr id="2010_titan_model.png"/> and <xr id="2012_titan_model.png"/> show the differences in the Titan models produced using these two standards. The motivated reader may wish to rerun {{setjy}} using the updated model. We will highlight later in this tutorial, and in the imaging tutorial that follows, the effects of using the updated model.<br />
</div><br />
<br />
==Gain (Phase and Amplitude) Calibration==<br />
<br />
With the flux now properly scaled, we will calibrate the phase and amplitude behavior of the antennas as a function of time.<br />
<br />
We begin by running a short-solution interval {{gaincal}} to solve for phase variation on short timescales during observations of our two calibrators, with '''solint''' set to "int". By applying this on-the-fly, we can remove any decorrelation in the data due to phase scatter when we solve for the amplitude calibration. However, there is no benefit to using this short-timescale solution to calibrate the source because we only have information on the gain during calibrator visits (though see the Imaging portion of this guide). Instead we will solve for the gains to apply to the source using a longer '''solint''' in just a moment.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Carrying out short timescale phase solution for "+asdm<br />
os.system('rm -rf '+asdm+'.intphase.gcal')<br />
gaincal(vis=asdm+'.wvrtsys.ms',<br />
gaintable=asdm+'.bandpass.bcal', <br />
caltable=asdm+'.intphase.gcal',<br />
calmode='p',<br />
field='Titan,3c279',<br />
spw='0:40~3800',<br />
refant='DV11', solint='int',minsnr=2.0, minblperant=4)<br />
</source><br />
<br />
Now we derive the longer timescale phase calibration table using '''solint''' set to "inf", but not allowing scan combination. This calibration has higher signal to noise due to combining more data, and for the purposes of correcting the source, it is just as precise as the short timescale solution.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Carrying out longer timescale phase solution for "+asdm<br />
os.system('rm -rf '+asdm+'.scanphase.gcal')<br />
gaincal(vis=asdm+'.wvrtsys.ms',<br />
gaintable=asdm+'.bandpass.bcal', <br />
caltable=asdm+'.scanphase.gcal',<br />
calmode='p',<br />
field='Titan,3c279',<br />
spw='0:40~3800',<br />
refant='DV11', solint='inf',minsnr=2.0,minblperant=4)<br />
</source><br />
<br />
Now we apply the short-timescale phase solution and carry out a scan length ('''solint''' set to "inf") calibration of the data using '''calmode''' of 'ap'.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Solving for longer (scan) interval amplitude solution for "+asdm<br />
os.system('rm -rf '+asdm+'.amp.cal')<br />
gaincal(vis = asdm+'.wvrtsys.ms',<br />
gaintable =[asdm+'.bandpass.bcal',asdm+'.intphase.gcal'],<br />
caltable = asdm+'.amp.cal',<br />
calmode='ap',<br />
field = 'Titan,3c279',<br />
spw='0:40~3800',<br />
refant = 'DV11',solint = 'inf', minblperant=4)<br />
</source><br />
<br />
This "amp.cal" solution gives us the amplitude variations as a function of time, but they are not yet pinned to a realistic scale except in the case of Titan, where we have solved using the model input by {{setjy}}. We will set the flux of our secondary calibrator 3c279 with reference to Titan using {{fluxscale}}.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Scaling amplitude calibration to match Titan for "+asdm<br />
os.system('rm -rf '+asdm+'.flux.cal')<br />
fluxscale(vis = asdm+'.wvrtsys.ms',<br />
caltable = asdm+'.amp.cal',<br />
fluxtable = asdm+'.flux.cal',<br />
reference = 'Titan',<br />
transfer = '3c279')<br />
</source><br />
<br />
This new correctly-scaled flux table ".flux.cal" replaces the previous ".amp.cal" table as the correct amplitude calibration table to apply to the data, i.e., the ".flux.cal" contains both the time variability of the amplitude solved for in ".amp.cal" and the correct flux scaling set with {{fluxscale}}.<br />
<br />
Fluxscale will output the derived flux for 3c279 to the CASA logger. This information is worth noting. We find that the flux of 3c279 is 10.41 Jy, by averaging the fluxes obtained from the ten available datasets. This value agrees within 10% with the most recent 0.850 millimeter measurements from the SMA calibrator list [http://sma1.sma.hawaii.edu/callist/callist.html] : (03 Feb 2014, SMA 10.93 ± 0.49).<br />
<br />
<div class="noprint" style="float:none; border:0px solid blue;background-color:#F6CEF5;padding:2px;"><br />
If you used the updated, Butler-JPL-Horizons 2012, flux density standard when you ran {{setjy}} earlier in this tutorial, the derived flux values for 3c279 will be slightly higher. The flux of 3c279, when averaged over all 10 measurement sets, will be 10.80 Jy.<br />
</div><br />
<br />
Now we plot the final phase and amplitude calibration tables for each data set. A well-behaved calibration table will show smooth variations as a function of time. Sudden jumps or wild variations among the antenna amplitude gains should prompt further investigation and possibly additional flagging.<br />
<br />
<source lang="python"><br />
# in CASA<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Plotting solutions for "+asdm<br />
plotcal(caltable = asdm+'.scanphase.gcal',<br />
xaxis = 'time', yaxis = 'phase',<br />
iteration = 'antenna', plotrange=[0,0,-180,180],<br />
showgui=False, subplot=421, figfile=asdm+'.scanphase.page1.png',<br />
antenna='0~7', fontsize=6.0)<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
plotcal(caltable = asdm+'.scanphase.gcal',<br />
xaxis = 'time', yaxis = 'phase',<br />
iteration = 'antenna', plotrange=[0,0,-180,180],<br />
showgui=False, subplot=421, figfile=asdm+'.scanphase.page2.png',<br />
antenna='8~15', fontsize=6.0)<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
plotcal(caltable = asdm+'.flux.cal', <br />
xaxis = 'time',yaxis = 'amp',<br />
plotrange = [0,0,0,0],<br />
antenna='0~7', iteration='antenna',<br />
showgui=False, subplot=421, figfile=asdm+'.flux.page1.png',<br />
fontsize=6.0)<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
plotcal(caltable = asdm+'.flux.cal', <br />
xaxis = 'time',yaxis = 'amp',<br />
plotrange = [0,0,0,0],<br />
antenna='8~15', iteration='antenna', fontsize=6.0,<br />
showgui=False, subplot=421, figfile=asdm+'.flux.page2.png')<br />
# dummy_string = raw_input("Hit <Enter> to see next plot.")<br />
</source><br />
<br />
==Apply the Calibrations and Inspect ==<br />
Now we will use {{applycal}} to apply the bandpass, phase, and amplitude calibration tables that we generated in the previous sections to the data. We apply the solutions separately to the bandpass and secondary ("phase") calibrator 3c279, the flux calibrator Titan, and the target source. In most data sets, the bandpass and secondary calibrator will not be the same and this step would include one additional {{applycal}}.<br />
<br />
<source lang="python"><br />
#In CASA<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
<br />
for asdm in basename_north: <br />
print "Applying calibrations for "+asdm<br />
applycal(vis=asdm+'.wvrtsys.ms',field='3c279',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='Titan',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','Titan','Titan'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='NGC*',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_south: <br />
print "Applying calibrations for "+asdm<br />
applycal(vis=asdm+'.wvrtsys.ms',field='3c279',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='Titan',<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.intphase.gcal',asdm+'.flux.cal'],<br />
interp=['nearest','nearest','nearest'],<br />
gainfield=['3c279','Titan','Titan'],flagbackup=False,calwt=False)<br />
applycal(vis=asdm+'.wvrtsys.ms',field='Ant*',<br />
interp=['nearest','linear','linear'],<br />
gaintable=[asdm+'.bandpass.bcal',asdm+'.scanphase.gcal',asdm+'.flux.cal'],<br />
gainfield=['3c279','3c279','3c279'],flagbackup=False,calwt=False)<br />
</source><br />
<br />
Here:<br />
* '''vis''' and '''field''' specify the measurement set and field to calibrate.<br />
* '''gaintable''' specifies the tables to apply to the data. There may be several tables applied all at once, here we apply the bandpass, phase, and flux calibrations.<br />
* '''interp''' specifies the type of interpolation used to match calibration tables to the data. If there are several gaintables then interp may be either a single value (e.g., "linear" or "nearest") or a list of values with size equal to the list of gaintables. In the case where interp is a list, applycal will match each element to the corresponding gaintable (e.g., first gaintable with first interp parameter).<br />
* '''gainfield''' specifies field from which to draw the calibration. As with interp, this can be a list of size matched to gaintable, so that the first element of gainfield will be the field used for the first table. For example, in the above commands the bandpass calibration (the first table) will always be applied from '3c279' (the first gainfield).<br />
* '''calwt''' indicates that the weights, which were derived from the Tsys measurements, should also be calibrated. Note that '''calwt''' is True by default.<br />
<br />
Once calibrations are applied, it is important to go back and inspect the calibrated data. New problematic antennas or baselines may be visible after calibration. Repeat the steps above, focusing on the CORRECTED data column. Bear in mind that for any point source calibrators we now expect to find phase scattering around zero and to find flat amplitudes as a function of u-v distance. Look for outliers and other signatures of problematic data. As a general rule, you will want to incorporate these data into your overall flagging script then rerun the whole calibration process, so that reduction is iterative. If the data only represent a minor problem, however, it may not be terribly harmful to flag them after the fact so that they do not interfere with imaging but trust that the calibrations are mostly unaffected.<br />
<br />
As an example of this inspection, we cycle through the corrected amplitudes and phases of 3c279 and Titan as a function u-v distance, to check that the phases are close to zero and the amplitudes are constant. <br />
<br />
<figure id="xb-checkcal-pha-cha.png"><br />
[[File:xb-checkcal-pha-cha.png|200px|thumb|right|<caption> Calibrated phase vs. channel plot for 3c279 (uid___A002_X1ff7b0_Xb dataset). </caption>]]<br />
</figure><br />
<figure id="xb-checkcal-amp-time.png"><br />
[[File:xb-checkcal-amp-time.png|200px|thumb|right|<caption> Calibrated amplitude vs. time plot for 3c279 (uid___A002_X1ff7b0_Xb dataset). </caption>]]<br />
</figure><br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='3c279',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='time', yaxis='amp',<br />
ydatacolumn='corrected', field='3c279',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='3c279',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='time', yaxis='phase',<br />
ydatacolumn='corrected', field='3c279',<br />
avgchannel='3840', avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
<br />
<br />
for asdm in basename_all:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='Titan',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='phase',<br />
ydatacolumn='corrected', field='Titan',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='Titan',avgtime='1e8',<br />
avgchannel='', avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot [type 'stop'+<Enter> to break out].")<br />
# check if a stop has been requested<br />
if dummy_string == "stop":<br />
break<br />
</source><br />
<br />
In <xr id="xb-checkcal-pha-cha.png"/> and <xr id="xb-checkcal-amp-time.png"/> we plot phase vs. channel and amp vs. time for 3c279 for the uid___A002_X1ff7b0_Xb dataset. <br />
<br />
Finally we can use {{plotms}} to examine the corrected amplitude and phase of Antennae galaxies as a function of time and uv-distance (plots not shown):<br />
<br />
<source lang="python"><br />
# In CASA<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
for asdm in basename_north:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='NGC*',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='NGC*',<br />
avgtime='1e8', avgscan=True, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
for asdm in basename_south:<br />
print "Examining calibrated data for "+asdm<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='uvdist', yaxis='amp',<br />
ydatacolumn='corrected', field='Ant*',<br />
averagedata=True, avgchannel='3840', avgtime='',<br />
avgscan=False, avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
plotms(vis = asdm+'.wvrtsys.ms', xaxis='freq', yaxis='amp',<br />
ydatacolumn='corrected', field='Ant*',<br />
avgtime='1e8', avgscan=True,avgbaseline=False, coloraxis='corr')<br />
dummy_string = raw_input("Hit <Enter> for next plot.")<br />
</source><br />
<br />
==Split and Concatenate Data for Northern and Southern Mosaics==<br />
The individual data sets are now calibrated. We can safely split out the calibrated data for our science target and drop the calibrators. As we do so, we will smooth the data in frequency, averaging together groups of 23 channels by setting '''width=23''' in {{split}}. The new data will have a channel width corresponding to about ~10 km/s, very similar to the SMA data being verified. The factor of >20 drop in data volume will also make the imaging steps ''much'' more tractable.<br />
<br />
<source lang="python"><br />
#In CASA<br />
<br />
basename_north=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9","uid___A002_X2181fb_X49"]<br />
<br />
basename_south=["uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7","uid___A002_X207fe4_X4d7",<br />
"uid___A002_X215db8_X18","uid___A002_X215db8_X1d5","uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_north:<br />
os.system('rm -rf '+asdm+'.cal.ms')<br />
split(vis = asdm+'.wvrtsys.ms',outputvis = asdm+'.cal.ms',<br />
field = 'NGC*',spw='0',width=23, keepflags=False)<br />
os.system('rm -rf '+asdm+'.cal.listobs.txt')<br />
listobs(asdm+'.cal.ms',listfile=asdm+'.cal.listobs.txt')<br />
<br />
for asdm in basename_south:<br />
os.system('rm -rf '+asdm+'.cal.ms')<br />
split(vis = asdm+'.wvrtsys.ms',outputvis = asdm+'.cal.ms',<br />
field = 'Ant*',spw='0',width=23, keepflags=False)<br />
os.system('rm -rf '+asdm+'.cal.listobs.txt')<br />
listobs(asdm+'.cal.ms',listfile=asdm+'.cal.listobs.txt')<br />
</source><br />
<br />
For convenience we concatenate all data for the Northern Mosaic into a single big MS and place all data for the Southern Mosaic into another file. To do this, we construct a list that holds the names of all the Southern Mosaic MS files and another that holds the name of all the Northern Mosaic MS files then feed these into the {{concat}} task. <br />
<br />
Before we do this, we'll take a brief aside to remove Pointing information from the calibrated data. Normally, the pointing information would apply important corrections to be used while imaging the data. However, some aspects of this are still under development and the pointing information in these data interacts poorly with CASA. We will remove the pointing information using the CASA toolkit Table tool (tb). ''This kind of operation is dangerous and should not be a regular feature of your CASA reduction.''<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
basename_all=["uid___A002_X1ff7b0_Xb","uid___A002_X207fe4_X3a","uid___A002_X207fe4_X3b9",<br />
"uid___A002_X2181fb_X49","uid___A002_X1ff7b0_X1c8","uid___A002_X207fe4_X1f7",<br />
"uid___A002_X207fe4_X4d7","uid___A002_X215db8_X18","uid___A002_X215db8_X1d5",<br />
"uid___A002_X215db8_X392"]<br />
<br />
for asdm in basename_all:<br />
print "Manually removing pointing table from "+asdm+".cal.ms ... Please be careful!"<br />
tb.open(asdm+'.cal.ms/POINTING',nomodify=False)<br />
a = tb.rownumbers()<br />
tb.removerows(a)<br />
tb.close()<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
cal_south_vis = [vis+'.cal.ms' for vis in basename_south]<br />
cal_north_vis = [vis+'.cal.ms' for vis in basename_north]<br />
<br />
os.system('rm -rf Antennae_South.cal.ms')<br />
concat(vis=cal_south_vis, concatvis='Antennae_South.cal.ms', timesort=True)<br />
<br />
os.system('rm -rf Antennae_North.cal.ms')<br />
concat(vis=cal_north_vis, concatvis='Antennae_North.cal.ms', timesort=True)<br />
</source><br />
<br />
The syntax used to construct the 'cal_south_vis' variable loops over basename_south and makes a list after adding '.cal.ms' to each member. To see the list 'print cal_south_vis'.<br />
<br />
==Continue on to Imaging of the Science Target==<br />
Now you can continue on to the [http://casaguides.nrao.edu/index.php?title=AntennaeBand7_Imaging_4.5 imaging guide].<br />
{{Checked 4.5.0}}</div>Jthorley